You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Attila Kiss <ki...@gmail.com> on 2017/05/01 17:52:23 UTC

PDDocument.load()- File vs. InputStream

Hello everybody,
I have a problem and I could not find any solution.

I have a pdf file and when I load the file with PDDocument.load(new
File("absolute/path/to/pdf/file");
it loads perfectly, I can add some text and then save it. Then I open the
file and the original content shows up and my added content shows up as
well.
But when I try to use
PDDocument.load(getClass().getResourceAsStream("/path/in/resources/dir"));
It throws the following error: FlateFilter: stop reading corrupt stream due
to a DataFormatException. And then I open the pdf file, and only the added
content shows up.
But I should use the getResourceAsStream() method, as I could not tell the
absolute file path now, the user will install the app whatever he/she wants.
Any idea, how and why is this happening? Or any solution?
Thanks,
Attila

Re: PDDocument.load()- File vs. InputStream

Posted by Attila Kiss <ki...@gmail.com>.
I am using version 2.0.5 but never mind, it was a maven resource plugin
problem with the binary resources. I added the nonFilteredFileExtension tag
with pdf and it works fine now.
Thank you.
Attila

2017-05-01 19:58 GMT+02:00 Tilman Hausherr <TH...@t-online.de>:

> What version are you using? Hopefully 2.0.5.
>
> Does your code with "getResourceAsStream" also have the file name (with
> .pdf) in it?
>
> If it happens with 2.0.5, then please upload the file somewhere.
>
> Although IMO your code will perform faster if you keep using files, like
> this:
>
> PDDocument.load(new File(getClass().getResource("p
> ath/test.pdf").toURI()));
>
> Tilman
>
>
> Am 01.05.2017 um 19:52 schrieb Attila Kiss:
>
>> Hello everybody,
>> I have a problem and I could not find any solution.
>>
>> I have a pdf file and when I load the file with PDDocument.load(new
>> File("absolute/path/to/pdf/file");
>> it loads perfectly, I can add some text and then save it. Then I open the
>> file and the original content shows up and my added content shows up as
>> well.
>> But when I try to use
>> PDDocument.load(getClass().getResourceAsStream("/path/in/res
>> ources/dir"));
>> It throws the following error: FlateFilter: stop reading corrupt stream
>> due
>> to a DataFormatException. And then I open the pdf file, and only the added
>> content shows up.
>> But I should use the getResourceAsStream() method, as I could not tell the
>> absolute file path now, the user will install the app whatever he/she
>> wants.
>> Any idea, how and why is this happening? Or any solution?
>> Thanks,
>> Attila
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>

Re: PDDocument.load()- File vs. InputStream

Posted by Tilman Hausherr <TH...@t-online.de>.
What version are you using? Hopefully 2.0.5.

Does your code with "getResourceAsStream" also have the file name (with 
.pdf) in it?

If it happens with 2.0.5, then please upload the file somewhere.

Although IMO your code will perform faster if you keep using files, like 
this:

PDDocument.load(new File(getClass().getResource("path/test.pdf").toURI()));

Tilman

Am 01.05.2017 um 19:52 schrieb Attila Kiss:
> Hello everybody,
> I have a problem and I could not find any solution.
>
> I have a pdf file and when I load the file with PDDocument.load(new
> File("absolute/path/to/pdf/file");
> it loads perfectly, I can add some text and then save it. Then I open the
> file and the original content shows up and my added content shows up as
> well.
> But when I try to use
> PDDocument.load(getClass().getResourceAsStream("/path/in/resources/dir"));
> It throws the following error: FlateFilter: stop reading corrupt stream due
> to a DataFormatException. And then I open the pdf file, and only the added
> content shows up.
> But I should use the getResourceAsStream() method, as I could not tell the
> absolute file path now, the user will install the app whatever he/she wants.
> Any idea, how and why is this happening? Or any solution?
> Thanks,
> Attila
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org