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


Java PdfWriter.getInstance方法代碼示例

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


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

示例1: createDocument

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
public boolean createDocument(String path) {
    try {
        Start.getScene().setCursor(Cursor.WAIT);
        Document document = new Document(PageSize.A4);
        PdfWriter.getInstance(document, new FileOutputStream(path + CommonUtils.DELIMITER + "Resume candidates list. Created by RecruiterVision [" + dateFormat.format(new Date()) + "].pdf"));
        document.open();
        addMetaData(document);
        addContent(document);
        document.close();
        logger.info("Data saved to candidates list file");
        Start.getScene().setCursor(Cursor.DEFAULT);
        return true;
    } catch (DocumentException | IOException e) {
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:victorward,項目名稱:recruitervision,代碼行數:18,代碼來源:PDFCreator.java

示例2: createPDF

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的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

示例3: print

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的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.pdf.PdfWriter; //導入方法依賴的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.pdf.PdfWriter; //導入方法依賴的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: createDocument

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
public Document createDocument(File pdfFile) throws DocumentException, IOException{
		Document document = new Document(new Rectangle(pageWidth, pageHeight));
		document.setPageSize(PageSize.A4);
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
		//寫入頁尾
		this.setFooter(writer); 
		writer.setFullCompression();
		writer.setPdfVersion(PdfWriter.VERSION_1_4);
		document.open();	
//		//加入二維碼圖片
//		Image image = Image.getInstance(System.getProperty(appConfig.getValue("app.root"))+"/images/logoqrcode.png");
//        image.scaleAbsolute(40,40);//控製圖片大小
//        image.setAlignment(Image.LEFT);
//        document.add(image);
        return document;
	}
 
開發者ID:simbest,項目名稱:simbest-cores,代碼行數:17,代碼來源:PdfBuilder.java

示例7: getPDF

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
public Document getPDF() throws Exception {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(FILE + problem.getPid() + ".pdf"));
    Image image = Image.getInstance(this.logo);
    document.open();
    document.add(image);
    document.addCreationDate();
    document.add(new Paragraph("Title: "+problem.getTitle()));
    document.add(new Paragraph("Code: "+problem.getPid()));
    document.add(new Paragraph(" "));
    document.add(addParagraph("Description",problem.getDescription(), true));
    document.add(addParagraph("Input",problem.getInput(), true));
    document.add(addParagraph("Output",problem.getOutput(), true));
    document.add(addParagraph("Input Example",problem.getInputex().replaceAll("<br/>", ""), true));
    document.add(addParagraph("Output Example",problem.getOutputex(), true));
    document.add(new Paragraph("Time(ms): "+problem.getTime()));
    document.add(new Paragraph("Memory(kb): "+problem.getMemory()));
    document.add(new Paragraph("Source(kb): "+problem.getFontsize()));
    document.addTitle("Challenger Online Judge");
    document.addAuthor("Chjudge");
    document.close();
    return document;
}
 
開發者ID:dovier,項目名稱:coj-web,代碼行數:24,代碼來源:PDFExportProblem.java

示例8: testAppendPDFs

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
/**
 * <a href="http://stackoverflow.com/questions/29001852/how-to-create-a-pdf-and-you-then-merge-another-pdf-to-the-same-document-using-it">
 * how to create a PDF and you then merge another pdf to the same document using itext
 * </a>
 * <p>
 * Testing the OP's method with <code>paginate</code> set to <code>false</code>
 * </p>
 */
@Test
public void testAppendPDFs() throws IOException, DocumentException
{
    try (
            InputStream testA4Stream = getClass().getResourceAsStream("testA4.pdf");
            InputStream fromStream = getClass().getResourceAsStream("from.pdf");
            InputStream prefaceStream = getClass().getResourceAsStream("preface.pdf");
            InputStream type3Stream = getClass().getResourceAsStream("Test_Type3_Problem.pdf");
            FileOutputStream output = new FileOutputStream(new File(RESULT_FOLDER, "appendPdfs.pdf"));
        )
    {
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, output);
        document.open();
        document.add(new Paragraph("Some content to start with"));
        appendPDFs(Arrays.asList(testA4Stream, fromStream, prefaceStream, type3Stream), writer, document, null, false);
        document.close();
    }
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:28,代碼來源:CreateAndAppendDoc.java

示例9: createSimpleCircleGraphicsPdf

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
/**
 * This method creates a PDF with a single styled paragraph.
 */
static byte[] createSimpleCircleGraphicsPdf() throws DocumentException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    document.open();

    float y = writer.getPageSize().getTop(document.topMargin());
    float radius = 20;
    for (int i = 0; i < 3; i++)
    {
        Rectangle pageSize = writer.getPageSize();
        writer.getDirectContent().circle(
                pageSize.getLeft(document.leftMargin()) + (pageSize.getWidth() - document.leftMargin() - document.rightMargin()) * Math.random(),
                y-radius, radius);
        y-= 2*radius + 5;
    }

    writer.getDirectContent().fillStroke();
    document.close();

    return baos.toByteArray();
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:28,代碼來源:ImportPageWithoutFreeSpace.java

示例10: writePdfDataToOutputStream

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
public void writePdfDataToOutputStream(OutputStream toWrite, final int treeCount, final String text, final String name, final String number, String imagePath) throws Exception {
    // create pdf
    final Document doc = new Document();
    final PdfWriter pdfWriter = PdfWriter.getInstance(doc, toWrite);
    pdfWriter.setEncryption(null, null, PdfWriter.ALLOW_DEGRADED_PRINTING | PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_128);

    final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+2"), Locale.GERMAN);
    cal.setTimeInMillis(System.currentTimeMillis());
    final String date = cal.get(Calendar.DAY_OF_MONTH) + "." + (cal.get(Calendar.MONTH) + 1) + "." + cal.get(Calendar.YEAR);

    _imagePath = imagePath;

    doc.open();

    PdfContentByte cb = pdfWriter.getDirectContent();
    PdfHelper.createHeaderBlock(cb,1,1);
    PdfHelper.createCircleAndText(cb, "Zertifikat", 298f, 665f, 75f, textFontForCircle, 0x9E, 0x3C, 0x59);
    createTreeCountAndCustomTextBlock(cb, text, treeCount);
    createLawTextDateAndSignatureBlock(cb, number, date);
    pdfHelper.addLogo(cb, imagePath, 262f, 20f);

    doc.close();
}
 
開發者ID:Dica-Developer,項目名稱:weplantaforest,代碼行數:24,代碼來源:PdfCertificateView.java

示例11: createSimpleTextPdf

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
static byte[] createSimpleTextPdf(String paragraphFormat, int paragraphCount) throws DocumentException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, baos);
    document.open();
    for (int i = 0; i < paragraphCount; i++)
    {
        Paragraph paragraph = new Paragraph();
        paragraph.add(String.format(paragraphFormat, i));
        document.add(paragraph);
    }
    document.close();

    return baos.toByteArray();
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:18,代碼來源:DenseMerging.java

示例12: exportInnertion

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的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

示例13: renderGraph

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的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

示例14: htmlToPdf

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的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

示例15: main

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的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


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