C# ITextSharp Copy existing PDF to new PDF -
i working series of pdf files. many of them have fields, able populate using itextsharp.
my issue there 1 static pdf seems reporting odd size, 9.5 x 12. page size should 8.5 x 11 , if opened using acrobat reader, prints fine.
to around this, want create new pdf document, using correct page size, read static file new document, save , print it.
i have read number of posts here on , done number of searches solution, of seem skirt particular issue.
is there way copy existing pdf new document using correct page size?
thank you
update
taking bruno's advice, did double check crop box , media box. pdf working has both. crop box array is
[28.008, 38.016, 640.008, 830.016]
and media box array
[0, 0, 668.016, 848.016]
i can alter upper right corner points making crop box , media box same crop box
[28.008, 38.016, 612, 792]
and media box
[0, 0, 612, 792]
but doing shifts "text" right , top much, leaving uneven margin.
i found changing lower left coordinates, of crop box, can shift text. in fact setting crop box 40, 40, 612, 792 works, top , bottom margins narrow.
i need media box 0, 0, 612, 792. not issue there. how shrink crop box , center text on page? must missing something.
i've followed bruno's rotatepages method, in book, , looked @ answer, itextsharp copy document, resize custom size, , center
but whatever change crop box seems zoom in on it.
any advice appreciated
thank bruno lowagie , mkl. assistance able arrive @ solution.
private void resizeform ( string path, string filename ) { string src = path + @"\" + filename + "_pre.pdf"; string dest = path + @"\" + filename + ".pdf"; file.move ( dest, src ); using ( pdfreader pdf = new pdfreader ( src ) ) { pdfdictionary pagedict; pdfarray cropbox; pdfarray mediabox; float letterwidth = pagesize.letter.width; float letterheight = pagesize.letter.height; int pagecount = pdf.numberofpages; ( int = 1; <= pagecount; i++ ) { pagedict = pdf.getpagen ( ); cropbox = pagedict.getasarray ( pdfname.cropbox ); mediabox = pagedict.getasarray ( pdfname.mediabox ); cropbox [ 0 ] = new pdfnumber ( 30 ); cropbox [ 1 ] = new pdfnumber ( 40 ); cropbox [ 2 ] = new pdfnumber ( letterwidth + 30 ); cropbox [ 3 ] = new pdfnumber ( letterheight + 40 ); mediabox [ 0 ] = new pdfnumber ( 30 ); mediabox [ 1 ] = new pdfnumber ( 40 ); mediabox [ 2 ] = new pdfnumber ( letterwidth + 30 ); mediabox [ 3 ] = new pdfnumber ( letterheight + 40 ); pagedict.put ( pdfname.cropbox, cropbox ); pagedict.put ( pdfname.mediabox, mediabox ); } pdfstamper stamper = new pdfstamper ( pdf, new filestream ( dest, filemode.create ) ); stamper.close ( ); } }
it may bit overkill, works purposes.
hopefully, else.
Comments
Post a Comment