当前位置: 首页>>代码示例>>Java>>正文


Java Document.add方法代码示例

本文整理汇总了Java中com.lowagie.text.Document.add方法的典型用法代码示例。如果您正苦于以下问题:Java Document.add方法的具体用法?Java Document.add怎么用?Java Document.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.lowagie.text.Document的用法示例。


在下文中一共展示了Document.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createContent

import com.lowagie.text.Document; //导入方法依赖的package包/类
public void createContent(WebInput wi, DocInfo di)throws ControllerException {
	Document pdfDoc = di.getPdfDocument();
	try {
		pdfDoc.add(new Paragraph("Hello World!"));
		try {
			BaseFont bf = BaseFont.createFont("STSong-Light",
					"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
			Font FontChinese = new Font(bf, 12, Font.NORMAL);
			String info=wi.getParameter("info");
			Paragraph p0 = new Paragraph(info, FontChinese);
			pdfDoc.add(p0);
			Paragraph p1 = new Paragraph("Beetle Web Framework 页面生成PDF文件演示!", FontChinese);
			pdfDoc.add(p1);
		} catch (Exception ex1) {
			throw new ControllerException(ex1);
		}
	} catch (DocumentException ex) {
		throw new ControllerException(ex);
	}
}
 
开发者ID:jbeetle,项目名称:BJAF3.x,代码行数:21,代码来源:GenPdfController.java

示例2: close

import com.lowagie.text.Document; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
	try {
		float width = 0;
		float[] w = new float[iMaxWidth.length - iHiddenColumns.size()]; int wi = 0;
		for (int i = 0; i < iMaxWidth.length; i++)
			if (!iHiddenColumns.contains(i)) { width += 15f + iMaxWidth[i]; w[wi++] = iMaxWidth[i]; }
		Document document = new Document(new Rectangle(60f + width, 60f + width * 0.75f), 30f, 30f, 30f, 30f);
		PdfWriter writer = PdfWriter.getInstance(document, iOutput);
		writer.setPageEvent(new PdfEventHandler());
		document.open();
		iTable.setWidths(w);
		document.add(iTable);
		document.close();
	} catch (DocumentException e) {
		throw new IOException(e.getMessage(), e);
	}
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:19,代码来源:PDFPrinter.java

示例3: convertWriteToPdf

import com.lowagie.text.Document; //导入方法依赖的package包/类
public static void convertWriteToPdf(BufferedImage bufeBufferedImage, String path) {
    try {
        //Image img = Image.getInstance("C:\\Users\\SOFTWARE1\\Desktop\\boshtwain4JImages\\testcapture1507134499431.jpg");
        Image img = Image.getInstance(bufeBufferedImage, null);
        Document document = new Document(img);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
        //--
        document.open();
        img.setAbsolutePosition(0, 0);
        //--
        document.add(img);
        //--
        document.close();
    } catch (DocumentException | IOException e) {
        System.out.println("Intern Log : " + e.getMessage());
    }
}
 
开发者ID:nrreal,项目名称:twainBDirect,代码行数:18,代码来源:ImageManager.java

示例4: buildPdfDocument

import com.lowagie.text.Document; //导入方法依赖的package包/类
@Override
protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer,
		HttpServletRequest request, HttpServletResponse response) throws Exception {

	List<Book> books = (List<Book>) model.get("book");

	PdfPTable table = new PdfPTable(3);
	table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
	table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
	table.getDefaultCell().setBackgroundColor(Color.lightGray);

	table.addCell("Book Name");
	table.addCell("Author Name");
	table.addCell("Price");

	for (Book book : books) {
		table.addCell(book.getBookName());
		table.addCell(book.getAuthor());
		table.addCell("" + book.getPrice());
	}
	document.add(table);

}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:24,代码来源:PdfView.java

示例5: downloadPdfFile

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * Generates a PDF file with the given text
 * http://itext.ugent.be/itext-in-action/
 * @return A PDF file as a byte array
 */
public FileTransfer downloadPdfFile(String contents) throws Exception
{
    if (contents == null || contents.length() == 0)
    {
        contents = "[BLANK]";
    }

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, buffer);

    document.addCreator("DWR.war using iText");
    document.open();
    document.add(new Paragraph(contents));
    document.close();

    return new FileTransfer("example.pdf", "application/pdf", buffer.toByteArray());
}
 
开发者ID:directwebremoting,项目名称:dwr,代码行数:25,代码来源:UploadDownload.java

示例6: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * Using FontSelector.
 */
@Test
public void main() throws Exception {
	// step 1
	Document document = new Document();
	// step 2
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("fontselection.pdf"));
	// step 3
	document.open();
	// step 4
	String text = "This text is the first verse of \u275dThe Iliad\u275e. It's not polytonic as it should be "
			+ "with \u2798 and \u279a entoation variants but that's all we have for now.\n\n"
			+ "\u2766\u00a0\u00a0\u039c\u03b7\u03bd\u03b9\u03bd \u03b1\u03b5\u03b9\u03b4\u03b5, \u03b8\u03b5\u03b1, \u03a0\u03b7\u03bb\u03b7\u03b9\u03b1\u03b4\u03b5\u03c9 \u0391\u03c7\u03b9\u03bb\u03b7\u03bf\u03c2";
	FontSelector sel = new FontSelector();
	sel.addFont(new Font(Font.TIMES_ROMAN, 12));
	sel.addFont(new Font(Font.ZAPFDINGBATS, 12));
	sel.addFont(new Font(Font.SYMBOL, 12));
	Phrase ph = sel.process(text);
	document.add(new Paragraph(ph));
	// step 5
	document.close();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:26,代码来源:FontSelectionTest.java

示例7: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * Adds an Image at an absolute position.
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file

	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("absolutepositions.pdf"));

	// step 3: we open the document
	document.open();

	// step 4: we add content
	Image png = Image.getInstance(PdfTestBase.RESOURCES_DIR + "hitchcock.png");
	png.setAbsolutePosition(171, 250);
	document.add(png);
	png.setAbsolutePosition(342, 500);
	document.add(png);

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:29,代码来源:AbsolutePositionsTest.java

示例8: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * How to substiture special characters with Phrase.getInstance.
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();
	// step 2:
	// we create a writer that listens to the document
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("SymbolSubstitution.pdf"));

	// step 3: we open the document
	document.open();
	// step 4:
	document.add(Phrase.getInstance("What is the " + (char) 945 + "-coefficient of the " + (char) 946
			+ "-factor in the " + (char) 947 + "-equation?\n"));
	for (int i = 913; i < 970; i++) {
		document.add(Phrase.getInstance(" " + i + ": " + (char) i));
	}

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:25,代码来源:SymbolSubstitutionTest.java

示例9: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
    * Generates a document with a header containing Page x of y and with a Watermark on every page.
    */
@Test
public void main() throws Exception {
       	// step 1: creating the document
           Document doc = new Document(PageSize.A4, 50, 50, 100, 72);
           // step 2: creating the writer
           PdfWriter writer = PdfWriter.getInstance(doc, PdfTestBase.getOutputStream( "pageNumbersWatermark.pdf"));
           // step 3: initialisations + opening the document
           writer.setPageEvent(new PageNumbersWatermarkTest());
           doc.open();
           // step 4: adding content
           String text = "some padding text ";
           for (int k = 0; k < 10; ++k) {
               text += text;
           }
           Paragraph p = new Paragraph(text);
           p.setAlignment(Element.ALIGN_JUSTIFIED);
           doc.add(p);
           // step 5: closing the document
           doc.close();
       
   }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:25,代码来源:PageNumbersWatermarkTest.java

示例10: buildPdfDocument

import com.lowagie.text.Document; //导入方法依赖的package包/类
protected void buildPdfDocument(Map<String, Object> map, Document document,
                                PdfWriter pdfWriter, HttpServletRequest httpServletRequest,
                                HttpServletResponse httpServletResponse) throws Exception {
    Map<String,String> userData = (Map<String,String>) map.get("userData");

    Table table = new Table(2);
    table.addCell("No.");
    table.addCell("User Name");

    for (Map.Entry<String, String> entry : userData.entrySet()) {
        table.addCell(entry.getKey());
        table.addCell(entry.getValue());
    }
    document.add(table);
}
 
开发者ID:garyhu1,项目名称:spring_mvc_demo,代码行数:16,代码来源:UserPDFView.java

示例11: buildPdfDocument

import com.lowagie.text.Document; //导入方法依赖的package包/类
@Override
protected void buildPdfDocument(Map<String, Object> map,
                                Document document,
                                PdfWriter pdfWriter,
                                HttpServletRequest httpServletRequest,
                                HttpServletResponse httpServletResponse) throws Exception {
    Grade grade = (Grade) map.get("grade");
    String validationLink = (String) map.get("validationLink");

    document.add(generateTitle());
    document.add(EMPTY_LINE);
    document.add(generateContent(grade));
    document.add(EMPTY_LINE);
    document.add(generateValidation(validationLink));
}
 
开发者ID:university-information-system,项目名称:uis,代码行数:16,代码来源:GradePDFView.java

示例12: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * Demonstrates how to measure and scale the width of a Chunk.
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();
	// step 2:
	// we create a writer that listens to the document
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Width.pdf"));

	// step 3: we open the document
	document.open();
	// step 4:
	Chunk c = new Chunk("quick brown fox jumps over the lazy dog");
	float w = c.getWidthPoint();
	Paragraph p = new Paragraph("The width of the chunk: '");
	p.add(c);
	p.add("' is ");
	p.add(String.valueOf(w));
	p.add(" points or ");
	p.add(String.valueOf(w / 72f));
	p.add(" inches.");
	document.add(p);
	document.add(c);
	document.add(Chunk.NEWLINE);
	c.setHorizontalScaling(0.5f);
	document.add(c);
	document.add(c);

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:36,代码来源:WidthTest.java

示例13: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * Uses a java.awt.Image object to construct a com.lowagie.text.Image
 * object.
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("awt_image.pdf"));

	// step 3: we open the document
	document.open();

	// step 4: we add content to the document
	for (int i = 0; i < 300; i++) {
		document.add(new Phrase("Who is this? "));
	}
	PdfContentByte cb = writer.getDirectContent();
	java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(PdfTestBase.RESOURCES_DIR + "H.gif");
	Image image = Image.getInstance(awtImage, null);
	image.setAbsolutePosition(100, 500);
	cb.addImage(image);
	Image gif = Image.getInstance(awtImage, new Color(0x00, 0xFF, 0xFF), true);
	gif.setAbsolutePosition(300, 500);
	cb.addImage(gif);
	Image img1 = Image.getInstance(awtImage, null, true);
	img1.setAbsolutePosition(100, 200);
	cb.addImage(img1);
	Image img2 = Image.getInstance(awtImage, new Color(0xFF, 0xFF, 0x00), false);
	img2.setAbsolutePosition(300, 200);
	cb.addImage(img2);

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:41,代码来源:AwtImageTest.java

示例14: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * Example originally written by Wendy Smoak to generate a Table with
 * 'floating boxes'. Adapted by Bruno Lowagie.
 * 
 */
@Test
public void main() throws Exception {
	FloatingBoxesTest floatingBoxes = new FloatingBoxesTest();
	// step 1
	Document document = new Document();
	// step 2
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("FloatingBoxes.pdf"));
	// step 3
	document.open();
	// step 4
	PdfPTable table = new PdfPTable(2);
	table.setTableEvent(floatingBoxes);
	table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
	table.getDefaultCell().setCellEvent(floatingBoxes);
	table.getDefaultCell().setPadding(5f);
	table.addCell("value");
	table.addCell("name");
	table.addCell(new Paragraph("dog"));
	table.addCell(new Paragraph("cat"));
	table.addCell(new Paragraph("bird"));
	table.addCell(new Paragraph("horse"));
	document.add(table);

	// step 5
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:32,代码来源:FloatingBoxesTest.java

示例15: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * An example using MultiColumnText with irregular columns.
 */
@Test
public void main() throws Exception {
	Document document = new Document();
	OutputStream out = PdfTestBase.getOutputStream("multicolumnsimple.pdf");
	PdfWriter.getInstance(document, out);
	document.open();

	MultiColumnText mct = new MultiColumnText();

	// set up 3 even columns with 10pt space between
	mct.addRegularColumns(document.left(), document.right(), 10f, 3);

	// Write some iText poems
	for (int i = 0; i < 30; i++) {
		mct.addElement(new Paragraph(String.valueOf(i + 1)));
		mct.addElement(newPara(randomWord(noun), Element.ALIGN_CENTER, Font.BOLDITALIC));
		for (int j = 0; j < 4; j++) {
			mct.addElement(newPara(poemLine(), Element.ALIGN_LEFT, Font.NORMAL));
		}
		mct.addElement(newPara(randomWord(adverb), Element.ALIGN_LEFT, Font.NORMAL));
		mct.addElement(newPara("\n\n", Element.ALIGN_LEFT, Font.NORMAL));
	}
	document.add(mct);
	document.close();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:30,代码来源:MultiColumnSimpleTest.java


注:本文中的com.lowagie.text.Document.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。