You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "John Hewson (JIRA)" <ji...@apache.org> on 2014/10/10 23:34:34 UTC

[jira] [Updated] (PDFBOX-362) ZipException occuring upon importing a page

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

John Hewson updated PDFBOX-362:
-------------------------------
    Fix Version/s: 2.0.0

> 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
>    Affects Versions: 1.8.7, 2.0.0
>            Reporter: Jukka Zitting
>             Fix For: 2.0.0
>
>         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.3.4#6332)