List of usage examples for com.itextpdf.text Rectangle getHeight
public float getHeight()
From source file:se.billes.pdf.renderer.process.CutmarksRenderer.java
License:Open Source License
public void render(PdfWriter writer, Document document) { Cutmarks cutmarks = request.getCutmarks(); if (cutmarks != null && !cutmarks.isIgnoreCutStroke()) { float width = SizeFactory.CUT_MARK; float height = SizeFactory.CUT_MARK; float lineWidth = SizeFactory.CUT_MARK_LINE; float lineHeight = SizeFactory.CUT_MARK_LINE; Rectangle rect = document.getPageSize(); PdfContentByte cb = writer.getDirectContent(); cb.setLineWidth(0.1f);//from w ww. j a v a2 s. c o m cb.moveTo(SizeFactory.millimetersToPostscriptPoints(width), 0); cb.lineTo(SizeFactory.millimetersToPostscriptPoints(width), SizeFactory.millimetersToPostscriptPoints(lineHeight)); cb.stroke(); cb.moveTo(0, SizeFactory.millimetersToPostscriptPoints(height)); cb.lineTo(SizeFactory.millimetersToPostscriptPoints(lineWidth), SizeFactory.millimetersToPostscriptPoints(height)); cb.stroke(); // Upper left cut mark cb.moveTo(SizeFactory.millimetersToPostscriptPoints(width), rect.getHeight()); cb.lineTo(SizeFactory.millimetersToPostscriptPoints(width), rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(lineHeight)); cb.stroke(); cb.moveTo(0, rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(height)); cb.lineTo(SizeFactory.millimetersToPostscriptPoints(lineWidth), rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(height)); cb.stroke(); /** * Upper right cut mark */ cb.moveTo(rect.getWidth(), rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(height)); cb.lineTo(rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(lineWidth), rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(height)); cb.stroke(); cb.moveTo(rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(width), rect.getHeight()); cb.lineTo(rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(width), rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(lineHeight)); cb.stroke(); /** * Lower right cut mark */ cb.moveTo(rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(width), 0); cb.lineTo(rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(width), SizeFactory.millimetersToPostscriptPoints(lineHeight)); cb.stroke(); cb.moveTo(rect.getWidth(), SizeFactory.millimetersToPostscriptPoints(height)); cb.lineTo(rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(lineWidth), SizeFactory.millimetersToPostscriptPoints(height)); cb.stroke(); } }
From source file:se.billes.pdf.renderer.request.factory.CellBlockEvent.java
License:Open Source License
public PdfPCellEvent createEvent(final Block block) { return new PdfPCellEvent() { public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) { float radiusInPs = SizeFactory.millimetersToPostscriptPoints(block.getRadius()); PdfContentByte cb = canvas[PdfPTable.LINECANVAS]; PdfTemplate template = cb.createTemplate(rect.getWidth(), rect.getHeight()); template.roundRectangle(0, 0, rect.getWidth(), rect.getHeight(), radiusInPs); template.clip();// ww w . j a v a 2s. com template.newPath(); if (block.getBaseColor() != null) { template.setColorFill(block.getBaseColor()); } Border border = block.getBorder(); if (border != null) { template.setLineWidth(SizeFactory.millimetersToPostscriptPoints(border.getThickness())); template.setColorStroke(border.getBaseColor()); } template.roundRectangle(0, 0, rect.getWidth(), rect.getHeight(), radiusInPs); if (block.getBaseColor() != null || border != null) { if (block.getBaseColor() != null && border != null) { template.fillStroke(); } else if (block.getBaseColor() != null) { template.fill(); } else { template.stroke(); } } cb.addTemplate(template, rect.getLeft(), rect.getBottom()); } }; }
From source file:valstreamtools.ValStrSplitPage.java
private void splitDocument(String[] args) throws IOException, DocumentException { /**/* w ww . j a v a2s . c om*/ * int splitNo = 4; String inputFileName = * "C:\\tmp\\valuestream_export_input_2015-03-03-22-18-37.pdf"; String * outputFileName = "C:\\tmp\\valuestream_export_op_2015-03-03-22-18-37.pdf";* */ int splitNo = Integer.parseInt(args[0]); String inputFileName = args[1]; if (splitNo > 1) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); String splitOutFileName = "/var/tmp/PDF_SPLIT_" + sdf.format(new Date()) + ".pdf"; PdfReader reader = new PdfReader(inputFileName); Rectangle pagesize = reader.getPageSize(1); float pageHeight = pagesize.getHeight(); float newpagewidth = (pagesize.getWidth() / splitNo); Rectangle newPapeSize = new Rectangle(0, 0, newpagewidth, pageHeight); Document document = new Document(newPapeSize); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(splitOutFileName)); document.open(); int pageNos = reader.getNumberOfPages(); PdfContentByte content = writer.getDirectContent(); for (int i = 1; i <= pageNos; i++) { PdfImportedPage page = writer.getImportedPage(reader, i); if (i > 1) {// In case of a new inpit page, need to create this. document.newPage(); } for (int j = 0; j < splitNo; j++) { if (j == 0) {//This condition is used to skip the adding of new page. content.addTemplate(page, 0, 0); } else { document.newPage(); content.addTemplate(page, (-1 * j * newpagewidth), 0); } } } document.close(); reader.close(); createPageNo(splitOutFileName, args[2], pageHeight); File f = new File(splitOutFileName); if (f.exists()) { f.delete(); } } else { PdfReader reader = new PdfReader(inputFileName); float pageHeight = reader.getPageSize(1).getHeight(); reader.close(); createPageNo(inputFileName, args[2], pageHeight); } }