PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Jul 05, 2024 5:24 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Wed Jan 12, 2011 12:56 pm 
Offline

Joined: Thu May 28, 2009 8:11 pm
Posts: 14
I have a private webserver on which I have installed the PDFsharp dll's.
The PDF's I generate are tickets for events, which have a barcode (font: free of 9) on them.

Now, when from my home machine I download a ticket (generated on the fly) the barcode is nicely added to the PDF and the font is applied so it also looks like a barcode.
But when I try to download the SAME ticket from my machine at work, the font is not used and I see the pure barcode in a regular text font (not free of 9).

My question is: what may be causing this?


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 12, 2011 2:53 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
petersmith wrote:
My question is: what may be causing this?

Is the barcode font included in the PDF?

If not, then the barcode font installed on the computer will be used.
So if the correct font is installed on your home computer, the PDF shows correctly.
If the font is not installed on your work computer, then a different font will be used.

Adobe Reader can show a list of all fonts in a PDF document.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 12, 2011 3:58 pm 
Offline

Joined: Thu May 28, 2009 8:11 pm
Posts: 14
Hi Thomas,

Thanks for the very quick reply! :)
well...I thought that too initially, so I installed the font also on my work pc...and that indeed seems to work. Ofcourse that is not acceptable to my customers, I dont want to force them to install a certain font.

But your remark does interest me:
Quote:
Is the barcode font included in the PDF?


This is what I see when I check whether the font is included in the PDF on a PC WITHOUT the free of 9 font:
I do see my 'free of 9 font' there. I see:
Actual Font: Adobe Sans MM
Actual Font Type: Type 1

And on a PC WITH the free of 9 font I see:
Actual Font: Freeof9Extended
Actual Font Type: TrueType


Since I generate the PDF on the fly...is there a programmatic way to include the font in my PDF?

Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 12, 2011 4:19 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
You specify this when creating a font in PDFsharp:
XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

http://www.pdfsharp.net/wiki/Unicode-sample.ashx
For MigraDoc:
http://www.pdfsharp.net/wiki/MigraDocHe ... ample.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 12, 2011 5:17 pm 
Offline

Joined: Thu May 28, 2009 8:11 pm
Posts: 14
Ok, so below (the most important) code piece on the way I currently generate my documents. How would your code sample fit in?
I thought it would be an extra parameter here: New MigraDoc.Rendering.DocumentRenderer(doc, XXX), but thats not possible apparently...

Dim fonttype As String = "Free 3 of 9 Extended"
Dim fontsize As Integer = 40

row = tbl.AddRow
Dim font As New MigraDoc.DocumentObjectModel.Font
font.Name = fonttype
font.Size = MigraDoc.DocumentObjectModel.Unit.FromPoint(fontsize)
row.Cells(0).Format.Font.ApplyFont(font)
row.Cells(0).AddParagraph("*" + userTicketsDT.Item(0).barcode.ToString + "*")


Dim docRenderer As MigraDoc.Rendering.DocumentRenderer = New MigraDoc.Rendering.DocumentRenderer(doc)
docRenderer.PrepareDocument()
docRenderer.RenderObject(gfx, XUnit.FromMillimeter(96), XUnit.FromMillimeter(228), "12cm", tbl)

Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 14, 2011 1:22 pm 
Offline

Joined: Thu May 28, 2009 8:11 pm
Posts: 14
Does anyone have a suggestion yet how to combine the code suggested with my current code?


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 19, 2011 10:37 am 
Offline

Joined: Thu May 28, 2009 8:11 pm
Posts: 14
Anyone at all? :)


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 19, 2011 11:04 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
If you use MigraDoc this way. then you must specify font embedding at the gfx object:
Code:
gfx.MUH = PdfFontEncoding.Unicode;
gfx.MFEH = PdfFontEmbedding.Default;


If you don't use Unicode, then set PdfFontEmbedding.Always.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 25, 2011 2:22 pm 
Offline

Joined: Thu May 28, 2009 8:11 pm
Posts: 14
Ok, I tried adding those lines, but still no luck:
I also fail to understand why I should use gfx object to apply the font, since I dont use that object to generate the actual barcode, which IMO is generated by this piece of code:
------------------------------------------------------------------------------------------------------------------
row = tbl.AddRow
Dim font As New MigraDoc.DocumentObjectModel.Font
font.Name = fonttype
font.Size = MigraDoc.DocumentObjectModel.Unit.FromPoint(fontsize)
row.Cells(0).Format.Font.ApplyFont(font)
row.Cells(0).AddParagraph("*" + userTicketsDT.Item(0).barcode.ToString + "*")
row.Cells(0).MergeRight = 1
------------------------------------------------------------------------------------------------------------------


Here's all my code:
gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend)

'this code was added using PDFsharp forum
gfx.MUH = PdfFontEncoding.Unicode

gfx.MFEH = PdfFontEmbedding.Default
'also tried: gfx.MFEH = PdfFontEmbedding.Always

Dim image As XImage = XImage.FromFile(flyerfilename)
gfx.DrawImage(image, 0, 0)

Dim imgOutput As New Bitmap(400, 50, PixelFormat.Format32bppArgb) ' create a New 24bit, 120x30 pixel image

image = XImage.FromGdiPlusImage(imgOutput)
gfx.DrawImage(image, 280, 800)

image = XImage.FromFile(logo)
gfx.DrawImage(image, 414, 10)

'ADD TABLE
tbl = New MigraDoc.DocumentObjectModel.Tables.Table
tbl.Borders.Width = 0
tbl.Shading.Color = MigraDoc.DocumentObjectModel.Colors.White
col = tbl.AddColumn(MigraDoc.DocumentObjectModel.Unit.FromCentimeter(3))
col.Format.Alignment = MigraDoc.DocumentObjectModel.ParagraphAlignment.Left
col = tbl.AddColumn(MigraDoc.DocumentObjectModel.Unit.FromCentimeter(8))
row = tbl.AddRow
cell = row.Cells(0)
cell.AddParagraph("Naam")
cell = row.Cells(1)
cell.AddParagraph(ticketDAL.BuildTicketName(userTicketsDT.Item(0).firstname, userTicketsDT.Item(0).middlename, userTicketsDT.Item(0).lastname))

row = tbl.AddRow
cell = row.Cells(0)
cell.AddParagraph("Tickettype")
cell = row.Cells(1)
cell.AddParagraph(userTicketsDT.Item(0).ticketname)

row = tbl.AddRow
cell = row.Cells(0)
cell.AddParagraph("OrderId")
cell = row.Cells(1)
cell.AddParagraph(orderID.ToString)

row = tbl.AddRow
Dim font As New MigraDoc.DocumentObjectModel.Font
font.Name = fonttype
font.Size = MigraDoc.DocumentObjectModel.Unit.FromPoint(fontsize)
row.Cells(0).Format.Font.ApplyFont(font)
row.Cells(0).AddParagraph("*" + userTicketsDT.Item(0).barcode.ToString + "*")
row.Cells(0).MergeRight = 1

tbl.SetEdge(0, 0, 2, 11, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1.5, MigraDoc.DocumentObjectModel.Colors.Black)

Dim doc As New MigraDoc.DocumentObjectModel.Document
Dim section As MigraDoc.DocumentObjectModel.Section = doc.AddSection()
doc.LastSection.Add(tbl)


Dim docRenderer As MigraDoc.Rendering.DocumentRenderer = New MigraDoc.Rendering.DocumentRenderer(doc)
docRenderer.PrepareDocument()
docRenderer.RenderObject(gfx, XUnit.FromMillimeter(96), XUnit.FromMillimeter(228), "12cm", tbl)


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 25, 2011 2:35 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
petersmith wrote:
I also fail to understand why I should use gfx object to apply the font, since I dont use that object to generate the actual barcode, which IMO is generated by this piece of code

The barcode is generated by this line of code:
Code:
docRenderer.RenderObject(gfx, XUnit.FromMillimeter(96), XUnit.FromMillimeter(228), "12cm", tbl)

and gfx is passed as a parameter here.
Like for page 1 of this sample:
http://www.pdfsharp.net/wiki/MixMigraDo ... rst_Page_1

I wouldn't use RenderObject, I would use RenderPage. MigraDoc will then create the complete page, so you must make the positioning in MigraDoc.
As shown for page 2 of the sample:
http://www.pdfsharp.net/wiki/MixMigraDo ... Page_Two_2

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 78 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group