You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by ph...@free.fr on 2015/04/29 14:26:39 UTC
AcroForm orientation
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.
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: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: AcroForm orientation
Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,
> Am 02.05.2015 um 13:02 schrieb Tilman Hausherr <TH...@t-online.de>:
>
> Am 29.04.2015 um 14:26 schrieb phiroc@free.fr:
>>
>> 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
I've created https://issues.apache.org/jira/browse/PDFBOX-2785 for that.
@ Philippe - could you attach your form to that issue so that we have a sample as there are different ways that rotation can be defined.
BR
Maruan
>
> 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: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: AcroForm orientation
Posted by Tilman Hausherr <TH...@t-online.de>.
Am 29.04.2015 um 14:26 schrieb phiroc@free.fr:
>
> 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: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org