On Wed, Mar 1, 2017 at 2:01 PM, Tilman Hausherr <[email protected]>
wrote:
> Am 01.03.2017 um 19:56 schrieb Thad Humphries:
>
>> I know that PDDocument (and COSDocument) has a close() method, but how do
>> I
>> reopen PDDocument? I see no open() method. In my merge method (below), if
>>
>
> You have to reload it from a file or a stream.
>
> the global document is closed here (before inDoc.close() as you suggest) or
>> elsewhere (in another method), won't the next call to
>> "merger.appendDocument(document, inDoc);" fail?
>>
>
> There is no exception for closing a document that uses resources that have
> already been closed. That's why the sequence is important:
>
> First save your work
> then close all documents the work is based on.
Thanks. I revised my mergePdfDoc() to do just that, and my test runs with
my problem PDF:
PDDocument document;
...
protected void mergePdfDoc(byte [] buffer) throws IOException {
PDFMergerUtility merger = new PDFMergerUtility();
PDDocument inDoc = PDDocument.load(buffer);
merger.appendDocument(document, inDoc);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
document.save(baos);
document.close();
inDoc.close();
document = PDDocument.load(baos.toByteArray());
baos.close();
}
>
>
>> PDDocument document;
>> ...
>> protected void mergePdfDoc(byte [] buffer) throws IOException {
>> PDFMergerUtility merger = new PDFMergerUtility();
>> PDDocument inDoc = PDDocument.load(buffer);
>> merger.appendDocument(document, inDoc);
>> inDoc.close();
>> }
>>
>> Is there an exception thrown closing an already closed
>> PDDocument/COSDocument? Or reopening an opened document?
>>
>
> No.
>
> Tilman
>
>
>> As for fonts, all I'm ever using is the PDType1Font fonts, so I think I'm
>> okay there.
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
--
"Hell hath no limits, nor is circumscrib'd In one self-place; but where we
are is hell, And where hell is, there must we ever be" --Christopher
Marlowe, *Doctor Faustus* (v. 121-24)