我載入PDF顯示時中文顯示不正常,以下是我替換字型的CODE
- Code: Select all
Dim fonts() As PdfUsedFont = doc.UsedFonts
Dim trueTypeFont As New PdfTrueTypeFont(New Font("細明體 標準", 11.0F), True)
For Each font As PdfUsedFont In fonts
font.Replace(trueTypeFont)
Next
Dim fonts() As PdfUsedFont = doc.UsedFonts
Dim trueTypeFont As New PdfTrueTypeFont(New Font("細明體 標準", 11.0F), True)
For Each font As PdfUsedFont In fonts
font.Replace(trueTypeFont)
Next
If url.ToLower.Contains(".pdf") Then
'for pdf
'Dim wc As New System.Net.WebClient()
'Using stream As New MemoryStream(wc.DownloadData(url))
' doc.LoadFromStream(stream)
'End Using
Using client As New System.Net.WebClient()
client.DownloadFile(url, outPdfFile)
doc.LoadFromFile(outPdfFile)
End Using
'doc.LoadFromBytes(wc.DownloadData(url))
Else
'for xml
'doc.LoadFromHTML(url, False, False, False, setting, htmlLayoutFormat, True)
Dim wc As New System.Net.WebClient()
doc.LoadFromBytes(wc.DownloadData(url))
End If
'encrypt the PDF file
doc.Security.Encrypt("user", "owner", PdfPermissionsFlags.None, PdfEncryptionKeySize.Key256Bit)
doc.ViewerPreferences.HideMenubar = True
doc.ViewerPreferences.HideToolbar = True
doc.ViewerPreferences.HideWindowUI = True
doc.ViewerPreferences.PageLayout = PdfPageLayout.SinglePage
doc.ViewerPreferences.PageMode = PdfPageMode.FullScreen
doc.ViewerPreferences.CenterWindow = True
doc.ViewerPreferences.DisplayTitle = False
doc.ViewerPreferences.FitWindow = True
Dim page As PdfPageBase = doc.Pages(0)
Dim dest As New PdfDestination(page, New PointF(-40.0F, -40.0F))
dest.Zoom = 1.5F
Dim gotoaction As New PdfGoToAction(dest)
doc.AfterOpenAction = gotoaction
'创建一个新的字体
'Dim newfont As PdfFont = New PdfFont(PdfFontFamily.Symbol, 11.0!, (PdfFontStyle.Italic Or PdfFontStyle.Bold))
'Font font1 = New Font("Arial Unicode MS", 11.0F);
'PdfTrueTypeFont trueTypeFont = New PdfTrueTypeFont(font1, True);
'//字体,字体大小,font中设置字体大小的单位为磅
'PdfTrueTypeFont titleFont = New PdfTrueTypeFont(New Font("宋体", unitCvtr.ConvertUnits(24.0F, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point)), True);
'PdfTrueTypeFont contentFont = New PdfTrueTypeFont(New Font("宋体", unitCvtr.ConvertUnits(14.0F, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point)), True);
''Dim fonts() As PdfUsedFont = doc.UsedFonts
''Dim trueTypeFont As New PdfTrueTypeFont(New Font("細明體 標準", 11.0F), True)
''For Each font As PdfUsedFont In fonts
'' font.Replace(trueTypeFont)
''Next
'Save pdf file.
doc.SaveToFile(outPdfFile, FileFormat.PDF)
doc.Close()
If File.Exists(outPdfFile) Then
PdfDocViewer.LoadFromFile(outPdfFile, "user")
'WebBrowser2.Navigate(outPdfFile)
End If
pdfDocumentViewer1.EastAsianFont = True