[
https://issues.apache.org/jira/browse/PDFBOX-889?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Adam Nichols resolved PDFBOX-889.
---------------------------------
Resolution: Fixed
Fix Version/s: 1.4.0
Assignee: Adam Nichols
Committed in revision 1038232. For future reference, it's best to attach
patches as files; when they're rendered in HTML it butchers the whitespace
which prevents me from applying the patch. That'll just help save me some time
since I can just apply the patch instead of reading it and making the changes
by hand.
> Empty page causes NPE in importPage
> -----------------------------------
>
> Key: PDFBOX-889
> URL: https://issues.apache.org/jira/browse/PDFBOX-889
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Affects Versions: 1.3.1
> Reporter: Kevin Jackson
> Assignee: Adam Nichols
> Fix For: 1.4.0
>
>
> An empty page does not need to have a Contents item.
> PDDocument.importPage() fails with a NullPointerException when such an empty
> page is imported.
> ### Eclipse Workspace Patch 1.0
> #P pdfbox
> Index: pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
> ===================================================================
> --- pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
> (revision 1026306)
> +++ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
> (working copy)
> @@ -322,16 +322,19 @@
> try
> {
> PDStream src = page.getContents();
> - PDStream dest = new PDStream( new COSStream( src.getStream(),
> document.getScratchFile() ) );
> - importedPage.setContents( dest );
> - os = dest.createOutputStream();
> + if (src != null)
> + {
> + PDStream dest = new PDStream( new COSStream(
> src.getStream(), document.getScratchFile() ) );
> + importedPage.setContents( dest );
> + os = dest.createOutputStream();
>
> - byte[] buf = new byte[10240];
> - int amountRead = 0;
> - is = src.createInputStream();
> - while((amountRead = is.read(buf,0,10240)) > -1)
> - {
> - os.write(buf, 0, amountRead);
> + byte[] buf = new byte[10240];
> + int amountRead = 0;
> + is = src.createInputStream();
> + while((amountRead = is.read(buf,0,10240)) > -1)
> + {
> + os.write(buf, 0, amountRead);
> + }
> }
> addPage( importedPage );
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.