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

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

Here's what should come - check your logging:
{quote}
15.10.2018 20:22:48.615 WARN  [main] org.apache.pdfbox.pdmodel.PDDocument:679 - 
inherited resources of source document are not imported to destination page
15.10.2018 20:22:48.618 WARN  [main] org.apache.pdfbox.pdmodel.PDDocument:680 - 
call importedPage.setResources(page.getResources()) to do this
{quote}
So the workaround would be somewhat like this:
{code}
PDPage page = pdfDocument.getDocumentCatalog().getPages().get(0);
PDPage newPage = newDocument.importPage(page);
if (newPage.getResources() == null)
     newPage.setResources(page.getResources());
{code}
Of course this should be fixed… I need to read PDFBOX-3428 and related again.


> 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