I have seen plenty of ways to change the pagesize of a new blank document, but I can not get it to work on a PDF i've accessed via pdfReader
Help?
I have seen plenty of ways to change the pagesize of a new blank document, but I can not get it to work on a PDF i've accessed via pdfReader
Help?
Warning: I know Very Little about CF, but quite a bit about iText.
Henry's answer will work, but it could be a bit more efficient.
You want a PdfStamper
. Changing the page size isn't something that is directly supported at a higher level, so you'll have to use low-level pdf object calls. Like this:
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
In addition to the media box, you may also have to modify the CROPBOX, using the same "get the rect, adjust the bottom" technique. Note that there are several other page boxes that might exist in your PDF that may or may not need to be modified... "art box", "trim box", "bleed box". I may have forgotten one or two as well.
This will almost certainly result in a negative value for your bottom Y coordinate[s]. If your PDF is processed by a Less-Than-Good bit of software, this could be a problem. This would be a bug in their software, not this process. However, if you need to work around a problem like this, Henry's code will do the trick, producing pages with 0,0 as the lower left corner. Adobe won't bat an eye, nor will iText itself, though software written using iText might not be so savvy.
not sure if it works, but here's what I found
You can use a blank PDF of the proper page size as a starting point and then overlay the PDF segments in the right position 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
Haven't tested 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">
see <cfpdf>
doc : http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7995.html