How to use SetStreamData


I am evaluating PDFTron and from my first test, it seems to be a powerful library.
I looked on Goolge, website, SDK documentation... but I didn't find anything regarding my problem...

The aim of my test is to identify and object from a property, modify its streamdata and save the file.

The first part is OK, I am able to :
- identify my object,
- get the decoded stream data
- replace a part of the string

But I am not able to set the new stream data. I always get an error message :
"Output stream is corrupt Conditional expression: false Filename : FilterWriter.cpp Function : trn::Filters::FilterWriter::WriteBuffer Linenumber : 59"

This is my code :

If System.Text.ASCIIEncoding.ASCII.GetString(o.GetBuffer()) = "[jobname 0]" Then
  o = doc.GetObj(i)
  Dim f As Filter = o.GetDecodedStream()
  Dim fr As New pdftron.Filters.FilterReader(f)
  Dim buff(f.Size) As Byte
  Dim nb As Integer = fr.Read(buff)
  Dim str As String = System.Text.ASCIIEncoding.ASCII.GetString(buff)
  str = str.Replace(txt_ancienne_valeur.Text, txt_nouvelle_valeur.Text)
  o.SetStreamData(System.Text.Encoding.ASCII.GetBytes(str), f)
End If

Do you have any idea ?

Thanks in advance,


Hi Frédéric,

I think that you don’t need second param in SetStreamDataI(). Try:

Also make sure that you call doc.InitSecurityHandler() and make sure that the function does not return false. If return value is false it means that the document is password encrypted and you need to supply the pass in the call to doc.InitStdSecurityHandler(“pass”).

If this does not help could you please send us a full test proj. along with the test pdf to support at pdftron. Thanks!

Sorry for my late, the solution proposed by support works well. Many thanks