PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

barcode font in PDF used on 1 machine but not the other?
http://forum.pdfsharp.de/viewtopic.php?f=2&t=1502
Page 1 of 1

Author:  petersmith [ Wed Jan 12, 2011 12:56 pm ]
Post subject:  barcode font in PDF used on 1 machine but not the other?

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?

Author:  Thomas Hoevel [ Wed Jan 12, 2011 2:53 pm ]
Post subject:  Re: barcode font in PDF used on 1 machine but not the other?

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.

Author:  petersmith [ Wed Jan 12, 2011 3:58 pm ]
Post subject:  Re: barcode font in PDF used on 1 machine but not the other?

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!

Author:  Thomas Hoevel [ Wed Jan 12, 2011 4:19 pm ]
Post subject:  Re: barcode font in PDF used on 1 machine but not the other?

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

Author:  petersmith [ Wed Jan 12, 2011 5:17 pm ]
Post subject:  Re: barcode font in PDF used on 1 machine but not the other?

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!

Author:  petersmith [ Fri Jan 14, 2011 1:22 pm ]
Post subject:  Re: barcode font in PDF used on 1 machine but not the other?

Does anyone have a suggestion yet how to combine the code suggested with my current code?

Author:  petersmith [ Wed Jan 19, 2011 10:37 am ]
Post subject:  Re: barcode font in PDF used on 1 machine but not the other?

Anyone at all? :)

Author:  Thomas Hoevel [ Wed Jan 19, 2011 11:04 am ]
Post subject:  Re: barcode font in PDF used on 1 machine but not the other?

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.

Author:  petersmith [ Tue Jan 25, 2011 2:22 pm ]
Post subject:  Re: barcode font in PDF used on 1 machine but not the other?

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)

Author:  Thomas Hoevel [ Tue Jan 25, 2011 2:35 pm ]
Post subject:  Re: barcode font in PDF used on 1 machine but not the other?

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

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