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

Tilman Hausherr commented on PDFBOX-4334:
-----------------------------------------

I don't know; I've now read the other issue again, the problem is that 
sometimes, the parent resource has ALL the resources of every page. Code to 
analyze the page content stream to find out what is really used would need some 
time to be written. (And I think that in some cases (type 3 fonts?) objects 
deep down want access to the page resources, if true then it is even more 
tricky)

My current thought is to make it configurable through an boolean extra 
parameter or through an extra method.

> Copying single page from pdf to new document results in invalid pdf
> -------------------------------------------------------------------
>
>                 Key: PDFBOX-4334
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4334
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.12
>            Reporter: Bjorn Misseghers
>            Priority: Minor
>         Attachments: 67.pdf, 67converted.pdf
>
>
> When trying to copy the first page of attached pdf document (67.pdf) into a 
> new pdf document, no errors are thrown. However, the resulting pdf document 
> is invalid.
> The code snippet used for extracting the page (tried using both the addPage 
> and importPage method) :
>  
> {code:java}
>     public static void getFirstPageOfPdfAsPdf(InputStream sourcePDF, 
> OutputStream outputPDF) throws OneaException {
>       try {
>          PDDocument pdfDocument = PDDocument.load(sourcePDF);
>          PDDocument newDocument = new PDDocument();
>          try {
>             
> newDocument.addPage(pdfDocument.getDocumentCatalog().getPages().get(0));
> //          newDocument.importPage(pdfDocument.getPage(0));
>             newDocument.save(outputPDF);
>          } finally {
>             StreamTools.closeStream(newDocument);
>             StreamTools.closeStream(pdfDocument);
>          }
>       } catch (Exception ex) {
>          throw new Exception("Cannot extract first page from PDF: " + 
> ex.getMessage());
>       }
>    }
> {code}
>  
> The converted file is also attached (67converted.pdf)
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to