当前位置:首页 > 开发 > 开源软件 > 正文

iText PDF template

发表于: 2012-07-26   作者:cute.spring   来源:转载   浏览:
摘要: useful materials http://svn.assembla.com/svn/jarbilling/billing/trunk/billing/vendor/pdfmanipulator/Fdf.java http://svn.assembla.com/svn/jarbilling/billing/trunk/billing/vendor/pdfmanipulator/test/B
useful materials
http://svn.assembla.com/svn/jarbilling/billing/trunk/billing/vendor/pdfmanipulator/Fdf.java
http://svn.assembla.com/svn/jarbilling/billing/trunk/billing/vendor/pdfmanipulator/test/BatchFormFill.java
http://www.coderanch.com/t/63861/open-source/iText-Silent-Print
http://threebit.net/mail-archive/itext-questions/msg02068.html

part4.chapter13.PrintPreferencesExample:
http://itextpdf.com/examples/iia.php?id=230

http://comments.gmane.org/gmane.comp.java.lib.itext.general/28053

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Map.Entry;
import java.util.Set;

import com.itextpdf.text.Document;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.AcroFields.Item;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;

public class PdfTest2 {
	public static void main(String[] args) throws Exception {
		// Create output PDF
		Document document = new Document(PageSize.A4);

		document.open();

		// Load existing PDF
		PdfReader reader = new PdfReader(new FileInputStream(
				"Sample application form_ENG edit.pdf"));
		// PdfImportedPage page = writer.getImportedPage(reader, 1);

		// we'll create the file in memory
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		// Now we create the PDF
		PdfStamper stamper = new PdfStamper(reader, baos);
		// We alter the fields of the existing PDF
		AcroFields fields = stamper.getAcroFields();

		 BaseFont baseFont = FontFactory.getFont(FontFactory.TIMES_ITALIC,BaseFont.IDENTITY_H, new Float(12)).getBaseFont();

		Set<Entry<String, Item>> entrySet = fields.getFields().entrySet();
		for (Entry<String, Item> entry : entrySet) {
			String key = entry.getKey();
			System.out.println(key);
			fields.setField(key, key);
//			if (fields.getFieldType(key) == AcroFields.FIELD_TYPE_TEXT) {
				fields.setFieldProperty(key, "textfont", baseFont, null);
				fields.setFieldProperty(key, "textsize", new Float(16), null);
//			}
		}
		fields.setField("tradeID", "007");
		// close the stamper
		fields.setField("acNo", "9527");
		 
	 
		stamper.close();

		document.close();

		// let's write the file in memory to a file anyway
		FileOutputStream fos = new FileOutputStream("HelloWorld-Gavin.pdf");
		fos.write(baos.toByteArray());
		fos.close();

	}
}

iText PDF template

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号