[
https://issues.apache.org/jira/browse/PDFBOX-4334?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Bjorn Misseghers updated PDFBOX-4334:
-------------------------------------
Description:
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}
was:
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 :
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 OneaException("Cannot extract first page from PDF: " +
ex.getMessage());
}
}
> 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
>
>
> 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}
>
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]