unfortunately there are currently several FDF related issues in PDFBox - maybe
you hit one of these. Do you have to load an FDF or could you just do
PDField field = acroForm.getField("FieldName");
field.setValue("SampleValue");
BR
Maruan
Am 28.10.2014 um 18:56 schrieb Rajeev Menon <[email protected]>:
> I have no clue how to import FDF document into PDF using PDFBox. Here is
> what I tried, it just opens the pdf form with no data filled in.
>
> String targetDirectory=System.getProperty("java.io.tmpdir");
> File fout = new File(targetDirectory+"/newfile.fdf");
> FileOutputStream fos = new FileOutputStream(fout);
>
> BufferedWriter bw = new BufferedWriter(new
> OutputStreamWriter(fos));
>
> bw.write("%FDF-1.2");
> bw.write("1 0 obj <<");
> bw.write("/FDF <<");
> bw.write("/F(https://servername/abc.pdf)");
>
> bw.write("/Fields[");
> bw.write("<</T(FieldName)/V (Sample Value)>>");
> bw.write("]");
> bw.write(">>/Type/Catalog");
> bw.write(">>");
> bw.write("endobj");
> bw.write("trailer");
> bw.write("<</Root 1 0 R>>");
> bw.write("%%EOF");
> bw.close();
>
> FDFDocument fdfdoc=new FDFDocument();
> fdfdoc.load(new File(targetDirectory+"/newfile.fdf"));
>
> System.out.println("a:"+fdfdoc.getDocument().getCOSObject().toString());
>
> pdfDoc = PDDocument.load("https://servername/abcTemp.pdf");
> PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog();
> PDAcroForm acroForm = docCatalog.getAcroForm();
> //acroForm.setXFA(null);
> acroForm.importFDF(fdfdoc);
>
>
> FacesContext facesContext = FacesContext.getCurrentInstance();
> HttpServletResponse response = JSFUtil.getServletRespone();
> response.setContentType("application/pdf");
> response.addHeader("Content-Type",
> "application/force-download");
> response.addHeader("Content-Disposition", "attachment;
> filename=\"abc.pdf\"");
> ServletOutputStream outStream = response.getOutputStream();
> pdfDoc.save(outStream);
>
> facesContext.responseComplete();
>
>
>
> On Tue, Oct 28, 2014 at 12:37 PM, Rajeev Menon <[email protected]>
> wrote:
>
>> *How do I create the FDFDocument to import into the acroForm?*
>>
>> PDAcroForm acroForm = docCatalog.getAcroForm();
>> acroForm.setXFA(null);
>> acroForm.importFDF(FDFDocument arg0);
>>
>> *The following is how I send the FDF content to browser currently.*
>>
>>
>> output.println("%FDF-1.2");
>> output.println("1 0 obj <<");
>> output.println("/FDF <<");
>> output.println("/F(https://servername/sample.pdf)");
>>
>> output.println("/Fields[");
>> output.println("<</T(
>> FieldName1)/V (Hello World)>>");
>> output.println("]");
>> output.println(">>/Type/Catalog");
>> output.println(">>");
>> output.println("endobj");
>> output.println("trailer");
>> output.println("<</Root 1 0 R>>");
>> output.println("%%EOF");
>>
>> output.flush();
>> output.close();
>>
>>
>> On Tue, Oct 28, 2014 at 11:36 AM, Maruan Sahyoun <[email protected]>
>> wrote:
>>
>>> Hi Rajeev
>>>
>>> you should set the mime type to application/vnd.fdf.
>>>
>>> If you set the the NeedAppearances flag in AcroForm using PDFBox then
>>> Reader will generate the appearances for you when the document is opened.
>>> Might be an alternative to using FDF.
>>>
>>> BR
>>>
>>> Maruan
>>>
>>> Am 28.10.2014 um 15:33 schrieb Rajeev Menon <[email protected]>:
>>>
>>>> Hi,
>>>>
>>>> I am populating a PDF file by creating a FDF file and sending it to the
>>>> browser. The FDF file has the url of the PDF that it should open to fill
>>>> the data. The file opens fine inside the browser (inline), but when I
>>> want
>>>> to force it to open with acrobat reader, it just shows a white page in
>>> the
>>>> reader. Here is the relevant code.
>>>>
>>>> response.setContentType("application/pdf");
>>>> response.setHeader("Content-disposition","attachment;
>>>> filename=\"somefile.fdf\"");
>>>>
>>>> output.println("%FDF-1.2");
>>>> output.println("1 0 obj <<");
>>>> output.println("/FDF <<");
>>>> output.println("/F(https://servername/sample.pdf)");
>>>>
>>>> output.println("/Fields[");
>>>> output.println("<</T(FieldName1)/V (Hello World)>>");
>>>> output.println("]");
>>>> output.println(">>/Type/Catalog");
>>>> output.println(">>");
>>>> output.println("endobj");
>>>> output.println("trailer");
>>>> output.println("<</Root 1 0 R>>");
>>>> output.println("%%EOF");
>>>>
>>>> output.flush();
>>>> output.close();
>>>>
>>>> Please let me know if I am missing something here. I implemented the PDF
>>>> form filling using both the PDFBox and the FDF approaches, but I am
>>>> experiencing some issues with the PDFBox.
>>>>
>>>> Thanks,
>>>> Rajeev.
>>>
>>>
>>