Hello,


I am sending regarding an issue I am dealing with using PDFBox 2.0.6 for
generating a pdf file.


When the generated pdf gets populated in mozilla , some of the fields of
the pdf are displayed normally and some of the fields not displayed at all.


In other browsers (IE,Chrome,Opera) the pdf is populated as expected.

The ttf file that I load to pdf is “lucidaSansUnicode.ttf” as you will see
at the code snippet I attached.

I tested with several ttf files but the problem remains.

At the attached file you will find the code reference to above case I am
describing.



Please if there is something that I am missing to solve the problem I would
appreciate your response.



Kind Regards,
               
public class PdfGenerator{      
        
        public byte[] populatePdf(){
                pdfDocument = 
PDDocument.load(getClass().getResourceAsStream(pdfPath));
                pdfDocument.getNumberOfPages();

                PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
                PDAcroForm acroForm = docCatalog.getAcroForm();
                InputStream fontStream = 
getClass().getResourceAsStream("/pdfassets/lucidaSansUnicode.ttf");

                PDResources res = acroForm.getDefaultResources();
                if (res == null)
                        res = new PDResources();

                PDFont font = PDType0Font.load(pdfDocument, fontStream, false);
                COSName cosFontName = res.add(font);
                acroForm.setDefaultResources(res);
                fontName = cosFontName.getName();
                acroForm.setNeedAppearances(true);
                setField(acroForm,"firstName","Κατερινα");
                setField(acroForm,"lastName","Πετροπουλου");
                setField(acroForm,"fathersName","Γιαννης");

                
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                pdfDocument.save(os);
                byte[] data = os.toByteArray();
                os.close();
                pdfDocument.close();
                return data;
        }
        
        
        
        public void setField(PDAcroForm acroForm, String name, String value) 
throws IOException {

                PDField field = acroForm.getField(name);

                if (field != null) {
                        field.setValue(value);
                        if (field instanceof PDTextField) {
                                // font size = 8
                                String da = "/" + fontName + " 8 Tf 0 g";
                                ((PDTextField) field).setDefaultAppearance(da);
                        }
                } else {
                        vlogError("No field found with name: {0}", name);
                }
        }
        
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to