You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Subrata Kumar Pradhan (JIRA)" <ji...@apache.org> on 2017/09/07 10:25:00 UTC

[jira] [Comment Edited] (PDFBOX-3924) How to flatten pdf which contains acroform fields

    [ https://issues.apache.org/jira/browse/PDFBOX-3924?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16156783#comment-16156783 ] 

Subrata Kumar Pradhan edited comment on PDFBOX-3924 at 9/7/17 10:24 AM:
------------------------------------------------------------------------

if you remove this line "acroForm.setNeedAppearances(true); then only you will get "U+xxxx is not available in this font's encoding: WinAnsiEncoding". i want setNeedAppearances should be true.
Here i am generating a pdf which contain some acroForm and in the acroForm i am setting both Hindi and English language and PDFBox doesn't support Hindi Font. if  setNeedAppearances is true then only i am able to generate the pdf otherwise i am getting an exception. Now i what the pdf should be flatten means i want the acroForm field value but not the form field.



was (Author: subrata1945):
if you remove this line "acroForm.setNeedAppearances(true); then only you will get "U+xxxx is not available in this font's encoding: WinAnsiEncoding". i want setNeedAppearances should be true.
Here i am generating a pdf which contain some acroForm and in the acroForm i am setting both Hindi and English language and PDFBox doesn't support Hindi Font. if  setNeedAppearances is true then only i am able to generate the pdf otherwise i am gettign an exception. Now i what the pdf should be flatten means i want the acroForm field value but not the form field.


> How to flatten  pdf which contains acroform fields
> --------------------------------------------------
>
>                 Key: PDFBOX-3924
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3924
>             Project: PDFBox
>          Issue Type: Improvement
>          Components: AcroForm
>    Affects Versions: 2.0.7
>         Environment: Windows 10
>            Reporter: Subrata Kumar Pradhan
>            Priority: Critical
>             Fix For: 2.0.7
>
>         Attachments: CPIS_test_language.pdf
>
>
> After set the value in the acroForm fields, i want to flatten the pdf. so that there should not be any form fields in my output pdf and when i am writing acroForm.flatten() it's not working.
> Here is my java code:
> {code}
> package com.sdrc.image;
> import java.io.File;
> import java.util.List;
> import org.apache.pdfbox.pdmodel.PDDocument;
> import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
> import org.apache.pdfbox.pdmodel.interactive.form.PDField;
> public class PDFBoxLanguageTest {
> 	public static void main(String[] args) throws Exception {
> 		
> 	    String formTemplate = "C:/Users/XXXX/Downloads/CPIS_test_language.pdf";
>             PDDocument pdfDocument = PDDocument.load(new File(formTemplate));
>             PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
>             acroForm.setNeedAppearances(true); //need this line for Hindi
>         
>             if (acroForm != null) {
>                 // Get field names
>                 List<PDField> fieldList = acroForm.getFields();
>                 for (PDField pdField : fieldList) {
>             	    if (pdField.getFullyQualifiedName().equals("Text1")){
>             		// Here i am passing a text in "English"
>     			acroForm.getField(pdField.getFullyQualifiedName()).setValue("Welcome");
>                         //pdField.setReadOnly(true);// not working
>                         //pdField.getCOSObject().setInt("FF", 1);// not working
>             	    } else if (pdField.getFullyQualifiedName().equals("Text3")) {
>             		// Here i am passing a text in "English-Hindi"
>     			acroForm.getField(pdField.getFullyQualifiedName()).setValue("Welcome-नमस्ते");	
>                         //pdField.setReadOnly(true);// not working
>                         //pdField.getCOSObject().setInt("FF", 1);// not working
>             	    } else {
>             		// Here i am passing a text in "Hindi"
>     			acroForm.getField(pdField.getFullyQualifiedName()).setValue("नमस्ते");
>             	        //pdField.setReadOnly(true);// not working
>                         //pdField.getCOSObject().setInt("FF", 1);// not working
>                     }
> 	        }
>             }
>             // acroForm.flatten(); // not working
>             pdfDocument.save("C:/Users/XXXX/Downloads/CPIS_test_languageE.pdf");
>             // acroForm.flatten();  // not working
>             pdfDocument.close();
>             System.out.println("Done");
>             System.out.println("============================================");
> 	}
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

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