You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2018/11/04 10:13:00 UTC

[jira] [Closed] (PDFBOX-4334) Copying single page from pdf to new document results in invalid pdf

     [ https://issues.apache.org/jira/browse/PDFBOX-4334?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tilman Hausherr closed PDFBOX-4334.
-----------------------------------
    Resolution: Duplicate

Closing as duplicate of PDFBOX-3428. I'll add you as a watcher there.

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