當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。