I am completely not an expert on the pdf specifications, but I'm wondering
whether this PDF I have is doing anything "wrong", and if so, whether it
would be worth itext[sharp] handling it anyway?

Context is, I was given a bug to fix that, for a particular PDF we were
sent to look at, which contains a field using a barcode font, if you open
the PDF (I tried both Reader X and FoxIt), you see the value of the field
using the right font, but after writing a new value to the field with
itextsharp and opening the PDF, the value of the field has lost its font
unless you click on the field to edit it.

I peeked inside the PDFs looking for differences, and determined the
proximate issue was that it wasn't writing the font to the field's
/AP/N/Resources/Font (it was writing the default, /HELV). So I poked around
the itextsharp source, and it looks like the *ultimate* cause is that in
DecodeGenericDictionary in AcroFields.cs, itextsharp is looking for the
list of available fonts in the /DR/Font dictionary inside the specific
field you're trying to write to, but in this particular PDF, that
dictionary only contains Helv. However, the /DR/Font dictionary attached
directly to the root /Catalog/AcroForm, does contain all the fonts being
used. Thus, adding:

if (po == null)
{
    PdfDictionary parentFont =
reader.Catalog.GetAsDict(PdfName.ACROFORM).GetAsDict(PdfName.DR).GetAsDict(PdfName.FONT);
    po = parentFont.Get(new PdfName((String)dab[DA_FONT]));
}

after the line in AcroFields.cs:
PdfObject po = font.Get(new PdfName((String)dab[DA_FONT]));

The issue on that specific pdf disappeared - the font rendered correctly
for the fields using it. I'm just wondering whether that would be worth
merging, or whether it's an unlikely issue from an invalid pdf.

Thanks
- Adam
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to