[
https://issues.apache.org/jira/browse/PDFBOX-362?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tilman Hausherr updated PDFBOX-362:
-----------------------------------
Attachment: real-empty-page.pdf
> ZipException occuring upon importing a page
> -------------------------------------------
>
> Key: PDFBOX-362
> URL: https://issues.apache.org/jira/browse/PDFBOX-362
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Reporter: Jukka Zitting
> Attachments: real-empty-page.pdf
>
>
> [Issue from SourceForge]
> http://sourceforge.net/tracker/index.php?func=detail&aid=2019925&group_id=78314&atid=552832
> copying page from source document to other doc, if the source page has no
> content, a ZipException occurs.
> the following sample code exhibits the problem with such source pdf:
> {code}
> public class LoadSaveSample
> {
> /**
> * @param args holds the name of a file to copy
> * @throws IOException
> * @throws COSVisitorException
> */
> public static void main(String[] args) throws IOException,
> COSVisitorException
> {
> String name = args[0];
> File file = new File(name);
> System.out.println("loading file " + file.getPath());
> PDDocument doc = PDDocument.load(file);
> ClassLoader loader = doc.getClass().getClassLoader();
> System.out.println("loader: " + loader);
> try
> {
> PDDocument doc2 = new PDDocument();
> List all = doc.getDocumentCatalog().getAllPages();
> Iterator it = all.iterator();
> while (true == it.hasNext())
> {
> PDPage page = (PDPage) it.next();
> // now do the copy through import...
> PDPage imported = doc2.importPage(page);
> imported.setCropBox(page.findCropBox());
> imported.setMediaBox(page.findMediaBox());
> imported.setResources(page.findResources());
> imported.setRotation(page.findRotation());
> }
> String outName = file.getPath() + ".saved.pdf";
> doc2.save(outName);
> System.out.println("saved as " + outName);
> }
> finally
> {
> doc.close();
> }
> }
> }
> {code}
> (Edited on 8.6.14 by [~tilman] for clarity)
--
This message was sent by Atlassian JIRA
(v6.2#6252)