You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by sa...@me.com on 2011/06/09 15:46:46 UTC

Can view document, but getPrintable fails due to unknown compression of zip stream

Hello,

I am using PDFBox to print  PDF's.  I have come across a  PDF which I can not print.  FlateFilter is thrown a ZipException due to an unknown compression method.  Yet, I know PDFBox can handle the file, because PDFReader, and PrintPDF utilities work fine. (aside: Speaking of which, could the error message printed when this happens be more specific than "Stop reading corrupt stream". )

So I am not sure if the bug is in my code or PDFBox's; this is the code I am using to print, which works with most PDF's.

public class MyPdfDoc implements Printable
{

	private PDDocument pdfDoc;

	public MyPdfDoc( String path )
	{
		try
		{
			pdfDoc = PDDocument.load(path);
		}
		catch( IOException e )
		{
			log.severe("failed to load " + path + ": " + e);
			pdfDoc = null;
		}
	}

	@Override
	public int print( Graphics graphics, PageFormat pageFormat, int pageIndex ) throws PrinterException
	{
		if( pdfDoc == null || pageIndex >= pdfDoc.getNumberOfPages() )
		{
			return NO_SUCH_PAGE;
		}

		Printable printable = pdfDoc.getPrintable(pageIndex);
		return printable.print(graphics, pageFormat, pageIndex);
	}
}

Any help appreciated, thanks.
~S

Re: Can view document, but getPrintable fails due to unknown compression of zip stream

Posted by Shea Martin <sh...@me.com>.
I should also note that I am printing the MyPdfDoc using printJob.setPrintable().  The PrintPDF utility which is part of PDF box, uses printJob.setPageable(). Should this matter?

On 2011-06-09, at 7:46 AM, samfree@me.com wrote:

> 
> Hello,
> 
> I am using PDFBox to print  PDF's.  I have come across a  PDF which I can not print.  FlateFilter is thrown a ZipException due to an unknown compression method.  Yet, I know PDFBox can handle the file, because PDFReader, and PrintPDF utilities work fine. (aside: Speaking of which, could the error message printed when this happens be more specific than "Stop reading corrupt stream". )
> 
> So I am not sure if the bug is in my code or PDFBox's; this is the code I am using to print, which works with most PDF's.
> 
> public class MyPdfDoc implements Printable
> {
> 
> 	private PDDocument pdfDoc;
> 
> 	public MyPdfDoc( String path )
> 	{
> 		try
> 		{
> 			pdfDoc = PDDocument.load(path);
> 		}
> 		catch( IOException e )
> 		{
> 			log.severe("failed to load " + path + ": " + e);
> 			pdfDoc = null;
> 		}
> 	}
> 
> 	@Override
> 	public int print( Graphics graphics, PageFormat pageFormat, int pageIndex ) throws PrinterException
> 	{
> 		if( pdfDoc == null || pageIndex >= pdfDoc.getNumberOfPages() )
> 		{
> 			return NO_SUCH_PAGE;
> 		}
> 
> 		Printable printable = pdfDoc.getPrintable(pageIndex);
> 		return printable.print(graphics, pageFormat, pageIndex);
> 	}
> }
> 
> Any help appreciated, thanks.
> ~S

----------------
Shea Martin
<contact info>




Re: Can view document, but getPrintable fails due to unknown compression of zip stream

Posted by Shea Martin <sh...@me.com>.
Solution:
pdf.decrypt("");

I guess this is somehting I have to check from now on. Perhaps a better erorr message would help people with this in the future.

CHeers,
~S
On 2011-06-09, at 10:29 AM, Shea Martin wrote:

> I have removed my code from suspicion, the following fails with pdfbox, jempbox, and fontbox in my classpath.  But if I put run pdfbox-app, as a PrintPDF, or PDFReader it works on the same pdf.  The app jar must include something extra?
> 
> The following produces the same corrupt stream error.
> static void main(String[] args)
> {
> 		PDDocument pdf  = PDDocument.load("testdata/cash_for_keys.pdf");
> 		pdf.silentPrint();
> }
> On 2011-06-09, at 7:46 AM, samfree@me.com wrote:
> 
>> 
>> Hello,
>> 
>> I am using PDFBox to print  PDF's.  I have come across a  PDF which I can not print.  FlateFilter is thrown a ZipException due to an unknown compression method.  Yet, I know PDFBox can handle the file, because PDFReader, and PrintPDF utilities work fine. (aside: Speaking of which, could the error message printed when this happens be more specific than "Stop reading corrupt stream". )
>> 
>> So I am not sure if the bug is in my code or PDFBox's; this is the code I am using to print, which works with most PDF's.
>> 
>> public class MyPdfDoc implements Printable
>> {
>> 
>> 	private PDDocument pdfDoc;
>> 
>> 	public MyPdfDoc( String path )
>> 	{
>> 		try
>> 		{
>> 			pdfDoc = PDDocument.load(path);
>> 		}
>> 		catch( IOException e )
>> 		{
>> 			log.severe("failed to load " + path + ": " + e);
>> 			pdfDoc = null;
>> 		}
>> 	}
>> 
>> 	@Override
>> 	public int print( Graphics graphics, PageFormat pageFormat, int pageIndex ) throws PrinterException
>> 	{
>> 		if( pdfDoc == null || pageIndex >= pdfDoc.getNumberOfPages() )
>> 		{
>> 			return NO_SUCH_PAGE;
>> 		}
>> 
>> 		Printable printable = pdfDoc.getPrintable(pageIndex);
>> 		return printable.print(graphics, pageFormat, pageIndex);
>> 	}
>> }
>> 
>> Any help appreciated, thanks.
>> ~S
> 
> ----------------
> Shea Martin
> <contact info>
> 
> 
> 

----------------
Shea Martin
<contact info>




Re: Can view document, but getPrintable fails due to unknown compression of zip stream

Posted by Shea Martin <sh...@me.com>.
I have removed my code from suspicion, the following fails with pdfbox, jempbox, and fontbox in my classpath.  But if I put run pdfbox-app, as a PrintPDF, or PDFReader it works on the same pdf.  The app jar must include something extra?

The following produces the same corrupt stream error.
static void main(String[] args)
{
		PDDocument pdf  = PDDocument.load("testdata/cash_for_keys.pdf");
		pdf.silentPrint();
}
On 2011-06-09, at 7:46 AM, samfree@me.com wrote:

> 
> Hello,
> 
> I am using PDFBox to print  PDF's.  I have come across a  PDF which I can not print.  FlateFilter is thrown a ZipException due to an unknown compression method.  Yet, I know PDFBox can handle the file, because PDFReader, and PrintPDF utilities work fine. (aside: Speaking of which, could the error message printed when this happens be more specific than "Stop reading corrupt stream". )
> 
> So I am not sure if the bug is in my code or PDFBox's; this is the code I am using to print, which works with most PDF's.
> 
> public class MyPdfDoc implements Printable
> {
> 
> 	private PDDocument pdfDoc;
> 
> 	public MyPdfDoc( String path )
> 	{
> 		try
> 		{
> 			pdfDoc = PDDocument.load(path);
> 		}
> 		catch( IOException e )
> 		{
> 			log.severe("failed to load " + path + ": " + e);
> 			pdfDoc = null;
> 		}
> 	}
> 
> 	@Override
> 	public int print( Graphics graphics, PageFormat pageFormat, int pageIndex ) throws PrinterException
> 	{
> 		if( pdfDoc == null || pageIndex >= pdfDoc.getNumberOfPages() )
> 		{
> 			return NO_SUCH_PAGE;
> 		}
> 
> 		Printable printable = pdfDoc.getPrintable(pageIndex);
> 		return printable.print(graphics, pageFormat, pageIndex);
> 	}
> }
> 
> Any help appreciated, thanks.
> ~S

----------------
Shea Martin
<contact info>