pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Migrate form field entries from one pdf to another
Date Mon, 06 Jul 2015 20:14:44 GMT
Am 06.07.2015 um 18:15 schrieb Maruan Sahyoun:
> There will be an issue with the test template when you set the Name and Prename field
as the field definition is incomplete (the font resource is missing) which will lead to an
exception
>
> java.io.IOException: Could not find font: /Courier
>
> The easiest would be to correct the template. If that's not possible we could help you
building a short workaround. But as the template you provided was only a quick mock up and
not the real one the final template might not have the issue.

I just tried a quick and dirty solution, I changed 
PDAppearanceString.getFont(), the "if (font == null)" segment is new:

     public PDFont getFont() throws IOException
     {
         COSName name = getFontResourceName();
         PDFont font = defaultResources.getFont(name);

         if (font == null)
         {
             if ("Courier".equals(name.getName()))
             {
                 COSDictionary dict = new COSDictionary();
                 dict.setName(COSName.BASE_FONT, "Courier");
                 dict.setName(COSName.NAME, "Courier");
                 dict.setName(COSName.SUBTYPE, "Type1");
                 dict.setName(COSName.TYPE, "Font");

                 font = PDFontFactory.createFont(dict);
             }
         }

         // todo: handle cases where font == null with special mapping 
logic (see PDFBOX-2661)
         if (font == null)
         {
             throw new IOException("Could not find font: /" + 
name.getName());
         }

         return font;
     }


Now I was able to set the text fields
(Roberto: in the file I sent to you earlier, uncomment 
"newTextField.setValue(textField.getValue());")

However the resources have two identical fonts now, /F2 and /Courier.

Tilman

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message