pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thad Humphries <thad.humphr...@gmail.com>
Subject Re: How do I analyze a problem PDF?
Date Wed, 01 Mar 2017 19:14:16 GMT
On Wed, Mar 1, 2017 at 2:01 PM, Tilman Hausherr <THausherr@t-online.de>
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: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>


-- 
"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)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message