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


Java PdfWriter类代码示例

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


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

示例1: exportVectorGraphics

import com.lowagie.text.pdf.PdfWriter; //导入依赖的package包/类
private void exportVectorGraphics(String formatName, File outputFile) throws ImageExportException {
	Component component = printableComponent.getExportComponent();
	int width = component.getWidth();
	int height = component.getHeight();
	try (FileOutputStream fs = new FileOutputStream(outputFile)) {
		switch (formatName) {
			case PDF:
				// create pdf document with slightly increased width and height
				// (otherwise the image gets cut off)
				Document document = new Document(new Rectangle(width + 5, height + 5));
				PdfWriter writer = PdfWriter.getInstance(document, fs);
				document.open();
				PdfContentByte cb = writer.getDirectContent();
				PdfTemplate tp = cb.createTemplate(width, height);
				Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper());
				component.print(g2);
				g2.dispose();
				cb.addTemplate(tp, 0, 0);
				document.close();
				break;
			case SVG:
				exportFreeHep(component, fs, new SVGGraphics2D(fs, new Dimension(width, height)));
				break;
			case EPS:
				exportFreeHep(component, fs, new PSGraphics2D(fs, new Dimension(width, height)));
				break;
			default:
				// cannot happen
				break;
		}
	} catch (Exception e) {
		throw new ImageExportException(I18N.getMessage(I18N.getUserErrorMessagesBundle(),
				"error.image_export.export_failed"), e);
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:36,代码来源:ImageExporter.java

示例2: html2pdf

import com.lowagie.text.pdf.PdfWriter; //导入依赖的package包/类
/**
 * Convert HTML to PDF
 */
public void html2pdf(File input, File output) throws ConversionException, DatabaseException, IOException {
	log.debug("** Convert from HTML to PDF **");
	FileOutputStream fos = null;

	try {
		fos = new FileOutputStream(output);

		// Make conversion
		Document doc = new Document(PageSize.A4);
		PdfWriter.getInstance(doc, fos);
		doc.open();
		HTMLWorker html = new HTMLWorker(doc);
		html.parse(new FileReader(input));
		doc.close();
	} catch (DocumentException e) {
		throw new ConversionException("Exception in conversion: " + e.getMessage(), e);
	} finally {
		IOUtils.closeQuietly(fos);
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:24,代码来源:DocConverter.java

示例3: close

import com.lowagie.text.pdf.PdfWriter; //导入依赖的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

示例4: onEndPage

import com.lowagie.text.pdf.PdfWriter; //导入依赖的package包/类
/**
 * After the content of the page is written, we put page X of Y at the
 * bottom of the page and we add either "Romeo and Juliet" of the title
 * of the current act as a header.
 * 
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter,
 *      com.lowagie.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
	int pageN = writer.getPageNumber();
	String text = "Page " + pageN + " of ";
	float len = bf.getWidthPoint(text, 8);
	cb.beginText();
	cb.setFontAndSize(bf, 8);
	cb.setTextMatrix(280, 30);
	cb.showText(text);
	cb.endText();
	cb.addTemplate(template, 280 + len, 30);
	cb.beginText();
	cb.setFontAndSize(bf, 8);
	cb.setTextMatrix(280, 820);
	if (pageN % 2 == 1) {
		cb.showText("Romeo and Juliet");
	} else {
		cb.showText(act);
	}
	cb.endText();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:29,代码来源:EventsTest.java

示例5: main

import com.lowagie.text.pdf.PdfWriter; //导入依赖的package包/类
/**
 * Demonstrates the alignment method.
 */
@Test
public void main() throws Exception {
	// step 1: creation of a document-object
	Document document = new Document();
	// step 2: creation of a writer
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("alignment.pdf"));

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

	Image gif = Image.getInstance(PdfTestBase.RESOURCES_DIR + "vonnegut.gif");
	gif.setAlignment(Image.RIGHT);
	Image jpeg = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
	jpeg.setAlignment(Image.MIDDLE);
	Image png = Image.getInstance(PdfTestBase.RESOURCES_DIR + "hitchcock.png");
	png.setAlignment(Image.LEFT);

	document.add(gif);
	document.add(jpeg);
	document.add(png);

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

示例6: createDocument

import com.lowagie.text.pdf.PdfWriter; //导入依赖的package包/类
@Override
public void createDocument(String documentName, String content) throws CitizenException {
	String realPath = FILE_PATH + documentName + ".pdf";
	Document doc = new Document();
	try {
		PdfWriter.getInstance(doc, new FileOutputStream(realPath));
		doc.open();
		addMetaData(doc);
		addTitlePage(doc);
		addContent(doc, content);
	} catch (DocumentException | FileNotFoundException e) {
		throw new CitizenException("Error al generar documento pdf" +
				" ["+ FILE_PATH+documentName+".pdf] | ["+this.getClass().getName()+"]");
	} finally {
		if (doc != null) {
			doc.close();
		}
	}

}
 
开发者ID:Arquisoft,项目名称:citizensLoader4a,代码行数:21,代码来源:PDFTextWritter.java

示例7: convertWriteToPdf

import com.lowagie.text.pdf.PdfWriter; //导入依赖的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

示例8: open

import com.lowagie.text.pdf.PdfWriter; //导入依赖的package包/类
public void open(OutputStream out, int mode) throws DocumentException, IOException {
    iOut = out;
    if (mode==sModeText) {
        iPrint = new PrintWriter(iOut);
    } else {
        iNrLines = (mode==sModeLedger?116:50);
        iDoc = new Document(mode==sModeLedger?PageSize.LEDGER.rotate():PageSize.LETTER.rotate());

        PdfWriter.getInstance(iDoc, iOut);

        iDoc.addTitle(iTitle);
        iDoc.addAuthor("UniTime "+Constants.getVersion()+", www.unitime.org");
        iDoc.addSubject(iSubject);
        iDoc.addCreator("UniTime "+Constants.getVersion()+", www.unitime.org");

        iDoc.open();
    }
    iEmpty = true;
    iPageNo = 0; iLineNo = 0;
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:21,代码来源:PdfLegacyReport.java

示例9: onEndPage

import com.lowagie.text.pdf.PdfWriter; //导入依赖的package包/类
/**
   * Print footer string on each page
   * @param writer
   * @param document
   */
  public void onEndPage(PdfWriter writer, Document document) {
   
  	if(getDateTime() == null) {
  		setDateTime(new Date());
  	}
  	
PdfContentByte cb = writer.getDirectContent();
cb.beginText();
cb.setFontAndSize(getBaseFont(), getFontSize());
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, getDateFormat().format(getDateTime()), 
	    document.left(), 20, 0);
cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, String.valueOf(document.getPageNumber()), 
	    document.right(), 20, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, MESSAGES.pdfCopyright(Constants.getVersion()),
		(document.left() + document.right()) / 2, 20, 0);
cb.endText();
	
      return;
  }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:25,代码来源:PdfEventHandler.java

示例10: buildPdfDocument

import com.lowagie.text.pdf.PdfWriter; //导入依赖的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

示例11: downloadPdfFile

import com.lowagie.text.pdf.PdfWriter; //导入依赖的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

示例12: getVersionAsName

import com.lowagie.text.pdf.PdfWriter; //导入依赖的package包/类
/**
 * Returns the PDF version as a name.
 * @param version	the version character.
 */
public PdfName getVersionAsName(char version) {
	switch(version) {
	case PdfWriter.VERSION_1_2:
		return PdfWriter.PDF_VERSION_1_2;
	case PdfWriter.VERSION_1_3:
		return PdfWriter.PDF_VERSION_1_3;
	case PdfWriter.VERSION_1_4:
		return PdfWriter.PDF_VERSION_1_4;
	case PdfWriter.VERSION_1_5:
		return PdfWriter.PDF_VERSION_1_5;
	case PdfWriter.VERSION_1_6:
		return PdfWriter.PDF_VERSION_1_6;
	case PdfWriter.VERSION_1_7:
		return PdfWriter.PDF_VERSION_1_7;
	default:
		return PdfWriter.PDF_VERSION_1_4;
	}
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:23,代码来源:PdfVersionImp.java

示例13: main

import com.lowagie.text.pdf.PdfWriter; //导入依赖的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

示例14: openDocument

import com.lowagie.text.pdf.PdfWriter; //导入依赖的package包/类
/**
 * Creates a document.
 *
 * @param outputStream The output stream to write the document content.
 * @param pageSize     the page size.
 * @return A Document.
 */
public static Document openDocument( OutputStream outputStream, Rectangle pageSize )
{
    try
    {
        Document document = new Document( pageSize );

        PdfWriter.getInstance( document, outputStream );

        document.open();

        return document;
    }
    catch ( DocumentException ex )
    {
        throw new RuntimeException( "Failed to open PDF document", ex );
    }
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:25,代码来源:PDFUtils.java

示例15: onEndPage

import com.lowagie.text.pdf.PdfWriter; //导入依赖的package包/类
public void onEndPage( PdfWriter writer, Document document ) {
    //Footer contains page numbers and date printed on all pages
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();

    String strFooter = promoTxt + " " + formatter.format(now);

    float textBase = document.bottom();
    cb.beginText();
    cb.setFontAndSize(font.getBaseFont(),FONTSIZE);
    Rectangle page = document.getPageSize();
    float width = page.getWidth();

    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase - 20, 0);

    strFooter = "-" + writer.getPageNumber() + "-";
    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase-10, 0);

    cb.endText();
    cb.restoreState();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:22,代码来源:OscarChartPrinter.java


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