How to resize an existing PDF file using Coldfusion / iText

I saw many ways to resize a new blank document, but I can not get it to work with the PDF file through which I accessed via pdfReader

reference

0
source share
2 answers

not sure if it works, but here is what i found

You can use a blank PDF file with page size as a starting point, and then overlay PDF segments to the right as watermarks using DDX. You probably need to flatten the PDF after each watermark has been added.

http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:62109

Did not check the code, but maybe something like this?

<cfpdf name="resizedPdf" action="addwatermark" source="blank.pdf" copyfrom="image.pdf">
<cfpdf name="resizedPdfWithFooter" action="addfooter" source="resizedPdf" text="xyz">

. <cfpdf> doc: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7995.html

+1

: CF, iText.

, .

PdfStamper. , , PDF. :

final static float POINTS_PER_INCH = 72f;
final static float INCHES_TO_ADD = 3f;

PdfReader reader = new PdfReader(pdfPath); // throws
PdfStamer stamper = new PdfStamper(reader, outputStream); // throws

for (int curPageNum = 1; curPageNum <= reader.getNumberOfPages(); ++curPageNum) {
  PdfDictionary pageDict = reader.getPageN(curPageNum);
  // pdf rects are stored as [llx, lly, urx, ury].
  // X increases to the right, Y increases upward.  
  // Note that the origin doesn't have to be 0,0.
  PdfArray mediaBox = pageDict.getAsArray(PdfName.MEDIABOX);
  float curBottom = mediaBox.getAsNumber(1).floatValue();
  curBottom -= INCHES_TO_ADD * POINTS_PER_INCH;
  mediaBox.set(1, new PdfNumber(curBottom));
}

stamper.close(); // throws

- CROPBOX, "get rect, adjust the bottom". , PDF , ... "art box", "trim box", "bleed box". , .

Y [s]. PDF , . ​​ , . , , , , 0,0 . Adobe , iText, , iText, .

+2

Source: https://habr.com/ru/post/1772498/


All Articles