pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Limit PDF size
Date Tue, 01 Aug 2017 19:22:27 GMT
The only thing that comes close to what you want is to create your 
PDDocument with MemoryUsageSetting.setupMixed(...) as parameter.

What you should do is to care to not have anything duplicate. So if you 
have a company logo on every page, create your object object only once. 
Same for fonts. And try to have only one content stream per page. (We 
recently had a guy who had a huge number of content streams and wondered 
why his PDF was so big).


Am 01.08.2017 um 20:04 schrieb Christopher Schultz:
> Hash: SHA256
> All,
> We use PDFBox on a server that must handle many transactions with
> (somewhat) limited memory. I'd like to limit the amount of memory used
> to generate our PDFs, which we then serialize to byte-array,
> base64-encode, etc. for ultimate delivery to some endpoint.
> I can obviously limit the number of bytes produced by using a
> size-limited OutputStream passed-into PDDocument.save(OutputStream),
> but I'm wondering if PDFBox has any facilities within it to limit the
> size of the object-tree in memory (or estimate its size, and we can
> stop operations when it reaches a certain size) so that we don't end
> up with a multi-GB object-tree that then fails to serialize to byte[]
> because it is too big.
> We are building our PDF documents from scratch, starting with the page
> definitions, fonts, etc. then adding titles, paragraphs of text, etc.
> It's all fairly straightforward, and we have full control over the
> whole process up to and including the call to
> PDDocument.save(OutputStream).
> We are manually constructing our pages as well, so I suppose we could
> simply limit the number of pages, but I'm more concerned about the
> size of the memory used and not the number of pages.
> Is there anything in PDFBox that can help us with this? We can always
> count e.g. the number of bytes/characters we have written to the PDF,
> but that seems less important than what is going on inside of the PDF
> structure itself.
> - -chris
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
> mgrUoJ0aAhpgwtuWEupTNHk08fufWmzwFmaxH5SMLpM7FALvy+u3ssn1w2+5OBZA
> xStk2Ni8dIo7jjl0YSC2wJ+z4FcfSzV40ut90OmrpkIpnPKM0ICYSERfxhiz1qzN
> Fhwtty2r+6o/OpyxPAVcLotWIKsOaXPxNg+LGh2WuOko58eXAABgHnMOw5w0ptZp
> n0DKDo36J0Y8towyQgGjUAIYq8a/8Lf1UVYsQI3qqZoo3B0N3TmSxy+wwNBJ9dyH
> l599aaBOuUh4BFg0JoAjkEge8Qobl7UrYA88mf6mcOeEKkUy5cald0WKZLkJChl3
> Vwybn8brtMJeXTTKpLQWgCQCDLmGUK181fGvofCqHaxdGkBYjqp4NjuqNXrG8adi
> FpMsxhLk/gpYyJ7i1a3ta+PqU3rw103fEEP5YNQGZx64/Ec4sqzC7QJ0E08hqpau
> /Ye9goyJ0a+620HS7GeYYCzN+bVVkdG2FUHWcRWG1hSF8+PLi1Y4atWDyWhG1qc7
> l3KU6NfM5UE+jS/lElUQxyTF9GuGdIhYfkuC5nl6tF2FI6drRogQ95mkEwFGWbw9
> ijssUevr43W/Gx5nUUKZueTjsLTDzgjCWk4cymDKAbP0PtOgE6EWxaP2LiFp9znH
> JOMb727eMhcfuNEO0eMj
> =odVE
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org

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

View raw message