You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Andreas Lehmkühler (JIRA)" <ji...@apache.org> on 2014/10/15 12:27:34 UTC
[jira] [Closed] (PDFBOX-481) renaming a field and not able to set
value to the saved PDF document ...
[ https://issues.apache.org/jira/browse/PDFBOX-481?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andreas Lehmkühler closed PDFBOX-481.
-------------------------------------
Resolution: Not a Problem
Assignee: Andreas Lehmkühler
The origin issue (filling the acroform) was invalid as it seemed to work. The rendering issue was solved some time in the past too.
> renaming a field and not able to set value to the saved PDF document ...
> ------------------------------------------------------------------------
>
> Key: PDFBOX-481
> URL: https://issues.apache.org/jira/browse/PDFBOX-481
> Project: PDFBox
> Issue Type: Bug
> Components: AcroForm
> Affects Versions: 0.7.3
> Environment: Windows XP Professional SP3, jre1.6.0_07/jdk1.6.0_11 , PDFBox-0.7.3.jar
> Reporter: Venkatesh Prasad.B.K.
> Assignee: Andreas Lehmkühler
> Attachments: PDFBOX481-Source_Target_filled.pdf, Source_Original.pdf, Source_Target.pdf
>
>
> I will explain what I want to do.
> 1. I have a PDF Document with Fields and let us call this 'Source_Original.PDF'. The field names in this PDF document have to be renamed and stored as 'Source_Target.PDF'. I then have to set/change the values of form-fields in 'Source_Target.PDF'.
> The issue I am facing is given below:
> 1. I renamed the form fields in 'Source_Original.PDF" using the code given in my earlier mail (below) and saved it as 'Source_Target.PDF'.
> 2. I checked the form fields in 'Source_Target.PDF" and form-fields were renamed correctly.
> 3. However when I tried to set/change values of form-fields in 'Source_Target.PDF' using PDFBox code, I was not able to do so.
> I used iText to set/change values of form-fields in 'Source_Target.PDF' and was successful. But we want to use only PDFBox.
> To summarize - We are not able to set/change values of form fields of a PDF Document whose form-fields have been renamed. There is no issue if the form-fields are renamed manually using Adobe Acrobat 9. The issue is only
> when the form-fields are renamed using PDFBox option - setPartialName(newFieldName);
> > Only to be sure, changing values in 'Source_Original.PDF' works with the same code you use to
> > manipulate 'Source_Target.PDF'??
> Yes
> I have attached the 2 files - "Source_Original.PDF' and 'Source_Target.PDF',
> ----- Code
> try
> {
> PDDocument pdfDocument = PDDocument.load(pdfSource);
> try
> {
> if (pdfDocument.isEncrypted())
> {
> pdfDocument.decrypt("");
> }
> PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
> PDAcroForm acroForm = docCatalog.getAcroForm();
> if (acroForm != null)
> {
> List pdfFields = acroForm.getFields();
> if (pdfFields != null)
> {
> PDField pdfField;
> for (int i = 0; i < pdfFields.size(); i++)
> {
> pdfField = (PDField) pdfFields.get(i);
> String fieldName = pdfField.getPartialName();
> if( pdfFieldNames.containsKey(fieldName) ){
> String newFieldName = (String) pdfFieldNames.get(fieldName);
> pdfField.setPartialName(newFieldName);
> }
> }
> pdfDocument.save(pdfOutput);
> } else {
> return "No Acro Form Fields found in PDF Document " + pdfSource + "!";
> }
> } else {
> return "PDF document " + pdfSource + " not able to access!";
> }
> } catch (Exception e) {
> return "PDF Document " + pdfSource + " is encrypted! Cannot process.";
> }
> pdfDocument.close();
> } catch (Exception e) {
> return "PDF Document " + pdfSource + " cannot be found!";
> }
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)