PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Modifying stream data for a page
https://forum.pdfsharp.net/viewtopic.php?f=2&t=20
Page 1 of 1

Author:  bvsoftware [ Wed Nov 08, 2006 4:23 pm ]
Post subject:  Modifying stream data for a page

Does anyone have code samples of how to modify the stream contents of a page?

I can get the stream decoded and modified but I can't seem to locate the "/Filter" element in order to encode the modified instructions.

Author:  bvsoftware [ Wed Nov 08, 2006 9:55 pm ]
Post subject:  Figured out part of it.

I've figured out the filter part now. Instead of pulling the single page content stream I'm walking all the elements in the PDF file and looking for PDFDictionary objects. I check to see if they have a stream and then I can get the /Filter value. I had to encode my modified stream and now it shows up in the modified PDF.

I am running into one more issue. InDesign sends text as hex encoded. It looks like this:

<0044>Tj

Which appears as the letter "a" but I haven't figured out the encoding yet because it doesn't match up to the standard ASCII or unicode values for "a"

Author:  Stefan Lange [ Thu Nov 09, 2006 1:26 pm ]
Post subject: 

PDFsharp 0.9 contains an early implementation of PdfSharp.Pdf.Content. ContentReader that converts a content stream in a sequence of instances of objects derived form CObject. My current code also has a ContentWriter that converts the objects back to a content stream.

This works fine, but it is just the beginning of the problem. The meaning of
Code:
<0044>Tj
can be determined only with the font that is used. PDF has no native support for Unicode. For using Unicode a so called CID (character ID) font must be derived from the underlying TrueType font. 0x0044 is NOT the Unicode character but the glyph id within the TrueType font the CID font is based on. :? To reverse lookup which character corresponds to 0x0044 you must use the ToUnicodeMap. It maps glyph IDs to Unicode characters. In general glyph IDs and Unicode characters are not the same values.

To save space tools like InDesign typically embed only a subset of the Unicode fonts in the PDF file. The subset only contains the glyphs used in your document. To make the structure of the internal tables of this subset font easier, the glyphs are renumbered when the subset font is created. Without the corresponding ToUnicodeMap even Acrobat cannot 'read' your Unicode text anymore (i.e. it cannot copy selected text to the clipboard), even if you can read the text very well because you interpret the stroked glyphs…

Best you can do is to embed the whole font. Then the glyph IDs and Unicode values partially match with an offset. With the help of the ToUnicodeMap you can encode or decode the text.

Regards
Stefan Lange

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/