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

Creating PDF: trouble displaying special fonts [PDFsharp]
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2091
Page 1 of 1

Author:  FrageWurm [ Wed Jul 18, 2012 1:41 pm ]
Post subject:  Creating PDF: trouble displaying special fonts [PDFsharp]

Hi all,

Im using PDFsharp and trying to create some output with some special fonts and somehow I cannot display all of them on a pdf.
If I want to display an other font in my Windows Form Application, I do this:

Code:
        private void Form1_Load(object sender, EventArgs e)
        {
            Label l = new Label();

            l.Text = "ÌtestwÎ";

            this.Font = new Font("Code 128", 80);

            l.Size = new System.Drawing.Size(300, 300);
           
            this.Controls.Add(l);
            this.Size = new Size(300, 300);
        }


As output I get a Window with my font (barcode), everything is fine
Attachment:
File comment: font in windows form
form.jpg
form.jpg [ 12.11 KiB | Viewed 12915 times ]



Now I would like to use the same font and the same string and write it in a pdf. That should work well. I try something like this:
Code:
            PdfDocument doc = new PdfDocument();
            PdfPage page = doc.AddPage();

            XGraphics gfx = XGraphics.FromPdfPage(page);

            gfx.DrawString("ÌtestwÎ", new XFont("Code 128", 80), XBrushes.Black, 50, 100);


If I open my pdf I get this
Attachment:
File comment: same font in pdf
pdf.jpg
pdf.jpg [ 18.4 KiB | Viewed 12915 times ]


I think everything is alright, there is just some trouble with the start and end characters Ì and Î But why?
How to avoid this issue? Any ideas? Thank you

PS: I downloaded the font from http://www.jtbarton.com/Barcodes/Code128.aspx But I think thats not that important.

Author:  dheijl [ Thu Jul 19, 2012 9:22 am ]
Post subject:  Re: Creating PDF: trouble displaying special fonts

As a work-around you could draw the barcode on a .Net bitmap or jpeg image and insert the image into the pdf.

Danny

Author:  FrageWurm [ Sun Jul 22, 2012 9:58 pm ]
Post subject:  Re: Creating PDF: trouble displaying special fonts

Hi, to create an image and then add this image to the pdf is one solution. But I liked pdfsharp because I could add my fonts "on the fly" without creating an image.

Somebody an idea why there is only a prob with the start and end character?

Author:  Thomas Hoevel [ Mon Jul 30, 2012 9:27 am ]
Post subject:  Re: Creating PDF: trouble displaying special fonts

Hi!
FrageWurm wrote:
Somebody an idea why there is only a prob with the start and end character?
I presume the font uses an unusual encoding. Could be a bug in PDFsharp.
I'll ask my boss when he's back from his holidays (fonts in PDF are not my area of expertise).

Author:  FrageWurm [ Mon Aug 06, 2012 7:39 pm ]
Post subject:  Re: Creating PDF: trouble displaying special fonts

Thomas Hoevel wrote:
I'll ask my boss when he's back from his holidays (fonts in PDF are not my area of expertise).

Thx that would be nice, Im still interested.

Ì is ASCII Code 204 and Î 206 (could use Convert.ToChar(204) to get the char).
These are some unusual chars, but I have to use them.

Author:  mikesowerbutts [ Tue Aug 07, 2012 1:56 pm ]
Post subject:  Re: Creating PDF: trouble displaying special fonts [PDFsharp

could it not be embedding some of the characters in the font within the PDF? i know it only does a subset by default, maybe you can check in the Properties screen of the PDF which characters are part of the embedded subset of that font?

Author:  FrageWurm [ Wed Aug 08, 2012 9:22 am ]
Post subject:  Re: Creating PDF: trouble displaying special fonts [PDFsharp

Hi. Im not sure what you mean with "Properties screen of the PDF", how/where should I check that?

Author:  Thomas Hoevel [ Wed Aug 08, 2012 9:45 am ]
Post subject:  Re: Creating PDF: trouble displaying special fonts [PDFsharp

The document properties dialog of Adobe Reader shows which fonts are embedded in the document. But AFAIK you cannot see which characters are included.

Author:  FrageWurm [ Wed Aug 08, 2012 12:27 pm ]
Post subject:  Re: Creating PDF: trouble displaying special fonts [PDFsharp

If I use another font (common font like arial) everything is fine:

Attachment:
File comment: pdf image
pdf.jpg
pdf.jpg [ 16.51 KiB | Viewed 12805 times ]


Thomas Hoevel wrote:
The document properties dialog of Adobe Reader shows which fonts are embedded in the document. But AFAIK you cannot see which characters are included.

I could upload the my pdf. Maybe there is a way to analyse it.
http://www.mediafire.com/?a9fkh70o7tc0ukl

Edit: Forgot to say, but this issue is with a lot unusual characters like Ã, Ä, Å... (Convert.ToChar(195+))

Author:  Thomas Hoevel [ Wed Aug 08, 2012 1:25 pm ]
Post subject:  Re: Creating PDF: trouble displaying special fonts [PDFsharp

FrageWurm wrote:
Edit: Forgot to say, but this issue is with a lot unusual characters like Ã, Ä, Å... (Convert.ToChar(195+))
All these letters work fine if you use a font like Arial.
They don't work with the Code 128 font. So Code 128 is somewhat different. Could be a bug in the font, could be a bug in PDFsharp.

I'm afraid we don't have time to investigate this in the near future. I would try a workaround, drawing the bar code on an image and using that image in the PDF.
This may even result in smaller PDFs as you don't have to include the font in the PDF file.

Author:  calosteward [ Tue Jul 21, 2015 6:37 am ]
Post subject:  Re: Creating PDF: trouble displaying special fonts [PDFsharp

If you only tested the code 128 font in PDF sharp, it cannot explain there's bug in PDFsharp.
Possible situation is that the code 128 font you downloaded is not compatible with PDFsharp.
Why not change other barcode fonts.

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