You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Adam Retter <ad...@googlemail.com> on 2015/10/12 22:03:27 UTC

Insert Cover Page (2.0.0)

Hey there,

I want to add a cover page to a PDF, i.e. add a new *first* page to an
existing PDF.

I managed this with 1.8.0 by manipulating the page nodes via
PDPage#setParent, however I can't figure out how to do this with
2.0.0-SNAPSHOT.

Can anyone tell me how to insert a new page at index 0 for an existing PDF?
Perhaps subsequently adding an example to
https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/
could help others?

Thanks Adam.

-- 
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk

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


Re: Insert Cover Page (2.0.0)

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
> Am 13.10.2015 um 08:42 schrieb Tilman Hausherr <TH...@t-online.de>:
> 
> Am 13.10.2015 um 01:35 schrieb Maruan Sahyoun:
>> Hi,
>> 
>> I currently can't try it myself but
>> 
>> 	PDDocument document = PDDocument.load(…)
>>         PDPage pageToInsert = new PDPage();
>>         PDPageTree pageTree = document.getPages();
>>         COSDictionary pagesDictionary = (COSDictionary) document.getDocumentCatalog().getCOSObject().getDictionaryObject(COSName.PAGES);
>>         COSArray kids = (COSArray) pagesDictionary.getDictionaryObject(COSName.KIDS);
>>         kids.add(0,pageToInsert.getCOSObject());
>>         pageToInsert.getCOSObject().setItem(COSName.PARENT, pagesDictionary);
>>         pagesDictionary.setInt(COSName.COUNT, pagesDictionary.getInt(COSName.COUNT) + 1);
>> 	document.save(...);
>>         document.close();
> 
> Heh heh, after having looked at the source code, I think this should work fine. I thought there is some caching, but there isn't.
> 

yes, it does - tried it out this morning.

BR
Maruan

> Tilman
> 
>> 
>> BR
>> Maruan
>> 
>> 
>>> Am 13.10.2015 um 00:23 schrieb Adam Retter <ad...@googlemail.com>:
>>> 
>>> Thanks,
>>> 
>>> I have implemented it using merge, but unfortunately that almost
>>> doubles my processing time :-(
>>> 
>>> The steps my app takes:
>>> 
>>> 1. I take a PDF of almost 2000 pages and add a footer to each page.
>>> This takes about 12 seconds.
>>> 2. I then create a PDF which has my single cover page.
>>> 3. I merge the two PDFs together. This takes an additional 10 seconds.
>>> 
>>> I guess that if we had the ability to insert a page then it would be
>>> much faster than a merge?
>>> 
>>> On 12 October 2015 at 21:23, Tilman Hausherr <TH...@t-online.de> wrote:
>>>> Am 12.10.2015 um 22:03 schrieb Adam Retter:
>>>>> Hey there,
>>>>> 
>>>>> I want to add a cover page to a PDF, i.e. add a new *first* page to an
>>>>> existing PDF.
>>>>> 
>>>>> I managed this with 1.8.0 by manipulating the page nodes via
>>>>> PDPage#setParent, however I can't figure out how to do this with
>>>>> 2.0.0-SNAPSHOT.
>>>>> 
>>>>> Can anyone tell me how to insert a new page at index 0 for an existing
>>>>> PDF?
>>>>> Perhaps subsequently adding an example to
>>>>> 
>>>>> https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/
>>>>> could help others?
>>>> 
>>>> You can't... unless you create a new PDDocument with the cover page and then
>>>> run a merge.
>>>> 
>>>> Your feature request already has an issue:
>>>> https://issues.apache.org/jira/browse/PDFBOX-2400
>>>> 
>>>> Tilman
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>> 
>>> 
>>> 
>>> -- 
>>> Adam Retter
>>> 
>>> skype: adam.retter
>>> tweet: adamretter
>>> http://www.adamretter.org.uk
>>> 
>>> ---------------------------------------------------------------------
>>> 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: Insert Cover Page (2.0.0)

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 13.10.2015 um 01:35 schrieb Maruan Sahyoun:
> Hi,
>
> I currently can't try it myself but
>
> 	PDDocument document = PDDocument.load(…)
>          PDPage pageToInsert = new PDPage();
>          PDPageTree pageTree = document.getPages();
>          COSDictionary pagesDictionary = (COSDictionary) document.getDocumentCatalog().getCOSObject().getDictionaryObject(COSName.PAGES);
>          COSArray kids = (COSArray) pagesDictionary.getDictionaryObject(COSName.KIDS);
>          kids.add(0,pageToInsert.getCOSObject());
>          pageToInsert.getCOSObject().setItem(COSName.PARENT, pagesDictionary);
>          pagesDictionary.setInt(COSName.COUNT, pagesDictionary.getInt(COSName.COUNT) + 1);
> 	document.save(...);
>          document.close();

Heh heh, after having looked at the source code, I think this should 
work fine. I thought there is some caching, but there isn't.

Tilman

>
> BR
> Maruan
>
>
>> Am 13.10.2015 um 00:23 schrieb Adam Retter <ad...@googlemail.com>:
>>
>> Thanks,
>>
>> I have implemented it using merge, but unfortunately that almost
>> doubles my processing time :-(
>>
>> The steps my app takes:
>>
>> 1. I take a PDF of almost 2000 pages and add a footer to each page.
>> This takes about 12 seconds.
>> 2. I then create a PDF which has my single cover page.
>> 3. I merge the two PDFs together. This takes an additional 10 seconds.
>>
>> I guess that if we had the ability to insert a page then it would be
>> much faster than a merge?
>>
>> On 12 October 2015 at 21:23, Tilman Hausherr <TH...@t-online.de> wrote:
>>> Am 12.10.2015 um 22:03 schrieb Adam Retter:
>>>> Hey there,
>>>>
>>>> I want to add a cover page to a PDF, i.e. add a new *first* page to an
>>>> existing PDF.
>>>>
>>>> I managed this with 1.8.0 by manipulating the page nodes via
>>>> PDPage#setParent, however I can't figure out how to do this with
>>>> 2.0.0-SNAPSHOT.
>>>>
>>>> Can anyone tell me how to insert a new page at index 0 for an existing
>>>> PDF?
>>>> Perhaps subsequently adding an example to
>>>>
>>>> https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/
>>>> could help others?
>>>
>>> You can't... unless you create a new PDDocument with the cover page and then
>>> run a merge.
>>>
>>> Your feature request already has an issue:
>>> https://issues.apache.org/jira/browse/PDFBOX-2400
>>>
>>> Tilman
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>
>>
>>
>> -- 
>> Adam Retter
>>
>> skype: adam.retter
>> tweet: adamretter
>> http://www.adamretter.org.uk
>>
>> ---------------------------------------------------------------------
>> 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: Insert Cover Page (2.0.0)

Posted by John Hewson <jo...@jahewson.com>.
> Iterator<PDPage> iterator = doc.getPages.iterator()
> while(iterator.hasNext()) {
>  PDPage page = iterator.next();
>  addFooter(doc, page, regularFont, footerDetail)
> }

This can be simplified to:

> for(PDPage page : doc.getPages()) {
>  addFooter(doc, page, regularFont, footerDetail)
> }

— John

> On 13 Oct 2015, at 07:24, Adam Retter <ad...@googlemail.com> wrote:
> 
> On 13 October 2015 at 14:34, Maruan Sahyoun <sa...@fileaffairs.de> wrote:
>> Hi,
>> 
>> glad it worked. I would be interested in how you add the footer to the page i.e. how do you do the iteration, how do you add the additional content. It's always good for us to get a better understanding of how PDFBox is actually used.
>> 
> 
> Once I have opened my document, set some metadata and inserted my
> cover page, then I basically have something similar to this:
> 
> Iterator<PDPage> iterator = doc.getPages.iterator()
> while(iterator.hasNext()) {
>  PDPage page = iterator.next();
>  addFooter(doc, page, regularFont, footerDetail)
> }
> 
> private void addFooter(PDDocument doc, PDPage page, PDFont
> regularFont, FooterDetail footerDetail) {
>  try(final PDPageContentStream contentStream = new
> PDPageContentStream(doc, page, true, true, true)) {
>    //various positioning, and calls to beginText, setFont, showText, endText
>  }
> }
> 
> 
> -- 
> Adam Retter
> 
> skype: adam.retter
> tweet: adamretter
> http://www.adamretter.org.uk
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


Re: Insert Cover Page (2.0.0)

Posted by Adam Retter <ad...@googlemail.com>.
On 13 October 2015 at 14:34, Maruan Sahyoun <sa...@fileaffairs.de> wrote:
> Hi,
>
> glad it worked. I would be interested in how you add the footer to the page i.e. how do you do the iteration, how do you add the additional content. It's always good for us to get a better understanding of how PDFBox is actually used.
>

Once I have opened my document, set some metadata and inserted my
cover page, then I basically have something similar to this:

Iterator<PDPage> iterator = doc.getPages.iterator()
while(iterator.hasNext()) {
  PDPage page = iterator.next();
  addFooter(doc, page, regularFont, footerDetail)
}

private void addFooter(PDDocument doc, PDPage page, PDFont
regularFont, FooterDetail footerDetail) {
  try(final PDPageContentStream contentStream = new
PDPageContentStream(doc, page, true, true, true)) {
    //various positioning, and calls to beginText, setFont, showText, endText
  }
}


-- 
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk

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


Re: Insert Cover Page (2.0.0)

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

glad it worked. I would be interested in how you add the footer to the page i.e. how do you do the iteration, how do you add the additional content. It's always good for us to get a better understanding of how PDFBox is actually used.

BR
Maruan

Am 13.10.2015 um 13:29 schrieb Adam Retter <ad...@googlemail.com>:
> 
> Awesome :-)
> 
> Thanks very much, my process now runs in just 12 seconds and uses much
> less memory. Perfect :-)
> 
> On 13 October 2015 at 00:35, Maruan Sahyoun <sa...@fileaffairs.de> wrote:
>> Hi,
>> 
>> I currently can't try it myself but
>> 
>>        PDDocument document = PDDocument.load(…)
>>        PDPage pageToInsert = new PDPage();
>>        PDPageTree pageTree = document.getPages();
>>        COSDictionary pagesDictionary = (COSDictionary) document.getDocumentCatalog().getCOSObject().getDictionaryObject(COSName.PAGES);
>>        COSArray kids = (COSArray) pagesDictionary.getDictionaryObject(COSName.KIDS);
>>        kids.add(0,pageToInsert.getCOSObject());
>>        pageToInsert.getCOSObject().setItem(COSName.PARENT, pagesDictionary);
>>        pagesDictionary.setInt(COSName.COUNT, pagesDictionary.getInt(COSName.COUNT) + 1);
>>        document.save(...);
>>        document.close();
>> 
>> BR
>> Maruan
>> 
>> 
>>> Am 13.10.2015 um 00:23 schrieb Adam Retter <ad...@googlemail.com>:
>>> 
>>> Thanks,
>>> 
>>> I have implemented it using merge, but unfortunately that almost
>>> doubles my processing time :-(
>>> 
>>> The steps my app takes:
>>> 
>>> 1. I take a PDF of almost 2000 pages and add a footer to each page.
>>> This takes about 12 seconds.
>>> 2. I then create a PDF which has my single cover page.
>>> 3. I merge the two PDFs together. This takes an additional 10 seconds.
>>> 
>>> I guess that if we had the ability to insert a page then it would be
>>> much faster than a merge?
>>> 
>>> On 12 October 2015 at 21:23, Tilman Hausherr <TH...@t-online.de> wrote:
>>>> Am 12.10.2015 um 22:03 schrieb Adam Retter:
>>>>> 
>>>>> Hey there,
>>>>> 
>>>>> I want to add a cover page to a PDF, i.e. add a new *first* page to an
>>>>> existing PDF.
>>>>> 
>>>>> I managed this with 1.8.0 by manipulating the page nodes via
>>>>> PDPage#setParent, however I can't figure out how to do this with
>>>>> 2.0.0-SNAPSHOT.
>>>>> 
>>>>> Can anyone tell me how to insert a new page at index 0 for an existing
>>>>> PDF?
>>>>> Perhaps subsequently adding an example to
>>>>> 
>>>>> https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/
>>>>> could help others?
>>>> 
>>>> 
>>>> You can't... unless you create a new PDDocument with the cover page and then
>>>> run a merge.
>>>> 
>>>> Your feature request already has an issue:
>>>> https://issues.apache.org/jira/browse/PDFBOX-2400
>>>> 
>>>> Tilman
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>> 
>>> 
>>> 
>>> 
>>> --
>>> Adam Retter
>>> 
>>> skype: adam.retter
>>> tweet: adamretter
>>> http://www.adamretter.org.uk
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>> 
> 
> 
> 
> -- 
> Adam Retter
> 
> skype: adam.retter
> tweet: adamretter
> http://www.adamretter.org.uk
> 
> ---------------------------------------------------------------------
> 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: Insert Cover Page (2.0.0)

Posted by Adam Retter <ad...@googlemail.com>.
Awesome :-)

Thanks very much, my process now runs in just 12 seconds and uses much
less memory. Perfect :-)

On 13 October 2015 at 00:35, Maruan Sahyoun <sa...@fileaffairs.de> wrote:
> Hi,
>
> I currently can't try it myself but
>
>         PDDocument document = PDDocument.load(…)
>         PDPage pageToInsert = new PDPage();
>         PDPageTree pageTree = document.getPages();
>         COSDictionary pagesDictionary = (COSDictionary) document.getDocumentCatalog().getCOSObject().getDictionaryObject(COSName.PAGES);
>         COSArray kids = (COSArray) pagesDictionary.getDictionaryObject(COSName.KIDS);
>         kids.add(0,pageToInsert.getCOSObject());
>         pageToInsert.getCOSObject().setItem(COSName.PARENT, pagesDictionary);
>         pagesDictionary.setInt(COSName.COUNT, pagesDictionary.getInt(COSName.COUNT) + 1);
>         document.save(...);
>         document.close();
>
> BR
> Maruan
>
>
>> Am 13.10.2015 um 00:23 schrieb Adam Retter <ad...@googlemail.com>:
>>
>> Thanks,
>>
>> I have implemented it using merge, but unfortunately that almost
>> doubles my processing time :-(
>>
>> The steps my app takes:
>>
>> 1. I take a PDF of almost 2000 pages and add a footer to each page.
>> This takes about 12 seconds.
>> 2. I then create a PDF which has my single cover page.
>> 3. I merge the two PDFs together. This takes an additional 10 seconds.
>>
>> I guess that if we had the ability to insert a page then it would be
>> much faster than a merge?
>>
>> On 12 October 2015 at 21:23, Tilman Hausherr <TH...@t-online.de> wrote:
>>> Am 12.10.2015 um 22:03 schrieb Adam Retter:
>>>>
>>>> Hey there,
>>>>
>>>> I want to add a cover page to a PDF, i.e. add a new *first* page to an
>>>> existing PDF.
>>>>
>>>> I managed this with 1.8.0 by manipulating the page nodes via
>>>> PDPage#setParent, however I can't figure out how to do this with
>>>> 2.0.0-SNAPSHOT.
>>>>
>>>> Can anyone tell me how to insert a new page at index 0 for an existing
>>>> PDF?
>>>> Perhaps subsequently adding an example to
>>>>
>>>> https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/
>>>> could help others?
>>>
>>>
>>> You can't... unless you create a new PDDocument with the cover page and then
>>> run a merge.
>>>
>>> Your feature request already has an issue:
>>> https://issues.apache.org/jira/browse/PDFBOX-2400
>>>
>>> Tilman
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>
>>
>>
>>
>> --
>> Adam Retter
>>
>> skype: adam.retter
>> tweet: adamretter
>> http://www.adamretter.org.uk
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>



-- 
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk

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


Re: Insert Cover Page (2.0.0)

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

I currently can't try it myself but

	PDDocument document = PDDocument.load(…)
        PDPage pageToInsert = new PDPage();
        PDPageTree pageTree = document.getPages();
        COSDictionary pagesDictionary = (COSDictionary) document.getDocumentCatalog().getCOSObject().getDictionaryObject(COSName.PAGES);
        COSArray kids = (COSArray) pagesDictionary.getDictionaryObject(COSName.KIDS);
        kids.add(0,pageToInsert.getCOSObject());
        pageToInsert.getCOSObject().setItem(COSName.PARENT, pagesDictionary);
        pagesDictionary.setInt(COSName.COUNT, pagesDictionary.getInt(COSName.COUNT) + 1);
	document.save(...);
        document.close();

BR
Maruan


> Am 13.10.2015 um 00:23 schrieb Adam Retter <ad...@googlemail.com>:
> 
> Thanks,
> 
> I have implemented it using merge, but unfortunately that almost
> doubles my processing time :-(
> 
> The steps my app takes:
> 
> 1. I take a PDF of almost 2000 pages and add a footer to each page.
> This takes about 12 seconds.
> 2. I then create a PDF which has my single cover page.
> 3. I merge the two PDFs together. This takes an additional 10 seconds.
> 
> I guess that if we had the ability to insert a page then it would be
> much faster than a merge?
> 
> On 12 October 2015 at 21:23, Tilman Hausherr <TH...@t-online.de> wrote:
>> Am 12.10.2015 um 22:03 schrieb Adam Retter:
>>> 
>>> Hey there,
>>> 
>>> I want to add a cover page to a PDF, i.e. add a new *first* page to an
>>> existing PDF.
>>> 
>>> I managed this with 1.8.0 by manipulating the page nodes via
>>> PDPage#setParent, however I can't figure out how to do this with
>>> 2.0.0-SNAPSHOT.
>>> 
>>> Can anyone tell me how to insert a new page at index 0 for an existing
>>> PDF?
>>> Perhaps subsequently adding an example to
>>> 
>>> https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/
>>> could help others?
>> 
>> 
>> You can't... unless you create a new PDDocument with the cover page and then
>> run a merge.
>> 
>> Your feature request already has an issue:
>> https://issues.apache.org/jira/browse/PDFBOX-2400
>> 
>> Tilman
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
> 
> 
> 
> -- 
> Adam Retter
> 
> skype: adam.retter
> tweet: adamretter
> http://www.adamretter.org.uk
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


Re: Insert Cover Page (2.0.0)

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 13.10.2015 um 00:23 schrieb Adam Retter:
> Thanks,
>
> I have implemented it using merge, but unfortunately that almost
> doubles my processing time :-(
>
> The steps my app takes:
>
> 1. I take a PDF of almost 2000 pages and add a footer to each page.
> This takes about 12 seconds.
> 2. I then create a PDF which has my single cover page.
> 3. I merge the two PDFs together. This takes an additional 10 seconds.
>
> I guess that if we had the ability to insert a page then it would be
> much faster than a merge?

Yes, I'd guess that too.

Another possibility would be to add all PDPage elements to a new 
PDDocument and save that one. However you would also have to handle meta 
data and outlines and who knows what else.

Tilman

>
> On 12 October 2015 at 21:23, Tilman Hausherr <TH...@t-online.de> wrote:
>> Am 12.10.2015 um 22:03 schrieb Adam Retter:
>>> Hey there,
>>>
>>> I want to add a cover page to a PDF, i.e. add a new *first* page to an
>>> existing PDF.
>>>
>>> I managed this with 1.8.0 by manipulating the page nodes via
>>> PDPage#setParent, however I can't figure out how to do this with
>>> 2.0.0-SNAPSHOT.
>>>
>>> Can anyone tell me how to insert a new page at index 0 for an existing
>>> PDF?
>>> Perhaps subsequently adding an example to
>>>
>>> https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/
>>> could help others?
>>
>> You can't... unless you create a new PDDocument with the cover page and then
>> run a merge.
>>
>> Your feature request already has an issue:
>> https://issues.apache.org/jira/browse/PDFBOX-2400
>>
>> Tilman
>>
>> ---------------------------------------------------------------------
>> 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: Insert Cover Page (2.0.0)

Posted by Adam Retter <ad...@googlemail.com>.
Thanks,

I have implemented it using merge, but unfortunately that almost
doubles my processing time :-(

The steps my app takes:

1. I take a PDF of almost 2000 pages and add a footer to each page.
This takes about 12 seconds.
2. I then create a PDF which has my single cover page.
3. I merge the two PDFs together. This takes an additional 10 seconds.

I guess that if we had the ability to insert a page then it would be
much faster than a merge?

On 12 October 2015 at 21:23, Tilman Hausherr <TH...@t-online.de> wrote:
> Am 12.10.2015 um 22:03 schrieb Adam Retter:
>>
>> Hey there,
>>
>> I want to add a cover page to a PDF, i.e. add a new *first* page to an
>> existing PDF.
>>
>> I managed this with 1.8.0 by manipulating the page nodes via
>> PDPage#setParent, however I can't figure out how to do this with
>> 2.0.0-SNAPSHOT.
>>
>> Can anyone tell me how to insert a new page at index 0 for an existing
>> PDF?
>> Perhaps subsequently adding an example to
>>
>> https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/
>> could help others?
>
>
> You can't... unless you create a new PDDocument with the cover page and then
> run a merge.
>
> Your feature request already has an issue:
> https://issues.apache.org/jira/browse/PDFBOX-2400
>
> Tilman
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>



-- 
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk

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


Re: Insert Cover Page (2.0.0)

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 12.10.2015 um 22:03 schrieb Adam Retter:
> Hey there,
>
> I want to add a cover page to a PDF, i.e. add a new *first* page to an
> existing PDF.
>
> I managed this with 1.8.0 by manipulating the page nodes via
> PDPage#setParent, however I can't figure out how to do this with
> 2.0.0-SNAPSHOT.
>
> Can anyone tell me how to insert a new page at index 0 for an existing PDF?
> Perhaps subsequently adding an example to
> https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/
> could help others?

You can't... unless you create a new PDDocument with the cover page and 
then run a merge.

Your feature request already has an issue:
https://issues.apache.org/jira/browse/PDFBOX-2400

Tilman

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