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


Java Document.close方法代码示例

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


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

示例1: exportVectorGraphics

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

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

示例4: 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

示例5: pdfTableForInstructionalOfferings

import com.lowagie.text.Document; //导入方法依赖的package包/类
public void pdfTableForInstructionalOfferings(
  		OutputStream out,
          ClassAssignmentProxy classAssignment,
          ExamAssignmentProxy examAssignment,
          InstructionalOfferingListForm form, 
          String[] subjectAreaIds, 
          SessionContext context,
          boolean displayHeader,
          boolean allCoursesAreGiven) throws Exception{
  	
  	setVisibleColumns(form);
  	
  	iDocument = new Document(PageSize.A4, 30f, 30f, 30f, 30f); 
iWriter = PdfEventHandler.initFooter(iDocument, out);

  	for (String subjectAreaId: subjectAreaIds) {
      	pdfTableForInstructionalOfferings(out, classAssignment, examAssignment,
      			form.getInstructionalOfferings(Long.valueOf(subjectAreaId)), 
      			Long.valueOf(subjectAreaId),
      			context,
      			displayHeader, allCoursesAreGiven,
      			new ClassCourseComparator(form.getSortBy(), classAssignment, false));
  	}
 	
iDocument.close();
  }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:27,代码来源:PdfInstructionalOfferingTableBuilder.java

示例6: createTempFile

import com.lowagie.text.Document; //导入方法依赖的package包/类
private void createTempFile(String filename, String[] pageContents) throws Exception{
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(filename));
    document.open();
    
    for (int i = 0; i < pageContents.length; i++) {
        if (i != 0)
            document.newPage();

        String content = pageContents[i];
        Chunk contentChunk = new Chunk(content);
        document.add(contentChunk);
    }
    
    
    document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:18,代码来源:TestPdfCopyAndStamp.java

示例7: 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

示例8: renderMergedOutputModel

import com.lowagie.text.Document; //导入方法依赖的package包/类
@Override
protected final 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:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:AbstractPdfView.java

示例9: pdfTableForInstructionalOffering

import com.lowagie.text.Document; //导入方法依赖的package包/类
public void pdfTableForInstructionalOffering(
 		OutputStream out,
 		ClassAssignmentProxy classAssignment, 
 		ExamAssignmentProxy examAssignment,
         Long instructionalOfferingId, 
         SessionContext context,
         Comparator classComparator) throws Exception{
 	
 	if (instructionalOfferingId != null && context != null){
      InstructionalOfferingDAO idao = new InstructionalOfferingDAO();
      InstructionalOffering io = idao.get(instructionalOfferingId);
      Long subjectAreaId = io.getControllingCourseOffering().getSubjectArea().getUniqueId();
      
      // Get Configuration
      TreeSet ts = new TreeSet();
      ts.add(io);
      WebInstructionalOfferingTableBuilder iotbl = new WebInstructionalOfferingTableBuilder();
      iotbl.setDisplayDistributionPrefs(false);
      setVisibleColumns(COLUMNS);
      
  	iDocument = new Document(PageSize.A4, 30f, 30f, 30f, 30f); 
iWriter = PdfEventHandler.initFooter(iDocument, out);

   pdfTableForInstructionalOfferings(out,
	        classAssignment, examAssignment,
	        ts, subjectAreaId, context, false, false, classComparator);
   
   iDocument.close();
 	}
 }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:31,代码来源:PdfInstructionalOfferingTableBuilder.java

示例10: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * Special rendering of Chunks.
 * 
 */
@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("Rendering.pdf"));

	// step 3: we open the document
	document.open();
	// step 4:
	Paragraph p = new Paragraph("Text Rendering:");
	document.add(p);
	Chunk chunk = new Chunk("rendering test");
	chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL, 100f, new Color(0xFF, 0x00, 0x00));
	document.add(chunk);
	document.add(Chunk.NEWLINE);
	chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 0.3f, new Color(0xFF, 0x00, 0x00));
	document.add(chunk);
	document.add(Chunk.NEWLINE);
	chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE, 100f, new Color(0x00, 0xFF, 0x00));
	document.add(chunk);
	document.add(Chunk.NEWLINE);
	chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_STROKE, 0.3f, new Color(0x00, 0x00, 0xFF));
	document.add(chunk);
	document.add(Chunk.NEWLINE);
	Chunk bold = new Chunk("This looks like Font.BOLD");
	bold.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 0.5f, new Color(0x00, 0x00, 0x00));
	document.add(bold);

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

示例11: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
    * Draws some shapes.
    */
@Test
public void main() throws Exception {
       
       
       // step 1: creation of a document-object
       Document document = new Document();
       
       try {
           
           // 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( "shapes.pdf"));
           
           // step 3: we open the document
           document.open();
           
           // step 4: we grab the ContentByte and do some stuff with it
           PdfContentByte cb = writer.getDirectContent();
           
           // an example of a rectangle with a diagonal in very thick lines
           cb.setLineWidth(10f);
           // draw a rectangle
           cb.rectangle(100, 700, 100, 100);
           // add the diagonal
           cb.moveTo(100, 700);
           cb.lineTo(200, 800);
           // stroke the lines
           cb.stroke();
           
           // an example of some circles
           cb.setLineDash(3, 3, 0);
           cb.setRGBColorStrokeF(0f, 255f, 0f);
           cb.circle(150f, 500f, 100f);
           cb.stroke();
           
           cb.setLineWidth(5f);
           cb.resetRGBColorStroke();
           cb.circle(150f, 500f, 50f);
           cb.stroke();
           
           // example with colorfill
           cb.setRGBColorFillF(0f, 255f, 0f);
           cb.moveTo(100f, 200f);
           cb.lineTo(200f, 250f);
           cb.lineTo(400f, 150f);
           // because we change the fill color BEFORE we stroke the triangle
           // the color of the triangle will be red instead of green
           cb.setRGBColorFillF(255f, 0f, 0f);
           cb.closePathFillStroke();
           
           cb.sanityCheck();
       }
       catch(DocumentException de) {
           System.err.println(de.getMessage());
       }
       catch(IOException ioe) {
           System.err.println(ioe.getMessage());
       }
       
       // step 5: we close the document
       document.close();
   }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:67,代码来源:ShapesTest.java

示例12: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * Combines 2 tiff-files into 1 PDF (similar to tiffmesh).
 * 
 * @param args
 *            [0] the file with the odd pages [1] the file with the even
 *            pages [2] the resulting file
 */
public void main(String... args) throws Exception {
	if (args.length < 3) {
		System.err.println("OddEven needs 3 Arguments.");
		System.out
				.println("Usage: com.lowagie.examples.objects.images.tiff.OddEven odd_file.tif even_file.tif combined_file.pdf");
		return;
	}
	RandomAccessFileOrArray odd = new RandomAccessFileOrArray(args[0]);
	RandomAccessFileOrArray even = new RandomAccessFileOrArray(args[1]);
	Image img = TiffImage.getTiffImage(odd, 1);
	Document document = new Document(new Rectangle(img.getScaledWidth(), img.getScaledHeight()));
	PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(args[2]));
	document.open();
	PdfContentByte cb = writer.getDirectContent();
	int count = Math.max(TiffImage.getNumberOfPages(odd), TiffImage.getNumberOfPages(even));
	for (int c = 0; c < count; ++c) {

		Image imgOdd = TiffImage.getTiffImage(odd, c + 1);
		Image imgEven = TiffImage.getTiffImage(even, count - c);
		document.setPageSize(new Rectangle(imgOdd.getScaledWidth(), imgOdd.getScaledHeight()));
		document.newPage();
		imgOdd.setAbsolutePosition(0, 0);
		cb.addImage(imgOdd);
		document.setPageSize(new Rectangle(imgEven.getScaledWidth(), imgEven.getScaledHeight()));
		document.newPage();
		imgEven.setAbsolutePosition(0, 0);
		cb.addImage(imgEven);

	}
	odd.close();
	even.close();
	document.close();

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

示例13: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
    * Layer radio group and zoom.
    */
@Test
public void main() throws Exception {
       	// step 1
           Document document = new Document(PageSize.A4, 50, 50, 50, 50);
           // step 2
           PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "layers.pdf"));
           writer.setPdfVersion(PdfWriter.VERSION_1_5);
           writer.setViewerPreferences(PdfWriter.PageModeUseOC);
           // step 3
           document.open();
           // step 4
           PdfContentByte cb = writer.getDirectContent();
           Phrase explanation = new Phrase("Layer radio group and zoom", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red));
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0);
           PdfLayer title = PdfLayer.createTitle("Layer radio group", writer);
           PdfLayer l1 = new PdfLayer("Layer 1", writer);
           PdfLayer l2 = new PdfLayer("Layer 2", writer);
           PdfLayer l3 = new PdfLayer("Layer 3", writer);
           PdfLayer l4 = new PdfLayer("Layer 4", writer);
           title.addChild(l1);
           title.addChild(l2);
           title.addChild(l3);
           l4.setZoom(2, -1);
           l4.setOnPanel(false);
           l4.setPrint("Print", true);
           l2.setOn(false);
           l3.setOn(false);
           ArrayList<PdfLayer> radio = new ArrayList<PdfLayer>();
           radio.add(l1);
           radio.add(l2);
           radio.add(l3);
           writer.addOCGRadioGroup(radio);
           Phrase p1 = new Phrase("Text in layer 1");
           Phrase p2 = new Phrase("Text in layer 2");
           Phrase p3 = new Phrase("Text in layer 3");
           Phrase p4 = new Phrase("Text in layer 4");
           cb.beginLayer(l1);
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
           cb.endLayer();
           cb.beginLayer(l2);
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
           cb.endLayer();
           cb.beginLayer(l3);
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
           cb.endLayer();
           cb.beginLayer(l4);
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p4, 50, 450, 0);
           cb.endLayer();
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("<< Zoom here!", new Font(Font.COURIER, 12, Font.NORMAL, Color.blue)), 150, 450, 0);
           // step 5
           document.close();

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

示例14: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * Generates a PDF file with metadata
 * 
 */
@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
	HtmlWriter.getInstance(document, PdfTestBase.getOutputStream("HelloWorldMeta.html"));

	// step 3: we add some metadata open the document
	// standard meta information
	document.addTitle("Hello World example");
	document.addAuthor("Bruno Lowagie");
	document.addSubject("This example explains step 3 in Chapter 1");
	document.addKeywords("Metadata, iText, step 3, tutorial");
	// custom (HTML) meta information
	document.addHeader("Expires", "0");
	// meta information that will be in a comment section in HTML
	document.addCreator("My program using iText");
	document.open();
	// step 4: we add a paragraph to the document
	document.add(new Paragraph("Hello World"));

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

示例15: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * Creates a document with chained Actions.
 * 
 */
@Test
public void main() throws Exception {

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

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("ChainedActions.pdf"));
	// step 3: we add Javascript as Metadata and we open the document
	document.open();
	// step 4: we add some content
	PdfAction action = PdfAction.javaScript("app.alert('Welcome at my site');\r", writer);
	action.next(new PdfAction("http://www.lowagie.com/iText/"));
	Paragraph p = new Paragraph(new Chunk("Click to go to Bruno's site").setAction(action));
	document.add(p);

	// step 5: we close the document
	document.close();

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


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