Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

COSStream Object Reference in COSObjectProxy

Help
jschneider
2014-03-03
2014-03-04
  • jschneider
    jschneider
    2014-03-03

    Hi,

    I have a PDDocument doc and would like to add an COSObjectProxy for doc.getCatalog().cosGetField(COSCatalog.DK_Metadata) whose type is COSStream. When I do so, in the finally written PDF file, the stream in supplied inline, not as a reference to a stream object, e.g.

    20 0 obj
    <<
    /Type /Catalog
    /PieceInfo 10 0 R
    /AcroForm 37 0 R
    ...SOME MORE ENTRIES...
    /Metadata <<
    /Subtype /XML
    /Type /Metadata
    /Length 3498
    >>

    stream
    STREAM CONTENT
    endstream
    >>
    endobj

    instead of

    20 0 obj
    <<
    /Type /Catalog
    /PieceInfo 10 0 R
    /AcroForm 37 0 R
    ...SOME MORE ENTRIES...
    /Metadata 21 0 obj
    >>
    endobj

    21 0 obj
    <<
    /Subtype /XML
    /Type /Metadata
    /Length 3498
    >>

    stream
    STREAM CONTENT
    endstream
    endobj

    According to the PDF Standard, the first is not allowed.

    Is there anything I can do to have it the second way?

    Thanks in advance!
    Johannes

     
  • jschneider
    jschneider
    2014-03-04

    I think I found it out by myself: Adding "beIndirect()" to the constructor of the proxy object seems to do the trick.

     
  • mtraut
    mtraut
    2014-03-04

    sorry for being too late and thank you for adding your solution.

    btw., you should need a "proxy" only if you have the special need to add physical content to the serialized document after writing is done (like you do when creating a signature). Otherwise you should be fine with adding a stream (which is always indirect) directly.

    What is your concrete scenario?

    Michael

     
  • jschneider
    jschneider
    2014-03-04

    Creating a signature. :)

    Johannes