0
votes

My PDF is not displayed properly with Adobe Reader. It is fine with other PDF readers so this must be a syntax issue, as I've heard that Adobe Reader is more strict with PDF syntax. The fonts seem to be twice as big as they should be but the horizontal spacing is correct, this makes the fonts overlap with each other.

This is my C# code (font creation code is at the end of this post).

Font officialUseFont = EmbeddedResources.CreateDesignFont(webform);
PdfContentByte officialUseCanvas = _stamper.GetOverContent(3);
ColumnText.ShowTextAligned(officialUseCanvas, Element.ALIGN_CENTER, new Phrase(webform.Text, officialUseFont), posX, posY, 0);

I'm using iTextSharp 5.4.2.0 with runtime v2.0.50727.PDF Font Properties

I must have embedded some fonts because the Cyrillic alphabet and Chinese alphabets were not working before but they work now. The form fields which exist in the PDF are populated with Cyrillic characters without any problems, it's only the canvas which causes the issue.enter image description here

public Font CreateDesignFont(IForm webform)
{
    var baseFont = GetBaseFont(fontNamespace.Length, selectedFontName);
    return new Font(baseFont, webform.FontSize);
}
    private static BaseFont GetBaseFont(int fontNamespaceLength, string selectedFontName)
    {

        byte[] fontBuffer;
        using (var stream = (Assembly.GetExecutingAssembly().GetManifestResourceStream(selectedFontName)))
        {
            fontBuffer = new byte[stream.Length];
            stream.Read(fontBuffer, 0, fontBuffer.Length);
        }
        var fontfile = selectedFontName.Substring(fontNamespaceLength);
        var customFont = BaseFont.CreateFont(fontfile, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, BaseFont.CACHED, fontBuffer, null);
        return customFont;
    }
2
Sorry I just made a mistake in the original post. I am using version 5.4.2.0 - fireydude
Please provide the PDF for inspection. - mkl
Do you have sufficient information in the post now? I could put the PDF in a dropbox folder if you need it. - fireydude
A Sample PDF would still be helpful. - mkl
I agree with @mkl I can't reproduce the problem, so I don't have a clue what is wrong. - Bruno Lowagie

2 Answers

0
votes

The code snippet you're providing isn't sufficient. The problem originates in whatever happens when you do EmbeddedResources.CreateDesignFont(webform);

If the font isn't shown in Adobe Reader, you didn't embed the font. Maybe you think you do, but judging by the behavior of the PDF viewers, you didn't.

Can you provide a screen shot of the Document Properties, more specifically the "Fonts" tab?

UPDATE

I tried writing my own code snippet, and I wasn't able to reproduce the problem. So I took another look at your code, and I saw that you're caching the font, but you've already used ArialMT using the WINANSI encoding to fill out the fields on page 1. IMO (I don't have the time to check) that's incompatible with using the same font from cache using IDENTITY_H. If you don't cache the font (why would you? you're passing the fontBuffer! no need to store the font in a cache if you're already caching the font bytes yourself), your problem will probably be solved.

0
votes

The problem stemmed from the fact I was using .otf fonts. When I changed to .ttf the problem disappeared.