C# iTextsharp Replace Page of a multi-page PDF -
say, have 5-page pdf called 'a.pdf' page 2 , 4 empty. , 2-page pdf called 'b.pdf'. want copy the first page of 'b.pdf' page2 of 'a.pdf' , second page of 'b.pdf' page 4 of 'a.pdf'.
i found it's quite hard find examples, found provided here, http://itextsharp.10939.n7.nabble.com/replace-pages-with-itextsharp-td2956.html called 'pdfstamper.replacepage()', guess i'm looking for, did simple demo didn't work out. can have check me?
string _outmergefile = server.mappath("~/11/a.pdf"); string file2 = server.mappath("~/11/b.pdf"); pdfreader readera = new pdfreader(_outmergefile); pdfreader readerb = new pdfreader(file2); pdfstamper cc = new pdfstamper(readera,new memorystream()); cc.replacepage(readerb, 1, 2); cc.replacepage(readerb, 2, 4); cc.close();
thanks in advance.
================================================================================= jose's suggestion. code works now. i'm providing simple sample here others reference.
public void myfunction() { string _outmergefile = server.mappath("~/11/a.pdf"); string file2 = server.mappath("~/11/b.pdf"); pdfreader readera = new pdfreader(_outmergefile); pdfreader readerb = new pdfreader(file2); pdfstamper cc = new pdfstamper(readera, new filestream(server.mappath("~/11/result.pdf"), filemode.append)); cc.replacepage(readerb, 1, 2); cc.close(); }
ok, think i've found problem. cc
created in memory, , don't see code save actual changes file before close it, alterations made in-memory file lost. 1 option create new filestream ()
instead of memory stream
Comments
Post a Comment