Cutting pdf page in half and reimposing parts differently using ghostscript -


i'm looking ghostscript (or other commandline) command reimpose pdf page elements on left side copied right. so: schematic view of reimposition

the size of page shouldn't change (each page cropped , cut differently), , while supply final size manually, neater read original pdf.

for sake of simplicity, let's assume input file has 1 page.

i've come extremely complicated series of commands, involving

  • reading cropbox pdfinfo
  • copying file , changing cropbox left half shortened , right half extended -c "[/cropbox [*new dimensions*] /pages pdfmark" command
  • copying file , changing cropbox left half remains
  • reprocessing file old page dimensions -g "pagedimension" , -c \"<<\/install{1 1 scale withofrightside 0 translate}>> setpagedevice\"
  • use pdftk merge 2 new files 1 page: pdftk.exe lefthalf.pdf background righthalf.pdf output combinedfile.pdf

i couldn't work satisfactorily, however, , don't either series of steps involved or number of tools invovled. surely steps performed ghostscript , in fewer steps (and less reprocessing of original).

i have come useful solution - though not reflect original question fully.

this solution based on (proprietary) acrobat, , uses acrobat javascript interface - not ghostscript. following script works beautifully, why decided share it:

/*   * acrobat pdf script   * transpose part of left page right side , recrop document   */    // define cutting line, in points left  var cuttingline = 300;    /* define offset(s)  ---  if uncertain, leave @ 0     a) of new left page border,      b) of transposed half of page          watch out:      a) may expose material original left half when negative     b) may expose material original right half when negative - leave "correctcrop" true avoid this.  */  var offsetleft = 5;  var offsettransposition = -50;  var correctcrop = true;    // cut off left page , add white space right, insert left part of page on top right  (var p = 0; p < this.numpages; p++) {    // add white space media box right    console.println("\npage " + (p + 1));    var arect = this.getpagebox("media", p);    console.println("original media box: " + arect);    arect[2] += cuttingline + offsettransposition;    console.println("new media box: " + arect);    this.setpageboxes("media", p, p, arect);        // add copy of page overlay, shifted right    this.addwatermarkfromfile({      cdipath: this.path,      nsourcepage: p,      nstart: p,      nend: p,      nhorizalign: app.constants.align.left,      nvertalign: app.constants.align.bottom,      nhorizvalue: arect[2] - cuttingline + offsettransposition,      nvertvalue: 0    });      // crop left, add space crop box right reveal page copy    var arect = this.getpagebox("crop", p);    console.println("original crop box: " + arect);    arect[0] += cuttingline + offsetleft;    arect[2] += cuttingline + offsettransposition + (((correctcrop == true) && (offsettransposition < 0)) ? offsettransposition : 0);    console.println("new crop box: " + arect);    this.setpageboxes("crop", p, p, arect);  }    // flatten layers  this.flattenpages();

please take note: doubles page content. use preflight profile or acrobat's document cleanup-tools remove (invisible) page contents.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -