Can I save twice to the same stream?

40 views
Skip to first unread message

Aaron

unread,
Oct 10, 2014, 12:39:11 PM10/10/14
to pdfne...@googlegroups.com
Q:

I'm signing a document twice, and each time saving to a memory stream incrementally.  My code looks something like this:

using (var ms = new MemoryStream())
{
 
using (PDFDoc doc = new PDFDoc(infile))
 
{
   
// [...sign the document...]
    doc
.Save(ms, 0);
 
}
  ms
.Position = 0;
 
using (var doc = new PDFDoc(ms))
 
{
   
// [...sign the document with a second signature...]
    doc
.Save(ms, SDFDoc.SaveOptions.e_incremental);
   
// [...save ms to file...]
 
}
}


The save after the second signature results in a corrupted file.  What's going wrong?



A:

You should save to a second stream different than the one you loaded the PDF from.  For example:

using (var ms = new MemoryStream())
{
 
using (PDFDoc doc = new PDFDoc(infile))
 
{
   
// [...sign the document...]
    doc
.Save(ms, 0);
 
}
  ms
.Position = 0;
 
using (var doc = new PDFDoc(ms))
 
{
   
// [...sign the document with a second signature...]
   
using (var ms1 = new MemoryStream())
   
{
      doc
.Save(ms1, SDFDoc.SaveOptions.e_incremental);
     
// [...save ms1 to file...]
   
}
 
}
}














Reply all
Reply to author
Forward
0 new messages