pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Foley Ma <fole...@gmail.com>
Subject Re: Extracting a page and recreating a document
Date Sun, 17 Jun 2012 22:27:35 GMT
I decided to use the Splitter class. Thank you very much!

Foley

On Sun, Jun 17, 2012 at 5:56 PM, Gilad Denneboom
<gilad.denneboom@gmail.com> wrote:
> You can use the
> PDFSplit<http://pdfbox.apache.org/apidocs/org/apache/pdfbox/PDFSplit.html>class,
> or for a more basic approach, the
> Splitter<http://pdfbox.apache.org/apidocs/org/apache/pdfbox/util/Splitter.html>util
> directly.
>
> On Sun, Jun 17, 2012 at 11:44 PM, Foley Ma <foleyma@gmail.com> wrote:
>
>> Hello,
>> I'm trying to use PDFBox to extract a page from a multi page document
>> and creating a new document from it. I thought it would be as simple
>> as getting the PDPage, get contents..then create a new PDPage, set
>> content, and add it to a new PDDocument...but I guess it's not that
>> straight forward, or I'm missing something.
>>
>> If I extract a PDPage, and put that same PDPAge it in a new document
>> and save it, it works.
>>
>> i.e.
>>
>> InputStream fileStream =
>> this.getClass().getResourceAsStream("sample.pdf");
>> PDDocument document = PDDocument.load(fileStream);
>> PDPage pdfPage = (PDPage)
>> document.getDocumentCatalog().getAllPages().get(0);
>>
>> PDDocument document2 = new PDDocument();
>>
>>
>> document2.addPage(pdfPage);
>> document2.save("c:\\generatedPDF.pdf");
>> document2.close();
>>
>>
>> But if I take the PDPage content and create a new PDPage, it doesn't work.
>>
>> InputStream fileStream =
>> this.getClass().getResourceAsStream("sample.pdf");
>> PDDocument document = PDDocument.load(fileStream);
>> PDPage pdfPage = (PDPage)
>> document.getDocumentCatalog().getAllPages().get(0);
>>
>> PDDocument document2 = new PDDocument();
>> PDPage testPDPage = new PDPage();
>>
>> testPDPage.setContents(pdfPage.getContents());
>>
>> document2.addPage(testPDPage);
>> document2.save("c:\\generatedPDF.pdf");
>> document2.close();
>>
>>
>> At the end of the day, what I'm trying to do is extract all the pages
>> from the document, store it in a database, retrieve each page sometime
>> in the future and create a document with that one page. So, at some
>> point I figure I'll be converting the contents inty a bytearray and
>> store that, and recreate it.
>>
>> Any help would be appreciated. Thanks for your time.
>>
>> Foley
>>

Mime
View raw message