I'm looking to create a downloads page where users will have the ability to
generate a number of copies of a given selected PDF document.
Under the hood, each of these documents will be stamped with a number on the
first page.
Example:
1) User selects a PDF and selects to have 3 copies.
2) 3 numbers are going to be generated by our database (1 for each first page)
3) All three copies will be read, stamped, and sent to the ByteArrayOutputStream
4) user views a single PDF in the browser with three copies of the document
(concatenated, 1 right after another, each first page has a unique number that
was stamped).
Currently I have a working version, but this simply reads the original PDF,
stamps with the number, and is sent to the output stream.
I've looked through several examples out there for some ideas, but where I see
document concatenation the PDFCopy is being used. Where I
see a document being stamped with something, I see the PDFStamper. Both are
considered the "writer" so how could I use both?
This might be something simple, however my Java skills are rusty and I'm
loosing it trying to figure this out.
Any help would be greatly appreciated!
Below is a script I'm using in conjunction with coldfusion to stamp a document
and output to the browser.
Any ideas on modifying this script to do what I need would surely be a plus!
Also any ideas on the below script as far as what I put together so far and
what I could fix for the better would help!
I am limited to using coldfusion to reference the iText library, however a Java
example would help as well.
<cfscript>
seqNTxt = "Testing Number to Stamp 1234567890"; //hardcoded for now
xMargin = 12;
yMargin = 16;
fontSize = 8;
template = "D:\CFusionMX\wwwroot\...\...DIRECTORY
PATH...\...\TestPdfTemplate.pdf";
reader = createObject("Java",
"com.lowagie.text.pdf.PdfReader").init(template);
baos = createObject("Java", "java.io.ByteArrayOutputStream").init();
stamper = createObject("Java",
"com.lowagie.text.pdf.PdfStamper").init(reader,baos);
baseFont = createObject("Java", "com.lowagie.text.pdf.BaseFont");
baseFont = baseFont.createFont(baseFont.HELVETICA, baseFont.WINANSI,
baseFont.NOT_EMBEDDED);
numPages = reader.getNumberOfPages();
pageCord = reader.getPageSize(1);
pageDim = createObject("Java","com.lowagie.text.Rectangle").init(pageCord);
xPos = int(pageDim.right()) - xMargin;
yPos = int(pageDim.top()) - yMargin;
pcbOver = createObject("Java","com.lowagie.text.pdf.PdfContentByte");
pcbOver = stamper.getOverContent(1);
pcbOver.beginText();
pcbOver.setFontAndSize(baseFont, fontSize);
pcbOver.showTextAligned(pcbOver.ALIGN_RIGHT, seqNTxt, xPos, yPos, 0);
pcbOver.endText();
stamper.close();
//get the output and display
context = getPageContext();
context.setFlushOutput(false);
response = context.getResponse().getResponse();
out = response.getOutputStream();
response.setContentType("application/pdf");
response.setContentLength(baos.size());
out.write(baos.toByteArray());
out.flush();
out.close();
reader = "";
baos = "";
stamper = "";
baseFont = "";
pageDim = "";
pcbOver = "";
</cfscript>
THANKS!
-Adam
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/