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 2014/06/08 22:09:01 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 ]
Tilman Hausherr updated PDFBOX-362:
-----------------------------------
Description:
[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)
was:
[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
content, a ZipException occurs.
the following sample code exhibits the problem with such source pdf:
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 ();
}
}
}
http://sourceforge.net/tracker/download.php?group_id=78314&atid=552832&file_id=284963&aid=2019925
[Comment on SourceForge]
Date: 2008-07-16 20:07
Sender: nobody
Logged In: NO
apologies: it should read:
copying page from source document to other doc, if the source page has NO
content, a ZipException occurs.
> 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
>
> [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)