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


Java PageSize.A4属性代码示例

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


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

示例1: createPDF

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,代码行数:28,代码来源:PDFCreator.java

示例2: writeChartToPDF

/**
 * Save the chart as pdf.
 *
 * @param chart
 *            chart that should be saved
 * @param fileName
 *            file name under which chart should be saved
 */
public static void writeChartToPDF(final JFreeChart chart,
		final String fileName) {
	PdfWriter writer = null;

	com.itextpdf.text.Document document = new com.itextpdf.text.Document(
			PageSize.A4);
	final int width = (int) PageSize.A4.getWidth();
	final int height = (int) PageSize.A4.getHeight();

	try {
		writer = PdfWriter.getInstance(document, new FileOutputStream(
				fileName + ".pdf"));
		document.open();
		PdfContentByte contentByte = writer.getDirectContent();
		PdfTemplate template = contentByte.createTemplate(width, height);
		Graphics2D graphics2d = template.createGraphics(width, height,
				new DefaultFontMapper());
		Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width,
				height);

		chart.draw(graphics2d, rectangle2d);

		graphics2d.dispose();
		contentByte.addTemplate(template, 0, 0);

	} catch (Exception e) {
		e.printStackTrace();
	}
	document.close();
}
 
开发者ID:adamIqbal,项目名称:Health,代码行数:38,代码来源:Histogram.java

示例3: testShowTextAlignedVsSimpleColumnTopAlignment

/**
 * <a href="http://stackoverflow.com/questions/32162759/columntext-showtextaligned-vs-columntext-setsimplecolumn-top-alignment">
 * ColumnText.ShowTextAligned vs ColumnText.SetSimpleColumn Top Alignment
 * </a>
 * <p>
 * Indeed, the coordinates do not line up. The y coordinate of 
 * {@link ColumnText#showTextAligned(PdfContentByte, int, Phrase, float, float, float)}
 * denotes the baseline while {@link ColumnText#setSimpleColumn(Rectangle)} surrounds
 * the text to come.
 * </p>
 */
@Test
public void testShowTextAlignedVsSimpleColumnTopAlignment() throws DocumentException, IOException
{
    Document document = new Document(PageSize.A4);

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "ColumnTextTopAligned.pdf")));
    document.open();

    Font fontQouteItems = new Font(BaseFont.createFont(), 12);
    PdfContentByte canvas = writer.getDirectContent();

    // Item Number
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("36222-0", fontQouteItems), 60, 450, 0);

    // Estimated Qty
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("47", fontQouteItems), 143, 450, 0);

    // Item Description
    ColumnText ct = new ColumnText(canvas); // Uses a simple column box to provide proper text wrapping
    ct.setSimpleColumn(new Rectangle(193, 070, 390, 450));
    ct.setText(new Phrase("In-Situ : Poly Cable - 100'\nPoly vented rugged black gable 100ft\nThis is an additional description. It can wrap an extra line if it needs to so this text is long.", fontQouteItems));
    ct.go();

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

示例4: testRotateAndZoomUpperHalfPage

/**
 * <a href="http://stackoverflow.com/questions/35374110/how-do-i-use-itext-to-have-a-landscaped-pdf-on-half-of-a-a4-back-to-portrait-and">
 * How do i use iText to have a landscaped PDF on half of a A4 back to portrait and full size on A4
 * </a>
 * <p>
 * This sample shows how to rotate and enlarge the upper half of an A4 page to fit into a new A4 page.
 * </p>
 */
@Test
public void testRotateAndZoomUpperHalfPage() throws IOException, DocumentException
{
    try (   InputStream resource = getClass().getResourceAsStream("/mkl/testarea/itext5/extract/test.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "test-upperHalf.pdf"))   )
    {
        PdfReader reader = new PdfReader(resource);
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, result);
        document.open();

        double sqrt2 = Math.sqrt(2);
        Rectangle pageSize = reader.getPageSize(1);
        PdfImportedPage importedPage = writer.getImportedPage(reader, 1);
        writer.getDirectContent().addTemplate(importedPage, 0, sqrt2, -sqrt2, 0, pageSize.getTop() * sqrt2, -pageSize.getLeft() * sqrt2);
        
        document.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:27,代码来源:EnlargePagePart.java

示例5: writeSimplePdf

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,代码行数:40,代码来源:ItextpdfTest.java

示例6: main

/**
 * Generates a document with a header containing Page x of y and with a Watermark on every page.
 * @param args no arguments needed
 */
public static void main(String args[]) {
    try {
    	// 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, new FileOutputStream("pageNumbersWatermark.pdf"));
        // step 3: initialisations + opening the document
        writer.setPageEvent(new PageNumbersWatermark());
        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();
    }
    catch ( Exception e ) {
        e.printStackTrace();
    }
}
 
开发者ID:ltrr-arizona-edu,项目名称:tellervo,代码行数:27,代码来源:PageNumbersWatermark.java

示例7: testMergeGrandizerFiles

/**
 * <a href="http://stackoverflow.com/questions/28991291/how-to-remove-whitespace-on-merge">
 * How To Remove Whitespace on Merge
 * </a>
 * <p>
 * Testing {@link PdfVeryDenseMergeTool} using the OP's files.
 * </p>
 */
@Test
public void testMergeGrandizerFiles() throws DocumentException, IOException
{
    try (   InputStream docA = getClass().getResourceAsStream("Header.pdf");
            InputStream docB = getClass().getResourceAsStream("Body.pdf");
            InputStream docC = getClass().getResourceAsStream("Footer.pdf");    )
    {
        PdfVeryDenseMergeTool tool = new PdfVeryDenseMergeTool(PageSize.A4, 18, 18, 5);
        PdfReader readerA = new PdfReader(docA);
        PdfReader readerB = new PdfReader(docB);
        PdfReader readerC = new PdfReader(docC);
        try (FileOutputStream fos = new FileOutputStream(new File(RESULT_FOLDER, "GrandizerMerge-veryDense.pdf")))
        {
            List<PdfReader> inputs = Arrays.asList(readerA, readerB, readerC);
            tool.merge(fos, inputs);
        }
        finally
        {
            readerA.close();
            readerB.close();
            readerC.close();
        }
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:32,代码来源:VeryDenseMerging.java

示例8: testMergeGrandizerFilesGap10

/**
 * <a href="http://stackoverflow.com/questions/28991291/how-to-remove-whitespace-on-merge">
 * How To Remove Whitespace on Merge
 * </a>
 * <p>
 * Testing {@link PdfVeryDenseMergeTool} using the OP's files and a gap of 10. This was the
 * OP's gap value of choice resulting in lost lines. Cannot reproduce...
 * </p>
 */
@Test
public void testMergeGrandizerFilesGap10() throws DocumentException, IOException
{
    try (   InputStream docA = getClass().getResourceAsStream("Header.pdf");
            InputStream docB = getClass().getResourceAsStream("Body.pdf");
            InputStream docC = getClass().getResourceAsStream("Footer.pdf");    )
    {
        PdfVeryDenseMergeTool tool = new PdfVeryDenseMergeTool(PageSize.A4, 18, 18, 10);
        PdfReader readerA = new PdfReader(docA);
        PdfReader readerB = new PdfReader(docB);
        PdfReader readerC = new PdfReader(docC);
        try (FileOutputStream fos = new FileOutputStream(new File(RESULT_FOLDER, "GrandizerMerge-veryDense-gap10.pdf")))
        {
            List<PdfReader> inputs = Arrays.asList(readerA, readerB, readerC);
            tool.merge(fos, inputs);
        }
        finally
        {
            readerA.close();
            readerB.close();
            readerC.close();
        }
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:33,代码来源:VeryDenseMerging.java

示例9: createPdf

public static void createPdf(String filename, String dbTable) throws SQLException, DocumentException, IOException {
        // step 1
        Document document = new Document(PageSize.A4);
//        System.out.println(Tax.class.getResource("fonts/arial.ttf").getPath());
        BaseFont bf = BaseFont.createFont("etc/Arial.ttf", "Cp1253", BaseFont.EMBEDDED);
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        // step 3
        document.open();
        // step 4
        PdfPTableEvent event = new Printer();
        PdfPTable table = getTable(dbTable, bf);
        table.setTableEvent(event);
        document.add(table);
        document.newPage();
        // step 5
        document.close();
    }
 
开发者ID:johnmans,项目名称:EnTax,代码行数:18,代码来源:Printer.java

示例10: CreatePDF

public void CreatePDF() throws IOException {
    Document doc = null;
    OutputStream outStream = null;

    try {
        doc = new Document(PageSize.A4, 72, 72, 72, 72);
        outStream = new FileOutputStream(fileName);
        PdfWriter.getInstance(doc, outStream);
        doc.open();
        doc.add(new Paragraph(getHeader()));
        doc.add(table);
        doc.add(new Paragraph(descricao));

    } catch (FileNotFoundException | DocumentException ex) {
        Logger.getLogger(OutPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (doc != null) {
            doc.close();
        }
        if (outStream != null) {
            outStream.close();
        }
        // table.getRows().add(null)
    }
    JOptionPane.showMessageDialog(null, "PDF Salvo com sucesso!");
}
 
开发者ID:sufex00,项目名称:GerenciadordeHorario,代码行数:26,代码来源:OutPDF.java

示例11: createPdf

/**
 * Create the PDF from a {@link Component}.
 * 
 * @param component
 */
private void createPdf(Component component) {
	if (component == null) {
		return;
	}

	// prompt user for pdf location
	File file = promptForPdfLocation();
	if (file == null) {
		return;
	}

	try {
		// create pdf document
		Document document = new Document(PageSize.A4);
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
		document.open();
		PdfContentByte cb = writer.getDirectContent();
		createPdfViaTemplate(component, document, cb);
		document.close();
	} catch (Exception e) {
		SwingTools.showSimpleErrorMessage("cannot_export_pdf", e, e.getMessage());
	}
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:28,代码来源:ExportPdfAction.java

示例12: getPageSize

private Rectangle getPageSize(String quality) {
    if (quality == null) {
        quality = "a2";
    }
    logger.info("Setting PDF Quality to : " + quality);
    logWindow.log("Setting PDF Quality to : " + quality);
    switch (quality.toLowerCase()) {
        case "a2":
            return PageSize.A2;
        case "a3":
            return PageSize.A3;
        case "a4":
            return PageSize.A4;
        case "a5":
            return PageSize.A5;
        case "a6":
            return PageSize.A6;
        case "a7":
            return PageSize.A7;
        default:
            return PageSize.A3;
    }
}
 
开发者ID:cancerian0684,项目名称:dli-downloader,代码行数:23,代码来源:DLIDownloader.java

示例13: savePageAsPdf

public String savePageAsPdf(boolean scaled) throws IOException, DocumentException
{
	String pdfName = "";

	// Define test screenshot root
	String test = "";
	if (TestNamingUtil.isTestNameRegistered()) {
		test = TestNamingUtil.getTestNameByThread();
	} else {
		test = "undefined";
	}
	
	File testRootDir = ReportContext.getTestDir();
	File artifactsFolder = ReportContext.getArtifactsFolder();

	String fileID = test.replaceAll("\\W+", "_") + "-" + System.currentTimeMillis();
	pdfName = fileID + ".pdf";

	String fullPdfPath = artifactsFolder.getAbsolutePath() + "/" + pdfName;
	// TODO: test this implementation and change back to capture if necessary
	Image image = Image.getInstance(testRootDir.getAbsolutePath() + "/" + Screenshot.captureFailure(driver, ""));
	Document document = null;
	if (scaled)
	{
		document = new Document(PageSize.A4, 10, 10, 10, 10);
		if (image.getHeight() > (document.getPageSize().getHeight() - 20)
				|| image.getScaledWidth() > (document.getPageSize().getWidth() - 20))
		{
			image.scaleToFit(document.getPageSize().getWidth() - 20, document.getPageSize().getHeight() - 20);
		}
	} else
	{
		document = new Document(new RectangleReadOnly(image.getScaledWidth(), image.getScaledHeight()));
	}
	PdfWriter.getInstance(document, new FileOutputStream(fullPdfPath));
	document.open();
	document.add(image);
	document.close();
	return fullPdfPath;
}
 
开发者ID:qaprosoft,项目名称:carina,代码行数:40,代码来源:AbstractPage.java

示例14: main

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,代码行数:40,代码来源:teste.java

示例15: GetPDFBin

public static String GetPDFBin(HttpServletResponse response, String docText) {
    Document document = new Document(PageSize.A4, 36, 36, 36, 36);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.open();
        InputStream is = new ByteArrayInputStream(docText.getBytes());
        XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
        document.close();
        return(new String(Base64.encodeBase64(baos.toByteArray())));
    }
    catch (Exception e) {
    	logger.error("Unexpected error", e);
    }
    return null;

}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:17,代码来源:Doc2PDF.java


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