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


Java Document.close方法代码示例

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


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

示例1: createPDF

import com.itextpdf.text.Document; //导入方法依赖的package包/类
public void createPDF(String outputFile, ArrayList<Question> qlist, boolean showCorrectAnswer,
        PageCounter pagecounter, int maximumPageNumber, String inputFolder) throws DocumentException, IOException
{
    _inputFolder = inputFolder;
    Document document = new Document(PageSize.A4, 50, 50, 70, 50);
    PdfWriter pdfwriter = PdfWriter.getInstance(document, new FileOutputStream(outputFile));

    pdfwriter.setBoxSize("art", new Rectangle(36, 54, 559, 788));

    pdfwriter.setPageEvent(new HeaderFooter(maximumPageNumber));

    if (pagecounter != null)
    {
        pdfwriter.setPageEvent(pagecounter);
    }

    document.open();

    Paragraph p = new Paragraph();
    // p.setSpacingBefore(SPACING);
    p.setSpacingAfter(SPACING);
    p.setIndentationLeft(INDENTATION);

    writeQuestions(p, document, showCorrectAnswer, qlist);

    document.close();

}
 
开发者ID:wolfposd,项目名称:IMSQTI2PDF,代码行数:29,代码来源:PDFCreator.java

示例2: renderMergedOutputModel

import com.itextpdf.text.Document; //导入方法依赖的package包/类
@Override
protected void renderMergedOutputModel(Map<String, Object> model,
		HttpServletRequest request, HttpServletResponse response) throws Exception {
	// IE workaround: write into byte array first.
	ByteArrayOutputStream baos = createTemporaryOutputStream();

	// Apply preferences and build metadata.
	Document document = newDocument();
	PdfWriter writer = newWriter(document, baos);
	prepareWriter(model, writer, request);
	buildPdfMetadata(model, document, request);

	// Build PDF document.
	document.open();
	buildPdfDocument(model, document, writer, request, response);
	document.close();

	// Flush to HTTP response.
	writeToResponse(response, baos);
}
 
开发者ID:okfarm09,项目名称:JYLAND,代码行数:21,代码来源:AbstractITextPdfView.java

示例3: print

import com.itextpdf.text.Document; //导入方法依赖的package包/类
public void print(String plot_pdf) {
	try {
		float width = jframe.getSize().width,
				height = jframe.getSize().height;
		Document document = new Document(new Rectangle(width, height));
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(plot_pdf));
		document.open();
		PdfContentByte canvas = writer.getDirectContent();
		PdfTemplate template = canvas.createTemplate(width, height);
		Graphics2D g2d = new PdfGraphics2D(template, width, height);
		jframe.paint(g2d);
		g2d.dispose();
		canvas.addTemplate(template, 0, 0);
		document.close();
	} catch (FileNotFoundException | DocumentException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:c-zhou,项目名称:polyGembler,代码行数:20,代码来源:JfreeChart.java

示例4: writeSimplePdf

import com.itextpdf.text.Document; //导入方法依赖的package包/类
public static void writeSimplePdf() throws Exception{
			//1.新建document对象
			//第一个参数是页面大小。接下来的参数分别是左、右、上和下页边距。
			Document document = new Document(PageSize.A4, 50, 50, 50, 50);
			//2.建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中。
			//创建 PdfWriter 对象 第一个参数是对文档对象的引用,第二个参数是文件的实际名称,在该名称中还会给出其输出路径。
			PdfWriter writer = PdfWriter.getInstance(document, 	new FileOutputStream("D:\\Documents\\ITextTest.pdf"));
			//3.打开文档
			document.open();		
			//4.向文档中添加内容
			//通过 com.lowagie.text.Paragraph 来添加文本。可以用文本及其默认的字体、颜色、大小等等设置来创建一个默认段落
			BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
			Font fontChinese = new Font(bfChinese, 22, Font.BOLD, BaseColor.BLACK);
			
			document.add(new Paragraph("sdfsdfsd全是中文显示了没.fsdfsfs",fontChinese));
			document.add(new Paragraph("Some more text on the 	first page with different color and font type.",
					FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new BaseColor(255, 150, 200))));
			Paragraph pragraph=new Paragraph("你这里有中亠好", fontChinese);
			document.add(pragraph);
			
			//图像支持格式 GIF, Jpeg, PNG, wmf
			Image gif = Image.getInstance("F:/keyworkspace/survey/WebRoot/images/logo/snlogo.png");
			gif.setBorder(5);
			gif.scaleAbsolute(30,30);
			gif.setAlignment(Image.RIGHT|Image.TEXTWRAP);
			document.add(gif);
			Paragraph pragraph11=new Paragraph("你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好", fontChinese);
			document.add(pragraph11);
			
			Image gif15 = Image.getInstance("F:/keyworkspace/survey/WebRoot/images/logo/snlogo.png");
//			gif15.setBorder(50);
			gif15.setBorder(Image.BOX);
			gif15.setBorderColor(BaseColor.RED);
//			gif15.setBorderColorBottom(borderColorBottom)
			gif15.setBorderWidth(1);
			gif15.scalePercent(50);
			document.add(gif15);
			//5.关闭文档
			document.close();
		}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:41,代码来源:ItextpdfTest.java

示例5: renderMergedOutputModel

import com.itextpdf.text.Document; //导入方法依赖的package包/类
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception  {
	// IE workaround: write into byte array first.
			ByteArrayOutputStream baos = createTemporaryOutputStream();

			// Apply preferences and build metadata.
			Document document = new Document();
			PdfWriter writer = PdfWriter.getInstance(document, baos);
			prepareWriter(model, writer, request);
			buildPdfMetadata(model, document, request);

			// Build PDF document.
			writer.setInitialLeading(16);
			document.open();
			buildPdfDocument(model, document, writer, request, response);
			document.close();

			// Flush to HTTP response.
			writeToResponse(response, baos);

	
}
 
开发者ID:PacktPublishing,项目名称:Spring-MVC-Blueprints,代码行数:23,代码来源:AbstractPdfView.java

示例6: renderMergedOutputModel

import com.itextpdf.text.Document; //导入方法依赖的package包/类
@Override
protected void renderMergedOutputModel(Map<String, Object> model,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    // IE workaround: write into byte array first.
    ByteArrayOutputStream baos = createTemporaryOutputStream();
 
    // Apply preferences and build metadata.
    Document document = newDocument();
    PdfWriter writer = newWriter(document, baos);
    prepareWriter(model, writer, request);
    buildPdfMetadata(model, document, request);
 
    // Build PDF document.
    document.open();
    buildPdfDocument(model, document, writer, request, response);
    document.close();
 
    // Flush to HTTP response.
    writeToResponse(response, baos);
}
 
开发者ID:PacktPublishing,项目名称:Spring-MVC-Blueprints,代码行数:21,代码来源:HRPDFBuilder.java

示例7: closePassedStream

import com.itextpdf.text.Document; //导入方法依赖的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

示例8: testDoubleSpace

import com.itextpdf.text.Document; //导入方法依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/35699167/double-space-not-being-preserved-in-pdf">
 * Double space not being preserved in PDF
 * </a>
 * <p>
 * Indeed, the double space collapses into a single one when copying&pasting from the
 * generated PDF displayed in Adobe Reader. On the other hand the gap for the double
 * space is twice as wide as for the single space. So this essentially is a quirk of
 * copy&paste of Adobe Reader (and some other PDF viewers, too).
 * </p>
 */
@Test
public void testDoubleSpace() throws DocumentException, IOException
{
    try (   OutputStream pdfStream = new FileOutputStream(new File(RESULT_FOLDER, "DoubleSpace.pdf")))
    {
        PdfPTable table = new PdfPTable(1);
        table.getDefaultCell().setBorderWidth(0.5f);
        table.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY);

        table.addCell(new Phrase("SINGLE SPACED", new Font(BaseFont.createFont(), 36)));
        table.addCell(new Phrase("DOUBLE  SPACED", new Font(BaseFont.createFont(), 36)));
        table.addCell(new Phrase("TRIPLE   SPACED", new Font(BaseFont.createFont(), 36)));

        Document pdfDocument = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
        PdfWriter.getInstance(pdfDocument, pdfStream);
        pdfDocument.open();
        pdfDocument.add(table);
        pdfDocument.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:32,代码来源:DoubleSpace.java

示例9: copyToMultiplePages

import com.itextpdf.text.Document; //导入方法依赖的package包/类
private static File copyToMultiplePages(CropJob cropJob) throws IOException, DocumentException {

		PdfReader reader = new PdfReader(cropJob.getSource().getAbsolutePath());
		Document document = new Document();

		File resultFile = File.createTempFile("cropped", ".pdf");
		PdfSmartCopy pdfCopy = new PdfSmartCopy(document, new FileOutputStream(resultFile));
		document.open();
		PdfImportedPage page;

		for (int pageNumber = 1; pageNumber <= cropJob.getSourcePageCount(); pageNumber++) {
			SingleCluster currentCluster = cropJob.getClusterCollection().getSingleCluster(pageNumber);
			page = pdfCopy.getImportedPage(reader, pageNumber);
			pdfCopy.addPage(page);
			for (int j = 1; j < currentCluster.getRatiosList().size(); j++) {
				pdfCopy.addPage(page);
			}
		}
		document.close();
		pdfCopy.close();
		reader.close();
		return resultFile;
	}
 
开发者ID:mbaeuerle,项目名称:Briss-2.0,代码行数:24,代码来源:CropManager.java

示例10: testRowspanWithHeaderRows

import com.itextpdf.text.Document; //导入方法依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/40947306/strange-setrowspan-error-not-working">
 * Strange setRowspan error/not working
 * </a>
 * <p>
 * Selecting 1 header row and having a cell in the first row which spans 2 rows
 * does not match. iText ignores the row span resulting in the weird appearance.
 * </p>
 */
@Test
public void testRowspanWithHeaderRows() throws IOException, DocumentException
{
    File file = new File(RESULT_FOLDER, "rowspanWithHeaderRows.pdf");
    OutputStream os = new FileOutputStream(file);

    Document document = new Document();
    /*PdfWriter writer =*/ PdfWriter.getInstance(document, os);
    document.open();

    document.add(createHeaderContent());
    document.newPage();
    document.add(createHeaderContent(new int[] {5,5,5,5,5}));

    document.close();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:26,代码来源:TableWithSpan.java

示例11: exportInnertion

import com.itextpdf.text.Document; //导入方法依赖的package包/类
/**
 * 
 */
@Override
public void exportInnertion(OutputStream servletOut, List header, List data)
		throws IOException {
	// step 1
	Document document = new Document();
	// step 2
	PdfWriter writer;
	try {
		writer = PdfWriter.getInstance(document, servletOut);
	} catch (DocumentException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return;
	}
	// step 3
	document.open();
	// step 4
	XMLWorkerHelper.getInstance().parseXHtml(writer, document,
			new java.io.StringReader(
			HtmlExport.createHTML(header, data)));
	// step 5
	document.close();

}
 
开发者ID:fellyvon,项目名称:wasexport,代码行数:28,代码来源:PdfExport.java

示例12: renderGraph

import com.itextpdf.text.Document; //导入方法依赖的package包/类
@Override
public void renderGraph(JGraph<?> graph, File file) throws PortException {
    // Get graph bounds. If not available, do nothing (probably empty graph)
    Rectangle2D bounds = graph.getGraphBounds();
    if (bounds == null) {
        return;
    }
    Rectangle bound = new Rectangle((float) bounds.getWidth(), (float) bounds.getHeight());

    try (FileOutputStream fos = new FileOutputStream(file)) {
        Document document = new Document(bound);
        // Open file, create PDF document
        PdfWriter writer = PdfWriter.getInstance(document, fos);
        // Set some metadata
        document.addCreator(Version.getAbout());

        // Open document, get graphics
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        boolean onlyShapes = true;
        //The embedded fonts most likely do not contain all necessary glyphs, so using outlines instead
        // onlyShapes makes PDF considerably bigger, but no alternative at the moment
        PdfGraphics2D pdf2d =
            new PdfGraphics2D(cb, (float) bounds.getWidth(), (float) bounds.getHeight(),
                new DefaultFontMapper(), onlyShapes, false, (float) 100.0);

        // Render
        toGraphics(graph, pdf2d);

        // Cleanup
        pdf2d.dispose();
        document.close();
    } catch (DocumentException | IOException e) {
        throw new PortException(e);
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:37,代码来源:GraphToPDF.java

示例13: htmlToPdf

import com.itextpdf.text.Document; //导入方法依赖的package包/类
public void htmlToPdf(String htmlPath, File pdfFile) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
    document.open();
    XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream(htmlPath), Charset.forName("UTF-8"));
    document.close();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:8,代码来源:ExportUtilImpl.java

示例14: main

import com.itextpdf.text.Document; //导入方法依赖的package包/类
public static void main(String[] args) throws FileNotFoundException, DocumentException {
    Document d = new Document(PageSize.A4);
    FileOutputStream fos = new FileOutputStream("teste.pdf");
    
    PdfWriter.getInstance(d, fos);
    
    d.open();
    PdfPTable pTable = new PdfPTable(3);
    
        PdfPCell cell1 = new PdfPCell(new Phrase("111111111"));
        PdfPCell cell2 = new PdfPCell(new Phrase("222222222"));
        cell2.setRowspan(5);
        PdfPCell cell3 = new PdfPCell(new Phrase("333333333"));
        
        pTable.addCell(cell1); 
        pTable.addCell(cell2);
        pTable.addCell(cell3);
        
        pTable.addCell(cell1);
        pTable.addCell(cell3);
        pTable.addCell(cell1);
        pTable.addCell(cell3);
        
        pTable.addCell(cell1);
        pTable.addCell(cell3);
        pTable.addCell(cell1);
        pTable.addCell(cell3);
        
        pTable.addCell(cell1);
        pTable.addCell(cell3);
        pTable.addCell(cell1);
        pTable.addCell(cell3);
        
        
     
        d.add(pTable);

    d.close();
    
}
 
开发者ID:JIGAsoftSTP,项目名称:NICON,代码行数:41,代码来源:teste.java

示例15: main

import com.itextpdf.text.Document; //导入方法依赖的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


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