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/21 11:32:27 UTC

Copying PDPages

Hello,

I would like to copy several times the first page of a PDF document to another.

What is the best way to do this?

Many thanks.

Philippe

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


Re: Filling out PDPage forms

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,

> Am 21.04.2015 um 18:15 schrieb phiroc@free.fr:
> 
> 
> Hi Maruan,
> 
> I have tried importing the form using LayerUtility.importPageAsForm(), into the destination PDF, as follows (sorry, Scala code, but comprehensible).

No, this will give you a page you can mount not another one - has nothing to do with AcroForm.

Did you follow the stack overflow post I mentioned?

BR
Maruan

> 
> However, the page is blank.
> 
> Is importPageAsForm the right method to import a form?
> 
> Cheers,
> 
> Philippe
> 
> 
> --------------------------------------------------
> import org.apache.pdfbox.pdmodel._
> import org.apache.pdfbox.util._
> import org.apache.pdfbox.pdmodel.common.PDRectangle
> 
> object App {
> 
>  def main(args: Array[String]) = {
> 
>  	val pathToPdfTemplateFile = "D:\\dev\\ProjectData\\fillbundlelabelformData\\pdf\\template\\LO_Labels210315_formulaire.pdf"
>  	val pathToClonedFile = "D:\\dev\\ProjectData\\fillbundlelabelformData\\pdf\\generated\\clone.pdf"
>  	
>  	val templatePDDocument = PDDocument.load(pathToPdfTemplateFile)
>  	val clonedDocument = new PDDocument
>  	val pDPage = new PDPage(new PDRectangle(612, 792))
>  	clonedDocument.addPage(pDPage)
>  	val aLayerUtility = new LayerUtility(clonedDocument)
>  	val aPDXObjectForm = aLayerUtility.importPageAsForm(templatePDDocument, 0)     
>        clonedDocument.save(pathToClonedFile)
>        clonedDocument.close
> 	templatePDDocument.close
> 		
>  }
> 
> }
> ----------------------------------------------------------
> 
> 
> 
> ----- Mail original -----
> De: "Maruan Sahyoun" <sa...@fileaffairs.de>
> À: users@pdfbox.apache.org
> Envoyé: Mardi 21 Avril 2015 15:39:37
> Objet: Re: Filling out PDPage forms
> 
> OK,
> 
>> Am 21.04.2015 um 15:04 schrieb phiroc@free.fr:
>> 
>> Hi,
>> 
>> unfortunately, once I have imported several copies of the source PDF form page into the destination PDF, PDDocument.getDocumentCatalog().getAcroForm() returns null.
>> 
> 
> so you have only imported the pages but not the AcroForm. If you import the AcroForm this will only have the fields pointing to the source page. You need to create new fields from the ones you have with unique names as I assume the fields on subsequent pages shall have their own content.  There is a sample available at http://stackoverflow.com/questions/29371129/java-pdfbox-fill-out-pdf-form-append-it-to-pddocument-and-repeat/29417945#29417945 <http://stackoverflow.com/questions/29371129/java-pdfbox-fill-out-pdf-form-append-it-to-pddocument-and-repeat/29417945#29417945>
> 
> BR
> 
> Maruan
> 
> 
>> 
>> 
>> ----- Mail original -----
>> De: "Maruan Sahyoun" <sa...@fileaffairs.de>
>> À: users@pdfbox.apache.org
>> Envoyé: Mardi 21 Avril 2015 14:53:48
>> Objet: Re: Filling out PDPage forms
>> 
>> Hi,
>> 
>>> Am 21.04.2015 um 12:35 schrieb phiroc@free.fr:
>>> 
>>> 
>>> The source PDF contains a form which I need to make multiple copies of, in the destination PDF.
>>> 
>>> I have adapted code found on Stack Overflow to retrieve the source PDF's first page:
>>> 
>>> PDPage firstPage = (PDPage) templatePDDocument.getDocumentCatalog().getAllPages().get(0);
>>> ...
>>> 
>>> and then to import it into the destination PDF:
>>> 
>>> PDPage clonedPDPage = clonedDocument.importPage(firstPage);
>>> ...
>>> 
>>> The destination PDF now contains several copies of the form.
>>> 
>>> I now need to fill out the forms with data from a CSV file.
>>> 
>>> How do I retrieve each page's form field, given that there's no PDPage.getAcroForm() function?
>> 
>> AcroForms are not page related as a field can appear on multiple pages. You need to use doc.getDocumentCatalog().getAcroForm() to retrieve the form.
>> 
>> 
>> BR
>> Maruan
>> 
>>> 
>>> Cheers,
>>> 
>>> Philippe
>>> 
>>> 
>>> ----- Mail original -----
>>> De: phiroc@free.fr
>>> À: users@pdfbox.apache.org
>>> Envoyé: Mardi 21 Avril 2015 11:32:27
>>> Objet: Copying PDPages
>>> 
>>> Hello,
>>> 
>>> I would like to copy several times the first page of a PDF document to another.
>>> 
>>> What is the best way to do this?
>>> 
>>> Many thanks.
>>> 
>>> Philippe
>>> 
>>> ---------------------------------------------------------------------
>>> 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
>> 
>> 
>> ---------------------------------------------------------------------
>> 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: Filling out PDPage forms

Posted by ph...@free.fr.
Hi Maruan,

I have tried importing the form using LayerUtility.importPageAsForm(), into the destination PDF, as follows (sorry, Scala code, but comprehensible).

However, the page is blank.

Is importPageAsForm the right method to import a form?

Cheers,

Philippe


--------------------------------------------------
import org.apache.pdfbox.pdmodel._
import org.apache.pdfbox.util._
import org.apache.pdfbox.pdmodel.common.PDRectangle

object App {

  def main(args: Array[String]) = {
  
  	val pathToPdfTemplateFile = "D:\\dev\\ProjectData\\fillbundlelabelformData\\pdf\\template\\LO_Labels210315_formulaire.pdf"
  	val pathToClonedFile = "D:\\dev\\ProjectData\\fillbundlelabelformData\\pdf\\generated\\clone.pdf"
  	
  	val templatePDDocument = PDDocument.load(pathToPdfTemplateFile)
  	val clonedDocument = new PDDocument
  	val pDPage = new PDPage(new PDRectangle(612, 792))
  	clonedDocument.addPage(pDPage)
  	val aLayerUtility = new LayerUtility(clonedDocument)
  	val aPDXObjectForm = aLayerUtility.importPageAsForm(templatePDDocument, 0)     
        clonedDocument.save(pathToClonedFile)
        clonedDocument.close
	templatePDDocument.close
		
  }

}
----------------------------------------------------------



----- Mail original -----
De: "Maruan Sahyoun" <sa...@fileaffairs.de>
À: users@pdfbox.apache.org
Envoyé: Mardi 21 Avril 2015 15:39:37
Objet: Re: Filling out PDPage forms

OK,

> Am 21.04.2015 um 15:04 schrieb phiroc@free.fr:
> 
> Hi,
> 
> unfortunately, once I have imported several copies of the source PDF form page into the destination PDF, PDDocument.getDocumentCatalog().getAcroForm() returns null.
> 

so you have only imported the pages but not the AcroForm. If you import the AcroForm this will only have the fields pointing to the source page. You need to create new fields from the ones you have with unique names as I assume the fields on subsequent pages shall have their own content.  There is a sample available at http://stackoverflow.com/questions/29371129/java-pdfbox-fill-out-pdf-form-append-it-to-pddocument-and-repeat/29417945#29417945 <http://stackoverflow.com/questions/29371129/java-pdfbox-fill-out-pdf-form-append-it-to-pddocument-and-repeat/29417945#29417945>

BR

Maruan


> 
> 
> ----- Mail original -----
> De: "Maruan Sahyoun" <sa...@fileaffairs.de>
> À: users@pdfbox.apache.org
> Envoyé: Mardi 21 Avril 2015 14:53:48
> Objet: Re: Filling out PDPage forms
> 
> Hi,
> 
>> Am 21.04.2015 um 12:35 schrieb phiroc@free.fr:
>> 
>> 
>> The source PDF contains a form which I need to make multiple copies of, in the destination PDF.
>> 
>> I have adapted code found on Stack Overflow to retrieve the source PDF's first page:
>> 
>> PDPage firstPage = (PDPage) templatePDDocument.getDocumentCatalog().getAllPages().get(0);
>> ...
>> 
>> and then to import it into the destination PDF:
>> 
>> PDPage clonedPDPage = clonedDocument.importPage(firstPage);
>> ...
>> 
>> The destination PDF now contains several copies of the form.
>> 
>> I now need to fill out the forms with data from a CSV file.
>> 
>> How do I retrieve each page's form field, given that there's no PDPage.getAcroForm() function?
> 
> AcroForms are not page related as a field can appear on multiple pages. You need to use doc.getDocumentCatalog().getAcroForm() to retrieve the form.
> 
> 
> BR
> Maruan
> 
>> 
>> Cheers,
>> 
>> Philippe
>> 
>> 
>> ----- Mail original -----
>> De: phiroc@free.fr
>> À: users@pdfbox.apache.org
>> Envoyé: Mardi 21 Avril 2015 11:32:27
>> Objet: Copying PDPages
>> 
>> Hello,
>> 
>> I would like to copy several times the first page of a PDF document to another.
>> 
>> What is the best way to do this?
>> 
>> Many thanks.
>> 
>> Philippe
>> 
>> ---------------------------------------------------------------------
>> 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
> 
> 
> ---------------------------------------------------------------------
> 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: Filling out PDPage forms

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
OK,

> Am 21.04.2015 um 15:04 schrieb phiroc@free.fr:
> 
> Hi,
> 
> unfortunately, once I have imported several copies of the source PDF form page into the destination PDF, PDDocument.getDocumentCatalog().getAcroForm() returns null.
> 

so you have only imported the pages but not the AcroForm. If you import the AcroForm this will only have the fields pointing to the source page. You need to create new fields from the ones you have with unique names as I assume the fields on subsequent pages shall have their own content.  There is a sample available at http://stackoverflow.com/questions/29371129/java-pdfbox-fill-out-pdf-form-append-it-to-pddocument-and-repeat/29417945#29417945 <http://stackoverflow.com/questions/29371129/java-pdfbox-fill-out-pdf-form-append-it-to-pddocument-and-repeat/29417945#29417945>

BR

Maruan


> 
> 
> ----- Mail original -----
> De: "Maruan Sahyoun" <sa...@fileaffairs.de>
> À: users@pdfbox.apache.org
> Envoyé: Mardi 21 Avril 2015 14:53:48
> Objet: Re: Filling out PDPage forms
> 
> Hi,
> 
>> Am 21.04.2015 um 12:35 schrieb phiroc@free.fr:
>> 
>> 
>> The source PDF contains a form which I need to make multiple copies of, in the destination PDF.
>> 
>> I have adapted code found on Stack Overflow to retrieve the source PDF's first page:
>> 
>> PDPage firstPage = (PDPage) templatePDDocument.getDocumentCatalog().getAllPages().get(0);
>> ...
>> 
>> and then to import it into the destination PDF:
>> 
>> PDPage clonedPDPage = clonedDocument.importPage(firstPage);
>> ...
>> 
>> The destination PDF now contains several copies of the form.
>> 
>> I now need to fill out the forms with data from a CSV file.
>> 
>> How do I retrieve each page's form field, given that there's no PDPage.getAcroForm() function?
> 
> AcroForms are not page related as a field can appear on multiple pages. You need to use doc.getDocumentCatalog().getAcroForm() to retrieve the form.
> 
> 
> BR
> Maruan
> 
>> 
>> Cheers,
>> 
>> Philippe
>> 
>> 
>> ----- Mail original -----
>> De: phiroc@free.fr
>> À: users@pdfbox.apache.org
>> Envoyé: Mardi 21 Avril 2015 11:32:27
>> Objet: Copying PDPages
>> 
>> Hello,
>> 
>> I would like to copy several times the first page of a PDF document to another.
>> 
>> What is the best way to do this?
>> 
>> Many thanks.
>> 
>> Philippe
>> 
>> ---------------------------------------------------------------------
>> 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
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


Re: Filling out PDPage forms

Posted by ph...@free.fr.
Hi Richard,

thanks for the suggestions, but I am not supposed to use Adobe Designer.

I have found a solution.

for all CSV data lines:
- open template PDF containing form
- fill form with data from CSV line
- save form as PDF with unique name (e.g., timestamp) in temporary directory

Next, use PDFMergerUtility to merge the PDFs into a single PDF.

There's no need to worry about AcroForms anymore.

Philippe


----- Mail original -----
De: "Richard Johnson" <ri...@ytivarg.com>
À: users@pdfbox.apache.org
Cc: phiroc@free.fr
Envoyé: Mardi 21 Avril 2015 15:19:33
Objet: Re: Filling out PDPage forms

Here's how I understand it--and I might well be wrong.  I'm just a user.

The document has pages.
The document has a form.

When you clone the first page into your working document, that page is not part 
of the form that came with the original and which remains unchanged.   You 
probably could make a new (output) document and put a new doc catalog and a 
new form on it.   

If it were me (and I'm by nature incredibly lazy) I'd use Adobe or MasterPDF 
to save the first page as a jpg, then make a whole new doc with that jpg as a 
template/background, add a whole new set of fields on top of it (several 
times), make sure every field was named uniquely ... and start my processing 
with that.  
-- 
Richard Johnson


On Tuesday, April 21, 2015 03:04:03 PM phiroc@free.fr wrote:
> Hi,
> 
> unfortunately, once I have imported several copies of the source PDF form 
page into the destination PDF, PDDocument.getDocumentCatalog().getAcroForm() 
returns null.
> 
> 
> 
> ----- Mail original -----
> De: "Maruan Sahyoun" <sa...@fileaffairs.de>
> À: users@pdfbox.apache.org
> Envoyé: Mardi 21 Avril 2015 14:53:48
> Objet: Re: Filling out PDPage forms
> 
> Hi,
> 
> > Am 21.04.2015 um 12:35 schrieb phiroc@free.fr:
> > 
> > 
> > The source PDF contains a form which I need to make multiple copies of, in 
the destination PDF.
> > 
> > I have adapted code found on Stack Overflow to retrieve the source PDF's 
first page:
> > 
> > PDPage firstPage = (PDPage) 
templatePDDocument.getDocumentCatalog().getAllPages().get(0);
> > ...
> > 
> > and then to import it into the destination PDF:
> > 
> > PDPage clonedPDPage = clonedDocument.importPage(firstPage);
> > ...
> > 
> > The destination PDF now contains several copies of the form.
> > 
> > I now need to fill out the forms with data from a CSV file.
> > 
> > How do I retrieve each page's form field, given that there's no 
PDPage.getAcroForm() function?
> 
> AcroForms are not page related as a field can appear on multiple pages. You 
need to use doc.getDocumentCatalog().getAcroForm() to retrieve the form.
> 
> 
> BR
> Maruan
> 
> > 
> > Cheers,
> > 
> > Philippe
> > 
> > 
> > ----- Mail original -----
> > De: phiroc@free.fr
> > À: users@pdfbox.apache.org
> > Envoyé: Mardi 21 Avril 2015 11:32:27
> > Objet: Copying PDPages
> > 
> > Hello,
> > 
> > I would like to copy several times the first page of a PDF document to 
another.
> > 
> > What is the best way to do this?
> > 
> > Many thanks.
> > 
> > Philippe
> > 
> > ---------------------------------------------------------------------
> > 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
> 
> 
> ---------------------------------------------------------------------
> 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: Filling out PDPage forms

Posted by Richard Johnson <ri...@ytivarg.com>.
Here's how I understand it--and I might well be wrong.  I'm just a user.

The document has pages.
The document has a form.

When you clone the first page into your working document, that page is not part 
of the form that came with the original and which remains unchanged.   You 
probably could make a new (output) document and put a new doc catalog and a 
new form on it.   

If it were me (and I'm by nature incredibly lazy) I'd use Adobe or MasterPDF 
to save the first page as a jpg, then make a whole new doc with that jpg as a 
template/background, add a whole new set of fields on top of it (several 
times), make sure every field was named uniquely ... and start my processing 
with that.  
-- 
Richard Johnson


On Tuesday, April 21, 2015 03:04:03 PM phiroc@free.fr wrote:
> Hi,
> 
> unfortunately, once I have imported several copies of the source PDF form 
page into the destination PDF, PDDocument.getDocumentCatalog().getAcroForm() 
returns null.
> 
> 
> 
> ----- Mail original -----
> De: "Maruan Sahyoun" <sa...@fileaffairs.de>
> À: users@pdfbox.apache.org
> Envoyé: Mardi 21 Avril 2015 14:53:48
> Objet: Re: Filling out PDPage forms
> 
> Hi,
> 
> > Am 21.04.2015 um 12:35 schrieb phiroc@free.fr:
> > 
> > 
> > The source PDF contains a form which I need to make multiple copies of, in 
the destination PDF.
> > 
> > I have adapted code found on Stack Overflow to retrieve the source PDF's 
first page:
> > 
> > PDPage firstPage = (PDPage) 
templatePDDocument.getDocumentCatalog().getAllPages().get(0);
> > ...
> > 
> > and then to import it into the destination PDF:
> > 
> > PDPage clonedPDPage = clonedDocument.importPage(firstPage);
> > ...
> > 
> > The destination PDF now contains several copies of the form.
> > 
> > I now need to fill out the forms with data from a CSV file.
> > 
> > How do I retrieve each page's form field, given that there's no 
PDPage.getAcroForm() function?
> 
> AcroForms are not page related as a field can appear on multiple pages. You 
need to use doc.getDocumentCatalog().getAcroForm() to retrieve the form.
> 
> 
> BR
> Maruan
> 
> > 
> > Cheers,
> > 
> > Philippe
> > 
> > 
> > ----- Mail original -----
> > De: phiroc@free.fr
> > À: users@pdfbox.apache.org
> > Envoyé: Mardi 21 Avril 2015 11:32:27
> > Objet: Copying PDPages
> > 
> > Hello,
> > 
> > I would like to copy several times the first page of a PDF document to 
another.
> > 
> > What is the best way to do this?
> > 
> > Many thanks.
> > 
> > Philippe
> > 
> > ---------------------------------------------------------------------
> > 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
> 
> 
> ---------------------------------------------------------------------
> 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: Filling out PDPage forms

Posted by ph...@free.fr.
Hi,

unfortunately, once I have imported several copies of the source PDF form page into the destination PDF, PDDocument.getDocumentCatalog().getAcroForm() returns null.



----- Mail original -----
De: "Maruan Sahyoun" <sa...@fileaffairs.de>
À: users@pdfbox.apache.org
Envoyé: Mardi 21 Avril 2015 14:53:48
Objet: Re: Filling out PDPage forms

Hi,

> Am 21.04.2015 um 12:35 schrieb phiroc@free.fr:
> 
> 
> The source PDF contains a form which I need to make multiple copies of, in the destination PDF.
> 
> I have adapted code found on Stack Overflow to retrieve the source PDF's first page:
> 
> PDPage firstPage = (PDPage) templatePDDocument.getDocumentCatalog().getAllPages().get(0);
> ...
> 
> and then to import it into the destination PDF:
> 
> PDPage clonedPDPage = clonedDocument.importPage(firstPage);
> ...
> 
> The destination PDF now contains several copies of the form.
> 
> I now need to fill out the forms with data from a CSV file.
> 
> How do I retrieve each page's form field, given that there's no PDPage.getAcroForm() function?

AcroForms are not page related as a field can appear on multiple pages. You need to use doc.getDocumentCatalog().getAcroForm() to retrieve the form.


BR
Maruan

> 
> Cheers,
> 
> Philippe
> 
> 
> ----- Mail original -----
> De: phiroc@free.fr
> À: users@pdfbox.apache.org
> Envoyé: Mardi 21 Avril 2015 11:32:27
> Objet: Copying PDPages
> 
> Hello,
> 
> I would like to copy several times the first page of a PDF document to another.
> 
> What is the best way to do this?
> 
> Many thanks.
> 
> Philippe
> 
> ---------------------------------------------------------------------
> 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


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


Re: Filling out PDPage forms

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,

> Am 21.04.2015 um 12:35 schrieb phiroc@free.fr:
> 
> 
> The source PDF contains a form which I need to make multiple copies of, in the destination PDF.
> 
> I have adapted code found on Stack Overflow to retrieve the source PDF's first page:
> 
> PDPage firstPage = (PDPage) templatePDDocument.getDocumentCatalog().getAllPages().get(0);
> ...
> 
> and then to import it into the destination PDF:
> 
> PDPage clonedPDPage = clonedDocument.importPage(firstPage);
> ...
> 
> The destination PDF now contains several copies of the form.
> 
> I now need to fill out the forms with data from a CSV file.
> 
> How do I retrieve each page's form field, given that there's no PDPage.getAcroForm() function?

AcroForms are not page related as a field can appear on multiple pages. You need to use doc.getDocumentCatalog().getAcroForm() to retrieve the form.


BR
Maruan

> 
> Cheers,
> 
> Philippe
> 
> 
> ----- Mail original -----
> De: phiroc@free.fr
> À: users@pdfbox.apache.org
> Envoyé: Mardi 21 Avril 2015 11:32:27
> Objet: Copying PDPages
> 
> Hello,
> 
> I would like to copy several times the first page of a PDF document to another.
> 
> What is the best way to do this?
> 
> Many thanks.
> 
> Philippe
> 
> ---------------------------------------------------------------------
> 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


Filling out PDPage forms

Posted by ph...@free.fr.
The source PDF contains a form which I need to make multiple copies of, in the destination PDF.

I have adapted code found on Stack Overflow to retrieve the source PDF's first page:

PDPage firstPage = (PDPage) templatePDDocument.getDocumentCatalog().getAllPages().get(0);
...

and then to import it into the destination PDF:

PDPage clonedPDPage = clonedDocument.importPage(firstPage);
...

The destination PDF now contains several copies of the form.

I now need to fill out the forms with data from a CSV file.

How do I retrieve each page's form field, given that there's no PDPage.getAcroForm() function?

Cheers,

Philippe


----- Mail original -----
De: phiroc@free.fr
À: users@pdfbox.apache.org
Envoyé: Mardi 21 Avril 2015 11:32:27
Objet: Copying PDPages

Hello,

I would like to copy several times the first page of a PDF document to another.

What is the best way to do this?

Many thanks.

Philippe

---------------------------------------------------------------------
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