PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

How to modify a PdfDictionary Stream
http://forum.pdfsharp.com/viewtopic.php?f=2&t=3769
Page 1 of 1

Author:  prw56 [ Fri Apr 20, 2018 6:33 pm ]
Post subject:  How to modify a PdfDictionary Stream

Hello,

I am trying to convert a Stream's value to a string, modify it, then assign the new string as the Stream's value, and save the Pdf.

I assumed it would be something like this:

Code:
               PdfDictionary contentsDict = dictObj.Elements.GetValue("/Contents") as PdfDictionary;
               if (contentsDict == null || contentsDict.Stream == null)
                  continue;

               PdfString pdfString = new PdfString(contentsDict.Stream.ToString().Replace("141.12", "0"),PdfStringEncoding.StandardEncoding);

               byte[] stringAsByteArray = //something like pdfString.ToByteArray, but that method does not exist

               contentsDict.Stream.Value = stringAsByteArray;


but no ToByteArray method exists. The only reason I'm trying to use a PdfString here is because I could not find another way to use any of the PdfStringEncoding types.

How should I encode the modified string?

How do I assign it to the Stream I want to modify afterwards?

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