2

I'm trying to make a program that produces pdf files. I've been studying the pdf format specification and specific pdf files whose format I'm trying to mimic. I found the line /FlateDecode in these documents and when I searched about this compression method the google results referenced a built in .Net algorithm, Deflate.

The thing is, when I try to decode the encoded text from the aforementioned files using Deflate, the C# algorithm returns nothing (I copied the binary data in a hex editor into a new file, cutting off both the starting and trailing newline (0x0A)) and the online Deflate decoders say the text is invalid (here I copied the data from a text editor, so it was text in the local ANSI encoding), as in not encoded by the same algorithm, leading me to believe that despite google's best efforts it popped up a similarly named, but not identical compression method.

If this hypothesis is correct, then does anybody know if there is a publicly available, already implemented Flate encoder or do I have to write my own based on the PDF file format specifications?

If the hypothesis is incorrect and I'm just screwing up something, what am I screwing up?

2
  • As far as I can tell 'Flate' and 'Deflate' are the same thing, but there might be differences in headers or something that prevents decoding. You could perhaps try another implementation, like SharpZipLib.
    – JonasH
    Jul 30, 2021 at 12:28
  • Thank you, much obliged. :) Jul 31, 2021 at 16:07

1 Answer 1

3

If you just start the .net DeflateStream at index 2 in the PDF FlateDecode stream it will read perfectly! (Writing Flate streams is harder, you need to compute the Adler32 checksum for Adobe reader to recognize the stream. I do not have that working yet.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.