PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

How to put Traditional Chinese Characters in PDF
https://forum.pdfsharp.net/viewtopic.php?f=2&t=28
Page 1 of 1

Author:  HjyangHJ [ Fri Nov 24, 2006 3:50 am ]
Post subject:  How to put Traditional Chinese Characters in PDF

Using sample XGraphicsLab.exe,
1. in "XGraphics Properties" window, set "Font Family" some traditional chinese font builtin in my PC. Type some chinese characters in the bottom TextBox.
2. in "XGraphics Lab" window, select [Text>Layout 1], the traditional chinese characters which I type in "XGraphics Properties" window do appear correctly in "Preview" window.
3. When I click the [Create PDF] button in "Preview" window , "Assert failed" dialog show up, after press [Ignore] button many times, Acrobat Reader load the pdf file I just created, BUT all chinese characters appear as a '?'

What is the problem ? :?

Author:  scneter [ Fri May 13, 2011 4:20 am ]
Post subject:  Re: How to put Traditional Chinese Characters in PDF

Dear all

I use PDFSharp Create Traditional Chinese PDF File
Will always appear as multiple error messages , Has been ignored Button Many times , Until after you complete the program
Use Adobe Reader Open PDF File , Traditional Chinese Fonts Normally appear
But I do not know in the process of creating , How to troubleshoot the error messages that appear

Attachments:
Error Message Image.jpg
Error Message Image.jpg [ 230.11 KiB | Viewed 11306 times ]
Create OK PDF File.jpg
Create OK PDF File.jpg [ 47.35 KiB | Viewed 11306 times ]

Author:  () => true [ Fri May 13, 2011 8:57 pm ]
Post subject:  Re: How to put Traditional Chinese Characters in PDF

scneter wrote:
How to troubleshoot the error messages that appear

Looks like a Debug.Assert message that won't come with a Release build.

If you let us know which Asserts are triggered I can try to find out what it means.

Author:  scneter [ Sat May 14, 2011 5:29 am ]
Post subject:  Re: How to put Traditional Chinese Characters in PDF

Dear All
I Try Sample Code & Add Test Code For Unicode
Use Code Like this:
'------------ Use ImageToPDF Demo Sample Code (VB2008) -----------------------------
Imports System.IO
Imports PdfSharp
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing

Public Class Form1
Private Sub B1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B1.Click
Dim document As PdfDocument = New PdfDocument
document.Info.Title = "Created with PDFsharp"
Dim source As String = CurDir() & "\20110429143219_2.jpg"
Dim img As XImage = XImage.FromFile(source)
' Create an empty page
Dim page As PdfPage = document.AddPage
' Get an XGraphics object for drawing
Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
gfx.DrawImage(img, 100, 100, 160, 120)
gfx.DrawImage(img, 300, 100, 160, 120)
' Draw crossing lines
Dim pen As XPen = New XPen(XColor.FromArgb(255, 0, 0))
'gfx.DrawMatrixCode(pen, New XPoint(20, 100))
gfx.DrawRectangle(pen, New XRect(100, 200, 400, 150))
' Draw an ellipse
gfx.DrawEllipse(pen, 3 * page.Width.Point / 10, 3 * page.Height.Point / 10, 2 * page.Width.Point / 5, 2 * page.Height.Point / 5)
' Create a font
Dim options As New XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always)
Dim font As XFont = New XFont("標楷體", 20, XFontStyle.Bold, options)
'Dim font As XFont = New XFont("Times New Roma", 20, XFontStyle.Bold)
' Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black, New XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormat.Center)
'---------------------- Test UniCode -------------------------------
gfx.DrawLine(pen, New XPoint(0, 0), New XPoint(page.Width.Point, page.Height.Point))
gfx.DrawLine(pen, New XPoint(page.Width.Point, 0), New XPoint(0, page.Height.Point))
gfx.DrawString("世界你好!", font, XBrushes.Black, New XRect(0, 50, page.Width.Point, page.Height.Point), XStringFormat.Center)
gfx.DrawString("這是測試 PDF 圖片檔案", font, XBrushes.Black, 150, 230)
gfx.DrawString("這是測試 PDF 圖片檔案", font, XBrushes.Black, 160, 260)
gfx.DrawString("這是測試 PDF 圖片檔案", font, XBrushes.Black, 170, 290)
gfx.DrawString("這是測試 PDF 圖片檔案", font, XBrushes.Black, 180, 320)
'----------------------------------------------------------------------
' Save the document...
Dim filename As String = "HelloWorld.pdf"
document.Save(filename)
' ...and start a viewer.
Process.Start(filename)
End Sub
End Class

Author:  () => true [ Sat May 14, 2011 9:07 am ]
Post subject:  Re: How to put Traditional Chinese Characters in PDF

scneter wrote:
Use Code Like this

Sorry, mate, but I won't use that code. I don't have chinese Windows, I don't have chinese Fonts, so probably I won't get the Debug.Assert anyway ...

I asked where in the PDFsharp code is the Debug.Assert that shows the messages you get. When the message comes, click Debug and you should see the line of code in your debugger.
Filename, methodname and linenumber will do.

Author:  scneter [ Mon May 16, 2011 1:40 am ]
Post subject:  Re: How to put Traditional Chinese Characters in PDF

Sorry!
Sorry! because my English is not good
It may be, can not fully understand what you're saying
But I will try to understand what you're saying, and try to put your way to complete the work of debugging

I'm back online to download new PDFSharp.DLL, after re-compile the test, they can already be displayed
But when I change the font in different font other tests and found he could not find the font error occurs

1. Appears before the problem is when I carried PDFsharp.Save (nFileName) problems arising
2. Now with the new DLL files, fonts when loading
Dim font As XFont = New XFont (FontNameString, 20, XFontStyle.Bold, options) was a problem

scneter chang

Author:  scneter [ Tue May 17, 2011 2:29 am ]
Post subject:  Re: How to put Traditional Chinese Characters in PDF

Dear All

I tested other fonts, and some can be normal, there is an error
I do not know where the problem because there is obviously a font
It generates an error message the program caused an interrupt, can not perform

I will continue to find time to continue testing to see if there is no solution

Thank you!

scneter chang

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/