You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Kevin Brown <kb...@gmail.com> on 2010/12/10 18:05:45 UTC

Size does matter (when it comes to PDF files)

It seems like just saving a simple PDF (which was generated by Adobe Acrobat
9 Web Capture) with PDFBox PDDocument.save method will balloon the file
size. We can fix it by opening the file in Adobe Acrobat 9 and then saving
it.  Is there any way to control this in PDFBox?

Is there a way to set the PDF version programagically? We were thinking
perhaps this might help.

Thanks,

Kevin

Re: Size does matter (when it comes to PDF files)

Posted by Kevin Brown <kb...@gmail.com>.
Whoa! I'll see if I can get at the current trunk. Thanks.

But, FYI, at least in 1.3.1, the setVersion() method of CosDocument does not
work, so you might want to get rid of that (or make it work).

Have a nice weekend, and thanks again.

Kevin

On Fri, Dec 10, 2010 at 5:40 PM, Andreas Lehmkuehler <an...@lehmi.de>wrote:

> Hi,
>
>
> Am 10.12.2010 23:05, schrieb Kevin Brown:
>
>  No, there really isn't a method by that name in PDFBox 1.3.1
>>
> I'm sorry, my fault. You're of course right. setVersion() was introduced
> just after releasing 1.3.1 [1] So, you have to use the current trunk or have
> to wait until the next release.
>
>
> BR
> Andreas Lehmkühler
>
> [1]
> http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentCatalog.java?view=log
>
>
>  Thanks for responding, though. :)
>>
>> On Fri, Dec 10, 2010 at 4:59 PM, Andreas Lehmkuehler<andreas@lehmi.de
>> >wrote:
>>
>>  Hi,
>>>
>>>
>>> Am 10.12.2010 20:11, schrieb Kevin Brown:
>>>
>>>  Thanks, Andreas.
>>>
>>>>
>>>> I was using the load method originally to get the PDDocument. I was just
>>>> trying other things to see if anything suck to the wall.
>>>>
>>>> There is no PDDocument.getDocumentCatelog.setVersion() method. There is
>>>> a
>>>> PDDocument.getDocument().setVersion(1.7) method. I can't get that to
>>>> work.
>>>> Have you done this kind of thing before?
>>>>
>>>>
>>> I'm pretty sure there is such method. Try this:
>>>
>>>
>>> PDDocument document = PDDocument.load("test.pdf");
>>> document.getDocumentCatalog().setVersion("1.5");
>>>
>>>
>>> BR
>>> Andreas Lehmkühler
>>>
>>>
>>>
>>>
>>>>
>>>> On Fri, Dec 10, 2010 at 2:07 PM, Andreas Lehmkuehler<andreas@lehmi.de
>>>>
>>>>> wrote:
>>>>>
>>>>
>>>>  Hi,
>>>>
>>>>>
>>>>>
>>>>> Am 10.12.2010 19:48, schrieb Kevin Brown:
>>>>>
>>>>>  I just tried the reverse -- creating the CosDocument before creating
>>>>> the
>>>>>
>>>>>  PDDocument, and still no dice. The version stays the same. Perhaps
>>>>>> this
>>>>>> is
>>>>>> a
>>>>>> bug?
>>>>>>
>>>>>>             File file = new File(args[1]);
>>>>>>             PDFParser parser = new PDFParser(new
>>>>>> FileInputStream(file));
>>>>>>             parser.parse();
>>>>>>             cos = parser.getDocument();
>>>>>>             cos.setVersion((float) 1.8);
>>>>>>             PDDocument document = new PDDocument(cos);
>>>>>>             document.save(args[1]+"b");
>>>>>>             document.close();
>>>>>>
>>>>>>
>>>>>>  First of all you should use something like the following to load a
>>>>> pdf
>>>>>
>>>>>        PDDocument document = PDDocument.load("test.pdf");
>>>>>
>>>>> To get/set the version you should use something like this
>>>>>
>>>>>        document.getDocumentCatalog.getVersion();
>>>>>        document.getDocumentCatalog.setVersion("1.5");
>>>>>
>>>>> I didn't try the second recently but it should work.
>>>>>
>>>>>
>>>>> BR
>>>>> Andreas Lehmkühler
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>

Re: Size does matter (when it comes to PDF files)

Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,


Am 10.12.2010 23:05, schrieb Kevin Brown:
> No, there really isn't a method by that name in PDFBox 1.3.1
I'm sorry, my fault. You're of course right. setVersion() was introduced just 
after releasing 1.3.1 [1] So, you have to use the current trunk or have to wait 
until the next release.


BR
Andreas Lehmkühler

[1] 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentCatalog.java?view=log

> Thanks for responding, though. :)
>
> On Fri, Dec 10, 2010 at 4:59 PM, Andreas Lehmkuehler<an...@lehmi.de>wrote:
>
>> Hi,
>>
>>
>> Am 10.12.2010 20:11, schrieb Kevin Brown:
>>
>>   Thanks, Andreas.
>>>
>>> I was using the load method originally to get the PDDocument. I was just
>>> trying other things to see if anything suck to the wall.
>>>
>>> There is no PDDocument.getDocumentCatelog.setVersion() method. There is a
>>> PDDocument.getDocument().setVersion(1.7) method. I can't get that to work.
>>> Have you done this kind of thing before?
>>>
>>
>> I'm pretty sure there is such method. Try this:
>>
>>
>> PDDocument document = PDDocument.load("test.pdf");
>> document.getDocumentCatalog().setVersion("1.5");
>>
>>
>> BR
>> Andreas Lehmkühler
>>
>>
>>
>>>
>>>
>>> On Fri, Dec 10, 2010 at 2:07 PM, Andreas Lehmkuehler<andreas@lehmi.de
>>>> wrote:
>>>
>>>   Hi,
>>>>
>>>>
>>>> Am 10.12.2010 19:48, schrieb Kevin Brown:
>>>>
>>>>   I just tried the reverse -- creating the CosDocument before creating the
>>>>
>>>>> PDDocument, and still no dice. The version stays the same. Perhaps this
>>>>> is
>>>>> a
>>>>> bug?
>>>>>
>>>>>              File file = new File(args[1]);
>>>>>              PDFParser parser = new PDFParser(new FileInputStream(file));
>>>>>              parser.parse();
>>>>>              cos = parser.getDocument();
>>>>>              cos.setVersion((float) 1.8);
>>>>>              PDDocument document = new PDDocument(cos);
>>>>>              document.save(args[1]+"b");
>>>>>              document.close();
>>>>>
>>>>>
>>>> First of all you should use something like the following to load a pdf
>>>>
>>>>         PDDocument document = PDDocument.load("test.pdf");
>>>>
>>>> To get/set the version you should use something like this
>>>>
>>>>         document.getDocumentCatalog.getVersion();
>>>>         document.getDocumentCatalog.setVersion("1.5");
>>>>
>>>> I didn't try the second recently but it should work.
>>>>
>>>>
>>>> BR
>>>> Andreas Lehmkühler
>>>>
>>>>
>>>
>>
>


Re: Size does matter (when it comes to PDF files)

Posted by Kevin Brown <kb...@gmail.com>.
No, there really isn't a method by that name in PDFBox 1.3.1

Thanks for responding, though. :)

On Fri, Dec 10, 2010 at 4:59 PM, Andreas Lehmkuehler <an...@lehmi.de>wrote:

> Hi,
>
>
> Am 10.12.2010 20:11, schrieb Kevin Brown:
>
>  Thanks, Andreas.
>>
>> I was using the load method originally to get the PDDocument. I was just
>> trying other things to see if anything suck to the wall.
>>
>> There is no PDDocument.getDocumentCatelog.setVersion() method. There is a
>> PDDocument.getDocument().setVersion(1.7) method. I can't get that to work.
>> Have you done this kind of thing before?
>>
>
> I'm pretty sure there is such method. Try this:
>
>
> PDDocument document = PDDocument.load("test.pdf");
> document.getDocumentCatalog().setVersion("1.5");
>
>
> BR
> Andreas Lehmkühler
>
>
>
>>
>>
>> On Fri, Dec 10, 2010 at 2:07 PM, Andreas Lehmkuehler<andreas@lehmi.de
>> >wrote:
>>
>>  Hi,
>>>
>>>
>>> Am 10.12.2010 19:48, schrieb Kevin Brown:
>>>
>>>  I just tried the reverse -- creating the CosDocument before creating the
>>>
>>>> PDDocument, and still no dice. The version stays the same. Perhaps this
>>>> is
>>>> a
>>>> bug?
>>>>
>>>>             File file = new File(args[1]);
>>>>             PDFParser parser = new PDFParser(new FileInputStream(file));
>>>>             parser.parse();
>>>>             cos = parser.getDocument();
>>>>             cos.setVersion((float) 1.8);
>>>>             PDDocument document = new PDDocument(cos);
>>>>             document.save(args[1]+"b");
>>>>             document.close();
>>>>
>>>>
>>> First of all you should use something like the following to load a pdf
>>>
>>>        PDDocument document = PDDocument.load("test.pdf");
>>>
>>> To get/set the version you should use something like this
>>>
>>>        document.getDocumentCatalog.getVersion();
>>>        document.getDocumentCatalog.setVersion("1.5");
>>>
>>> I didn't try the second recently but it should work.
>>>
>>>
>>> BR
>>> Andreas Lehmkühler
>>>
>>>
>>
>

Re: Size does matter (when it comes to PDF files)

Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,


Am 10.12.2010 20:11, schrieb Kevin Brown:
> Thanks, Andreas.
>
> I was using the load method originally to get the PDDocument. I was just
> trying other things to see if anything suck to the wall.
>
> There is no PDDocument.getDocumentCatelog.setVersion() method. There is a
> PDDocument.getDocument().setVersion(1.7) method. I can't get that to work.
> Have you done this kind of thing before?

I'm pretty sure there is such method. Try this:

PDDocument document = PDDocument.load("test.pdf");
document.getDocumentCatalog().setVersion("1.5");


BR
Andreas Lehmkühler

>
>
>
> On Fri, Dec 10, 2010 at 2:07 PM, Andreas Lehmkuehler<an...@lehmi.de>wrote:
>
>> Hi,
>>
>>
>> Am 10.12.2010 19:48, schrieb Kevin Brown:
>>
>>   I just tried the reverse -- creating the CosDocument before creating the
>>> PDDocument, and still no dice. The version stays the same. Perhaps this is
>>> a
>>> bug?
>>>
>>>              File file = new File(args[1]);
>>>              PDFParser parser = new PDFParser(new FileInputStream(file));
>>>              parser.parse();
>>>              cos = parser.getDocument();
>>>              cos.setVersion((float) 1.8);
>>>              PDDocument document = new PDDocument(cos);
>>>              document.save(args[1]+"b");
>>>              document.close();
>>>
>>
>> First of all you should use something like the following to load a pdf
>>
>>         PDDocument document = PDDocument.load("test.pdf");
>>
>> To get/set the version you should use something like this
>>
>>         document.getDocumentCatalog.getVersion();
>>         document.getDocumentCatalog.setVersion("1.5");
>>
>> I didn't try the second recently but it should work.
>>
>>
>> BR
>> Andreas Lehmkühler
>>
>


Re: Size does matter (when it comes to PDF files)

Posted by Kevin Brown <kb...@gmail.com>.
Thanks, Andreas.

I was using the load method originally to get the PDDocument. I was just
trying other things to see if anything suck to the wall.

There is no PDDocument.getDocumentCatelog.setVersion() method. There is a
PDDocument.getDocument().setVersion(1.7) method. I can't get that to work.
Have you done this kind of thing before?



On Fri, Dec 10, 2010 at 2:07 PM, Andreas Lehmkuehler <an...@lehmi.de>wrote:

> Hi,
>
>
> Am 10.12.2010 19:48, schrieb Kevin Brown:
>
>  I just tried the reverse -- creating the CosDocument before creating the
>> PDDocument, and still no dice. The version stays the same. Perhaps this is
>> a
>> bug?
>>
>>             File file = new File(args[1]);
>>             PDFParser parser = new PDFParser(new FileInputStream(file));
>>             parser.parse();
>>             cos = parser.getDocument();
>>             cos.setVersion((float) 1.8);
>>             PDDocument document = new PDDocument(cos);
>>             document.save(args[1]+"b");
>>             document.close();
>>
>
> First of all you should use something like the following to load a pdf
>
>        PDDocument document = PDDocument.load("test.pdf");
>
> To get/set the version you should use something like this
>
>        document.getDocumentCatalog.getVersion();
>        document.getDocumentCatalog.setVersion("1.5");
>
> I didn't try the second recently but it should work.
>
>
> BR
> Andreas Lehmkühler
>

Re: Size does matter (when it comes to PDF files)

Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,


Am 10.12.2010 19:48, schrieb Kevin Brown:
> I just tried the reverse -- creating the CosDocument before creating the
> PDDocument, and still no dice. The version stays the same. Perhaps this is a
> bug?
>
>              File file = new File(args[1]);
>              PDFParser parser = new PDFParser(new FileInputStream(file));
>              parser.parse();
>              cos = parser.getDocument();
>              cos.setVersion((float) 1.8);
>              PDDocument document = new PDDocument(cos);
>              document.save(args[1]+"b");
>              document.close();

First of all you should use something like the following to load a pdf

	PDDocument document = PDDocument.load("test.pdf");

To get/set the version you should use something like this

	document.getDocumentCatalog.getVersion();
	document.getDocumentCatalog.setVersion("1.5");

I didn't try the second recently but it should work.


BR
Andreas Lehmkühler

Re: Size does matter (when it comes to PDF files)

Posted by Kevin Brown <kb...@gmail.com>.
I just tried the reverse -- creating the CosDocument before creating the
PDDocument, and still no dice. The version stays the same. Perhaps this is a
bug?

            File file = new File(args[1]);
            PDFParser parser = new PDFParser(new FileInputStream(file));
            parser.parse();
            cos = parser.getDocument();
            cos.setVersion((float) 1.8);
            PDDocument document = new PDDocument(cos);
            document.save(args[1]+"b");
            document.close();

On Fri, Dec 10, 2010 at 1:08 PM, Kevin Brown <kb...@gmail.com> wrote:

> I don't seem to be able to get CosDocument.setVersion() to work. Where
> Document is a PDDocument, I get the COSDocument.... anyone had any luck with
> this? Am I doing something wrong? If I call getVersion() before changing it,
> I get the old version, and if I call getVersion() after I changed the
> version I get the new version. But when I save and open the file in Reader,
> it's the old version I see.
>
>   COSDocument cos = document.getDocument();
>            System.out.println("got cos " + cos.getVersion());
>                cos.setVersion((float) 1.8);
>
>
>
>             document.save(args[1]);
>
>               cos.close();
>
>
>
>              document.close();
>
>
> On Fri, Dec 10, 2010 at 12:11 PM, Kevin Brown <kb...@gmail.com> wrote:
>
>> Ah, sorry, I see you can set the version with the method:
>>
>> COSDocument.setVersion()
>>
>> I'll see if that helps!
>>
>>
>>
>>
>> On Fri, Dec 10, 2010 at 12:05 PM, Kevin Brown <kb...@gmail.com> wrote:
>>
>>> It seems like just saving a simple PDF (which was generated by Adobe
>>> Acrobat 9 Web Capture) with PDFBox PDDocument.save method will balloon the
>>> file size. We can fix it by opening the file in Adobe Acrobat 9 and then
>>> saving it.  Is there any way to control this in PDFBox?
>>>
>>> Is there a way to set the PDF version programagically? We were thinking
>>> perhaps this might help.
>>>
>>> Thanks,
>>>
>>> Kevin
>>>
>>>
>>
>>
>

Re: Size does matter (when it comes to PDF files)

Posted by Kevin Brown <kb...@gmail.com>.
I don't seem to be able to get CosDocument.setVersion() to work. Where
Document is a PDDocument, I get the COSDocument.... anyone had any luck with
this? Am I doing something wrong? If I call getVersion() before changing it,
I get the old version, and if I call getVersion() after I changed the
version I get the new version. But when I save and open the file in Reader,
it's the old version I see.

  COSDocument cos = document.getDocument();
           System.out.println("got cos " + cos.getVersion());
               cos.setVersion((float) 1.8);



            document.save(args[1]);

              cos.close();



             document.close();


On Fri, Dec 10, 2010 at 12:11 PM, Kevin Brown <kb...@gmail.com> wrote:

> Ah, sorry, I see you can set the version with the method:
>
> COSDocument.setVersion()
>
> I'll see if that helps!
>
>
>
>
> On Fri, Dec 10, 2010 at 12:05 PM, Kevin Brown <kb...@gmail.com> wrote:
>
>> It seems like just saving a simple PDF (which was generated by Adobe
>> Acrobat 9 Web Capture) with PDFBox PDDocument.save method will balloon the
>> file size. We can fix it by opening the file in Adobe Acrobat 9 and then
>> saving it.  Is there any way to control this in PDFBox?
>>
>> Is there a way to set the PDF version programagically? We were thinking
>> perhaps this might help.
>>
>> Thanks,
>>
>> Kevin
>>
>>
>
>

Re: Size does matter (when it comes to PDF files)

Posted by Kevin Brown <kb...@gmail.com>.
Ah, sorry, I see you can set the version with the method:

COSDocument.setVersion()

I'll see if that helps!



On Fri, Dec 10, 2010 at 12:05 PM, Kevin Brown <kb...@gmail.com> wrote:

> It seems like just saving a simple PDF (which was generated by Adobe
> Acrobat 9 Web Capture) with PDFBox PDDocument.save method will balloon the
> file size. We can fix it by opening the file in Adobe Acrobat 9 and then
> saving it.  Is there any way to control this in PDFBox?
>
> Is there a way to set the PDF version programagically? We were thinking
> perhaps this might help.
>
> Thanks,
>
> Kevin
>
>