c# - PdfSmartCopy is copying the contents at the bottom (footer) of the new PDF file -


i have function cropping specific part of pdf file , adding new pdf file main problem getting is showing cropped part of page bottom (footer) of newly created pdf file. here code..

public static void croppdffile(string sourcefilepath, string outputfilepath) {     // allows pdfreader read pdf document without owner's password     pdfreader.unethicalreading = true;      // reads pdf document     using (pdfreader pdfreader = new pdfreader(sourcefilepath))     {         // set part of source document copied.         // pdfrectangel(bottom-left-x, bottom-left-y, upper-right-x, upper-right-y)          pdfrectangle rect = new pdfrectangle(0f, 9049.172f, 594.0195f, 700.3f);          using (var output = new filestream(outputfilepath, filemode.createnew, fileaccess.write))         {             // create new document             using (document doc = new document())             {                  // make copy of document                 pdfsmartcopy smartcopy = new pdfsmartcopy(doc, output);                  // open newly created document                 doc.open();                                // loop through pages of source document                 (int = 4; <= pdfreader.numberofpages; i++)                 {                     // page                     var page = pdfreader.getpagen(i);                      // apply rectangle filter created                       page.put(pdfname.cropbox, rect);                       page.put(pdfname.mediabox, rect);                      // copy content , insert new document                        smartcopy.setlinearpagemode();                      var copiedpage = smartcopy.getimportedpage(pdfreader, i);                     smartcopy.addpage(copiedpage);                  }                  // close output document                 doc.close();             }         }     } 

please me solve this..

the size of pdf page (expressed in user units) depends on value of mediabox. instance: media box of a4 page defined [0 0 595 842]

in case, origin of coordinate system (0, 0) coincides lower-left corner. coordinate of upper right corner (595, 842).

another possible value a4 page [0 842 595 1684]. same width (595 user units), same height (1684 - 842 = 842 user units), lower-left corner has coordinate (0, 842) , coordinate of upper-right corner (595, 1684).

you write create pdfrectangle using these parameters: (bottom-left-x, bottom-left-y, upper-right-x, upper-right-y). however, you're using these hard-coded values: 0f, 9049.172f, 594.0195f, 700.3f.

your lower-left-y (9049.172) @ higher position upper-right-y (700.3). doesn't make sense. hence: should consider changing value make sense. value should be, question can answer since know value of mediabox of file want crop.

in comment, explain pdf a4 page. can check using pdfreader method named getpagesize(). if want crop page see header of document, need use this:

pdfrectangle rect = new pdfrectangle(0f, 842 - x, 595, 842); 

where x height of header. instance, if header 100 user units, you'd need:

pdfrectangle rect = new pdfrectangle(0f, 742, 595, 842); 

it unclear why you're talking 100px. if want convert pixels points, please read convert pixels points

using formula mentioned there 100 pixels equals 75 points.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -