Am 29.04.2015 um 14:26 schrieb [email protected]:

Hello,

when you add an AcroForm to a document that has a 90 degree orientation, does 
the form automatically have a 90 degree orientation?

What about it fields?

My problem with the code below is that the fields' data are printed vertically 
instead of horizontally.

Seems not to be supported:
http://stackoverflow.com/questions/16952710/filling-landscape-pdf-with-pdfbox

Tilman



Many thanks.

Philippe


                // Loop through CSV lines and retrieve each line's data
                for (Map<String, String> pdfLineTreeMap : csvDataArrayList) {

                        // Retrieve template's catalog
                        final PDDocumentCatalog templateCatalog = 
PDDocument.load(pdfTemplateFilePath).getDocumentCatalog();
                        // Retrieve its acroForm
                        final PDAcroForm templateAcroForm = 
templateCatalog.getAcroForm();

                        // Get all template PDF's pages
                        final List<PDPage> templateCatalogPages = 
templateCatalog.getAllPages();
                        // Get template document's first page
                        final PDPage templateFirstPage = 
templateCatalogPages.get(0);
                        LOGGER.info("Template page rotation  " + 
templateFirstPage.getRotation());

                        // Add first page to final doc with filled out fields
                        finalDoc.addPage(templateFirstPage);
                        List<PDPage> pages = 
finalDoc.getDocumentCatalog().getAllPages();
                        final int pageCount = pages.size();
                        final PDPage lastPage = pages.get(pageCount - 1);
                        LOGGER.info("last page rotation = " + 
lastPage.getRotation());

                        // Loop through PDF field names in pdfLineTreeMap (this 
map was previously
                        // created to store the CSV data; its keys are equal to 
the
                        // PDF field names) and set their respective values in 
PDF
                        for (String fieldName : pdfLineTreeMap.keySet()) {

                                final String fieldValue = 
pdfLineTreeMap.get(fieldName);
                                // Try to retrieve the field in the template's 
acroForm with the same name
                                // as the column in csvDataArrayList
                                final PDField pDField = 
templateAcroForm.getField(fieldName);

                                // field with same name in CSV as in PDF was 
found...
                                if (pDField != null) {

                                        // Only circle non-empty insertion codes
                                        if (fieldName.indexOf("INSERT") >= 0 && fieldValue 
!= null && fieldValue.length() > 0) {
                                                circleField(pDField, 
templateFirstPage);
                                        }
                                        // add increment to it's partial name
                                        pDField.setPartialName(fieldName + "-" 
+ Integer.toString(csvLineCounter));
                                        pDField.setValue(fieldValue.trim());
                                        //pDField.setReadonly(true);

                                        finalDocFields.add(pDField);
                                }

                        } // end for fieldName

                        // Page number is in templateAcroForm (but not in 
pdfLineTreeMap)
                        final PDField pDPageField = 
templateAcroForm.getField("pagenumber");
                        if (pDPageField != null) {
                                pDPageField.setPartialName("pagenumber" + 
Integer.toString(csvLineCounter));
                                
pDPageField.setValue(Integer.toString(csvLineCounter + 1));
                                //pDPageField.setReadonly(true);
                                finalDocFields.add(pDPageField);
                        }

                        // Stop at second CSV line for debugging !!!!!
                        if (csvLineCounter == 2) {
                                break;
                        }

                        ++csvLineCounter;

                } // end for CSV Lines

                // Create new form in final document
                final PDAcroForm finalDocAcroForm = new PDAcroForm(finalDoc);
                // Set final document's form
                finalDoc.getDocumentCatalog().setAcroForm(finalDocAcroForm);
                // Set form's fields
                finalDocAcroForm.setFields(finalDocFields);
                        
                // Save final doc
                finalDoc.save(finalDocFilePath);
                finalDoc.close();

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to