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

Tilman Hausherr edited comment on PDFBOX-4334 at 10/8/18 7:19 PM:
------------------------------------------------------------------

Did you get a log message when using importPage? I haven't tested myself yet 
but I suspect that the problem is that the resources are not in the page 
resource dictionary, but higher up..


was (Author: tilman):
Did you get a log message when using importPage?

> 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: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to