c# - Read an Aspose pdf from stream with IText -


i need read pdf created aspose, using itextsharp. here code :

// instantiate pdf object aspose.pdf.generator.pdf pdf = new aspose.pdf.generator.pdf(); // specify character encoding for html file pdf.htmlinfo.charset = "utf-8"; pdf.htmlinfo.charsetapplyinglevelofforce = aspose.pdf.generator.htmlinfo.charsetapplyingforcelevel.usewhenimpossibledetectfromcontent;  // bind source html pdf.bindhtml(htmlstring);  memorystream stream = new memorystream(); pdf.save(stream);  form form = new form(); form.bindpdf(stream);  var instream = new memorystream(input.templatefile);  var pdfconcat = new pdfconcatenate(instream); var pdfreader = new pdfreader(stream);  pdfreader.selectpages(new list<int>() { 0, 1 }); pdfconcat.addpages(pdfreader);  pdfreader.close(); pdfconcat.close(); 

while debugging, got following error on line var pdfreader = new pdfreader(stream);

pdf header signature not found

what want : - create 1 pdf page html string - append existing pdf

any idea how solve issue ?

you a

form.bindpdf(stream); 

before give stream itextsharp

var pdfreader = new pdfreader(stream); 

the former operation reads stream leaving nothing read pdfreader.

probably a

stream.position = 0; 

right before pdfreader initialization can rewind stream.


if not work (e.g. if form.bindpdf not merely read stream manipulates it), retrieve byte[] copy of stream

byte[] bytes = stream.toarray(); 

before bindpdf call , initialize pdfreader that:

var pdfreader = new pdfreader(bytes); 

Comments

Popular posts from this blog

Capture and play voice with Asterisk ARI -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -