當前位置: 首頁>>代碼示例>>Java>>正文


Java PdfWriter.close方法代碼示例

本文整理匯總了Java中com.itextpdf.text.pdf.PdfWriter.close方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfWriter.close方法的具體用法?Java PdfWriter.close怎麽用?Java PdfWriter.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.itextpdf.text.pdf.PdfWriter的用法示例。


在下文中一共展示了PdfWriter.close方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: closePassedStream

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
/**
 * The <code>closePassedStream</code> method closes the stream passed.
 * 
 * @param reader {@link PdfReader}
 * @param document {@link Document}
 * @param contentByte {@link PdfContentByte}
 * @param writer {@link PdfWriter}
 * @param fileInputStream {@link FileInputStream}
 * @param fileOutputStream {@link FileOutputStream}
 * @throws IOException {@link} if unable to close input or output stream
 */
private static void closePassedStream(final PdfReader reader, final Document document,
		final PdfContentByte contentByte, final PdfWriter writer,
		final FileInputStream fileInputStream, final FileOutputStream fileOutputStream) throws IOException {
	if (null != reader) {
		reader.close();
	} 
	if (null != document) {
		document.close();
	}
	if (null != contentByte) {
		contentByte.closePath();
	}
	if (null != writer) {
		writer.close();
	}
	if (null != fileInputStream) {
		fileInputStream.close();
	}
	
	if (null != fileOutputStream) {
		fileOutputStream.flush();
		fileOutputStream.close();
	}
}
 
開發者ID:kuzavas,項目名稱:ephesoft,代碼行數:36,代碼來源:PDFUtil.java

示例2: image2pdf

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
/**
 * 將圖片轉換為 PDF.
 *
 * @param image
 * @param pageSize     supported type will be found in com.itextpdf.text.PageSize,
 *                     like A2, A3, A4, LETTER_LANDSCAPE etc.
 * @param marginLeft   0f
 * @param marginRight  0f
 * @param marginTop    0f
 * @param marginBottom 0f
 * @return PDF格式的 byte[]
 */
public static byte[] image2pdf(byte[] image, Rectangle pageSize, Float marginLeft, Float marginRight,
                               Float marginTop, Float marginBottom) {

    Document document = new Document(pageSize == null ? PageSize.A4 : pageSize,
            marginLeft == null ? 0f : marginLeft, marginRight == null ? 0f : marginRight,
            marginTop == null ? 0f : marginTop, marginBottom == null ? 0f : marginBottom);
    PdfWriter pdfWriter;
    try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
        pdfWriter = PdfWriter.getInstance(document, byteArrayOutputStream);
        document.open();
        document.add(Image.getInstance(image, true));
        // need close document and pdfWriter before convert byte array!
        document.close();
        pdfWriter.close();
        return byteArrayOutputStream.toByteArray();
    } catch (DocumentException | IOException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:asdf2014,項目名稱:yuzhouwan,代碼行數:32,代碼來源:HtmlExporterUtils.java

示例3: createPdf

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
private String createPdf(Context context) throws Exception {
	BscReportPropertyUtils.loadData();
	String visionOid = (String)context.get("visionOid");
	VisionVO vision = null;
	BscStructTreeObj treeObj = (BscStructTreeObj)this.getResult(context);
	for (VisionVO visionObj : treeObj.getVisions()) {
		if (visionObj.getOid().equals(visionOid)) {
			vision = visionObj;
		}
	}		
	FontFactory.register(BscConstants.PDF_ITEXT_FONT);
	String fileName = SimpleUtils.getUUIDStr() + ".pdf";
	String fileFullPath = Constants.getWorkTmpDir() + "/" + fileName;
	OutputStream os = new FileOutputStream(fileFullPath);
	Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);	
	document.left(100f);
	document.top(150f);
	PdfWriter writer = PdfWriter.getInstance(document, os);
	document.open();  
	
	PdfPTable table = new PdfPTable(MAX_COLSPAN);
	table.setWidthPercentage(100f);	
	PdfPTable signTable = new PdfPTable( 1 );
	signTable.setWidthPercentage(100f);		
	
	this.createHead(table, vision, context);
	this.createBody(table, vision);
	
	this.putSignature(signTable, context);		
	
	document.add(table); 
	document.add(signTable);
	document.close();
	writer.close();			
	
	os.flush();
	os.close();
	os = null;
	
	File file = new File(fileFullPath);
	String oid = UploadSupportUtils.create(
			Constants.getSystem(), UploadTypes.IS_TEMP, false, file, "department-report.pdf");
	file = null;
	return oid;		
}
 
開發者ID:billchen198318,項目名稱:bamboobsc,代碼行數:46,代碼來源:OrganizationReportPdfCommand.java

示例4: main

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
public static void main(String[] args) throws FileNotFoundException, DocumentException {
	Document document = new Document();
	PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST));
	document.open();
	document.add(new Paragraph("hello world"));
	document.close();
	writer.close();
}
 
開發者ID:Sunny0715,項目名稱:java_pdf_demo,代碼行數:9,代碼來源:JavaToPdf.java

示例5: main

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
public static void main(String[] args) throws FileNotFoundException, DocumentException {
	Document document = new Document();
	PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST));
	document.open();
	Font font = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
	document.add(new Paragraph("hello world,我是rainbowhorse。", font));
	document.close();
	writer.close();
}
 
開發者ID:Sunny0715,項目名稱:java_pdf_demo,代碼行數:10,代碼來源:JavaToPdfCN.java

示例6: save

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
public static final void save(File file, Component c, int width, int height) {
	if (file == null) {
		logger.log(Level.WARNING, "no file selected");
		return;
	}
	if (c == null) {
		logger.log(Level.WARNING, "no component provided");
		return;
	}
	try {
		Document document = new Document(new Rectangle(width, height));
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file.getAbsolutePath()));
		document.addAuthor("UJMP v" + UJMP.UJMPVERSION);
		document.open();
		PdfContentByte cb = writer.getDirectContent();
		PdfTemplate tp = cb.createTemplate(width, height);
		Graphics2D g2 = new PdfGraphics2D(cb, width, height, new DefaultFontMapper());
		if (c instanceof CanRenderGraph) {
			((CanRenderGraph) c).renderGraph(g2);
		} else {
			c.paint(g2);
		}
		g2.dispose();
		cb.addTemplate(tp, 0, 0);
		document.close();
		writer.close();
	} catch (Exception e) {
		logger.log(Level.WARNING, "could not save PDF file", e);
	}
}
 
開發者ID:ujmp,項目名稱:universal-java-matrix-package,代碼行數:31,代碼來源:ExportPDF.java

示例7: createPdf

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
private String createPdf(Context context) throws Exception {
	BscReportPropertyUtils.loadData();
	String visionOid = (String)context.get("visionOid");
	VisionVO vision = null;
	BscStructTreeObj treeObj = (BscStructTreeObj)this.getResult(context);
	for (VisionVO visionObj : treeObj.getVisions()) {
		if (visionObj.getOid().equals(visionOid)) {
			vision = visionObj;
		}
	}		
	FontFactory.register(BscConstants.PDF_ITEXT_FONT);
	String fileName = SimpleUtils.getUUIDStr() + ".pdf";
	String fileFullPath = Constants.getWorkTmpDir() + "/" + fileName;
	OutputStream os = new FileOutputStream(fileFullPath);
	Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);	
	document.left(100f);
	document.top(150f);
	PdfWriter writer = PdfWriter.getInstance(document, os);
	document.open();  
	
	PdfPTable table = new PdfPTable(MAX_COLSPAN);
	table.setWidthPercentage(100f);	
	PdfPTable signTable = new PdfPTable( 1 );
	signTable.setWidthPercentage(100f);
	
	this.createHead(table, vision, context);
	this.createBody(table, vision);
	this.createFoot(table, context);
	this.putSignature(signTable, context);
	
	document.add(table);
	document.add(signTable);
	document.close();
	writer.close();			
	
	os.flush();
	os.close();
	os = null;
	
	File file = new File(fileFullPath);
	String oid = UploadSupportUtils.create(
			Constants.getSystem(), UploadTypes.IS_TEMP, false, file, "personal-report.pdf");
	file = null;
	return oid;
}
 
開發者ID:billchen198318,項目名稱:bamboobsc,代碼行數:46,代碼來源:PersonalReportPdfCommand.java

示例8: createPdf

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
private String createPdf(Context context) throws Exception {
	BscReportPropertyUtils.loadData();
	BscReportSupportUtils.loadExpression(); // 2015-04-18 add
	String visionOid = (String)context.get("visionOid");
	VisionVO vision = null;
	BscStructTreeObj treeObj = (BscStructTreeObj)this.getResult(context);
	for (VisionVO visionObj : treeObj.getVisions()) {
		if (visionObj.getOid().equals(visionOid)) {
			vision = visionObj;
		}
	}		
	FontFactory.register(BscConstants.PDF_ITEXT_FONT);
	String fileName = SimpleUtils.getUUIDStr() + ".pdf";
	String fileFullPath = Constants.getWorkTmpDir() + "/" + fileName;
	OutputStream os = new FileOutputStream(fileFullPath);
	//Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
	Document document = new Document(PageSize.A4, 10, 10, 10, 10);		
	document.left(100f);
	document.top(150f);
	PdfWriter writer = PdfWriter.getInstance(document, os);
	document.open();  
	
	int dateRangeRows = 4 + vision.getPerspectives().get(0).getObjectives().get(0).getKpis().get(0).getDateRangeScores().size();
	PdfPTable table = new PdfPTable(MAX_COLSPAN);
	PdfPTable dateRangeTable = new PdfPTable( dateRangeRows );
	PdfPTable chartsTable = new PdfPTable( 2 );
	PdfPTable signTable = new PdfPTable( 1 );
	table.setWidthPercentage(100f);	
	dateRangeTable.setWidthPercentage(100f);
	chartsTable.setWidthPercentage(100f);
	signTable.setWidthPercentage(100f);
	
	this.createHead(table, vision);
	this.createBody(table, vision);
	this.createDateRange(dateRangeTable, vision, context, dateRangeRows);		
	this.putCharts(chartsTable, context);
	this.putSignature(signTable, context);
	
	document.add(chartsTable);
	document.add(table);  
	document.add(dateRangeTable);  
	document.add(signTable);
	document.close();
	writer.close();			
	
	os.flush();
	os.close();
	os = null;
	
	File file = new File(fileFullPath);
	String oid = UploadSupportUtils.create(
			Constants.getSystem(), UploadTypes.IS_TEMP, false, file, "kpi-report.pdf");
	file = null;
	return oid;
}
 
開發者ID:billchen198318,項目名稱:bamboobsc,代碼行數:56,代碼來源:KpiReportPdfCommand.java

示例9: GeneratePDF

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
public void GeneratePDF()
{
    Document document = new Document();
    try
    {
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("/sdcard/TutorialesHackro/hoja.pdf"));

        document.open();

        PdfPTable table = new PdfPTable(3); // 3 columns.
        table.setWidthPercentage(100); //Width 100%
        table.setSpacingBefore(10f); //Space before table
        table.setSpacingAfter(10f); //Space after table

        //Set Column widths
        float[] columnWidths = {1f, 1f, 1f};
        table.setWidths(columnWidths);

        PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1"));
        cell1.setBorderColor(BaseColor.BLUE);
        cell1.setPaddingLeft(10);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2"));
        cell2.setBorderColor(BaseColor.GREEN);
        cell2.setPaddingLeft(10);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3"));
        cell3.setBorderColor(BaseColor.RED);
        cell3.setPaddingLeft(10);
        cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);

        //To avoid having the cell border and the content overlap, if you are having thick cell borders
        //cell1.setUserBorderPadding(true);
        //cell2.setUserBorderPadding(true);
        //cell3.setUserBorderPadding(true);

        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);

        document.add(table);

        createDirectoryAndSaveFile(writer, "david");
        document.close();
        writer.close();
    } catch (Exception e)
    {
        e.printStackTrace();
        Log.e("ewdfhyfafedyatfawytedfytew b",e.getMessage());
    }

}
 
開發者ID:David-Hackro,項目名稱:ExamplesAndroid,代碼行數:58,代碼來源:Metodos.java


注:本文中的com.itextpdf.text.pdf.PdfWriter.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。