My last message got a little garbage, but I have found a half solution. Code is
below. This edits a pdf file with forms, creats another , then merges them
together. The only problem is that the resulting document has the the tables
from the second document starting on the page after the forms instead of right
after the forms. Hope this isnt' too. Any ideas on how to add content driectly
after a form area in a document?
public static void buildProvDosesAdminReport(String docType, FileOutputStream
out ) throws Exception {
//read in existing PDF with forms
ByteArrayOutputStream pdfStream1 = new ByteArrayOutputStream();
PdfReader reader = new
PdfReader("docs/pdf/providers_dose_admin.pdf");
PdfStamper stamp = new PdfStamper(reader , pdfStream1 );
AcroFields form = stamp.getAcroFields();
//Find text fields to fill out
Date now = new Date();
form.setField("ClinicName", "provider");
formatter.applyPattern(DATE_FORMAT);
form.setField("Date", formatter.format(now) );
formatter.applyPattern(TIME_FORMAT);
form.setField("Time", formatter.format(now) );
form.setField("Address", "street");
form.setField("City", "city");
form.setField("Phone", "phone");
form.setField("State", "state");
form.setField("Zip", "zip");
form.setField("Fax", "fax");
form.setField("Contact", "contact");
stamp.setFormFlattening(true);
//write to pdfStream and close editing
stamp.close();
//Create the document with tables.
ByteArrayOutputStream pdfStream2 = new ByteArrayOutputStream();
Document document = new Document(PageSize.A4, 10, 10, 10, 10);
PdfWriter writer = PdfWriter.getInstance(document, pdfStream2);
document.open();
int NumColumns = 11;
PdfPTable datatable = new PdfPTable(NumColumns);
int headerwidths[] = { 10, 8, 8, 6, 6, 6, 6, 7, 7, 7, 5 }; //
percentage
datatable.setWidths(headerwidths);
datatable.setWidthPercentage(90); // percentage
datatable.getDefaultCell().setPadding(1);
datatable.getDefaultCell().setBorderWidth(2);
datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
datatable.addCell("Lot #");
datatable.addCell("Vaccine Code");
datatable.addCell("Manuf.");
datatable.addCell("< 1 yrs.");
datatable.addCell("1-4 yrs.");
datatable.addCell("5-11 yrs.");
datatable.addCell("12-17 yrs.");
datatable.addCell("18-49 yrs.");
datatable.addCell("50-64 yrs.");
datatable.addCell("65 + yrs.");
datatable.addCell("Total");
datatable.setHeaderRows(1); // this is the end of the table
header
datatable.getDefaultCell().setBorderWidth(1);
for (int i = 1; i < 14; i++) {
if (i % 2 == 1) {
datatable.getDefaultCell().setGrayFill(0.9f);
}
for (int x = 0; x < NumColumns; x++) {
if (i==13 && x==0) datatable.addCell("Total");
else datatable.addCell(""+i);
}
if (i % 2 == 1) {
datatable.getDefaultCell().setGrayFill(0.0f);
}
}
document.add(new Paragraph("\nFederal Funding\n\n"));
document.add(datatable);
document.add(new Paragraph("\nState Funding\n\n"));
document.add(datatable);
document.add(new Paragraph("\nSpecial Projects Funding\n\n"));
document.add(datatable);
document.add(new Paragraph("\nOther Funding\n\n"));
document.add(datatable);
document.close();
//Read the two files and merge.
PdfCopyFields copy = new PdfCopyFields( out );
PdfReader reader1 = new PdfReader( pdfStream1.toByteArray() );
PdfReader reader2 = new PdfReader( pdfStream2.toByteArray() );
copy.addDocument(reader1);
copy.addDocument(reader2);
copy.close();
}
>>> "Paulo Soares" <[EMAIL PROTECTED]> 12/5/2005 1:42 pm >>>
Do the first part with PdfStamper and flattening and then import the pages.
----- Original Message -----
From: "Eric Anderson" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, December 05, 2005 5:33 PM
Subject: [iText-questions] Copying stamped objects to a document.
Is there anyway to do something like this?
Document document = new Document(PageSize.A4, 10, 10, 10, 10);
document.open();
PdfReader reader = new PdfReader("../docs/pdf/providers_dose_admin.pdf");
PdfStamper stamp = new PdfStamper(reader , out);
AcroFields form = stamp.getAcroFields();
.... fill in forms then flatten?
then
document.add(stamp.getAll()); ??
How can I bring in an already created document with stamps, fill in those
stamps and use that in my documents?
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions