#30 Crash when opening a saved Acrobat Reader X document

open
nobody
None
5
2013-01-26
2012-02-28
No

PDF Clown v0.1.1.0.
Open any PDF document with Acrobat Reader X.
Save the document using Save As (PDF).
Using the code snippet below, open the document as a file stream.
Don't modify any parameters, save the stream.
Repeat the above:
Using the code snippet below, open the document as a file stream.
Don't modify any parameters, save the stream.
PDF Clown crashes with the exception Unknown type: Keyword.
at org.pdfclown.tokens.BaseParser.ParsePdfObject() in C:\Research and Development\PDFClownTestApp\Test App\pdfclown.lib\src\\org\pdfclown\tokens\BaseParser.cs:line 147

This does not occur when the PDF document is saved as using Acrobat Reader 8.

Code snippet:
public void WriteStuff(Stream ostream)
{
// Make a copy of the stream to use as the input
using (MemoryStream istream = new MemoryStream((int)ostream.Length))
{
// Copy the output stream to the new input stream
ostream.CopyTo(istream);

// Seek back to the beginning of input stream
istream.Seek(0, SeekOrigin.Begin);// input stream - a copy of the output stream.

// use input stream (copy of outstream) to create msg objects
using (org.pdfclown.bytes.Stream pdfStreamIn = new org.pdfclown.bytes.Stream(istream))
{
org.pdfclown.files.File pdfFile = new org.pdfclown.files.File(pdfStreamIn);
Document pdfDoc = pdfFile.Document;

// Seek back to the beginning of the original output stream:
ostream.Seek(0, SeekOrigin.Begin);

// reset the output stream length
ostream.SetLength(0);

using (org.pdfclown.bytes.Stream pdfStreamOut = new org.pdfclown.bytes.Stream(ostream))
{
pdfFile.Save(pdfStreamOut, SerializationModeEnum.Standard);
}
}

Discussion

  • Stefano Chizzolini

    I lost the count of code gymnastics you made :-)
    It's better that you attach the PDF files demonstrating that behavior... unfortunately I have no time to further improve my muscles -- pan guellich series are just enough for me... :-D

     
  • JazzyFizzles

    JazzyFizzles - 2012-03-07

    We found the behaviour was reproducible with any version of PDF document that was opened and saved with Acrobat Reader X.

    What do you mean by code gymnastics? The code is based on given examples, and we need to make a copy of the stream as the PDFClown library doesn’t allow read / write to the same stream. If we are wrong, please explain.

    Thanks, James.

     
  • Stefano Chizzolini

    I said "code gymnastics" because your reproduction steps seemed somewhat convoluted: is the stream-copy algorithm described in your code snippet needed to generate the behaviour or not? Can you please attach the versions of the *same* document saved through Reader 8 and Reader X, so I can compare them?

    thank you
    Stefano

     
  • JazzyFizzles

    JazzyFizzles - 2012-03-08

    PDF doc opened with Acrobat Reader v8, and SaveAs

     
  • JazzyFizzles

    JazzyFizzles - 2012-03-08

    PDF doc opened with Acrobat Reader vX, and SaveAs

     
  • JazzyFizzles

    JazzyFizzles - 2012-03-08

    Hi, I've uploaded two files.
    The v8 file I can re/write 'nothing' multiple times.
    The vX file crashes on writing 'nothing' a second time.

    Writing 'nothing' uses the code snippet above.

     
  • JazzyFizzles

    JazzyFizzles - 2012-03-09

    Further update, if we change the serialisation mode in the call to the PDFClown save function to Incremental, as below, we don’t get a crash when writing the stream from Acrobat Reader vX files, however the file size creeps up by 372 bytes each time.

    //pdfFile.Save(pdfStreamOut, SerializationModeEnum.Standard);// crash on second write
    pdfFile.Save(pdfStreamOut, SerializationModeEnum.Incremental);// no crash, but file size increases by 372bytes on each write.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks