List of usage examples for com.itextpdf.text Rectangle rotate
public Rectangle rotate()
From source file:com.bdaum.zoom.email.internal.job.PdfJob.java
License:Open Source License
public static Rectangle computeFormat(PageLayout_type layout) { Rectangle format = PageSize.A4; String f = layout.getFormat(); for (int i = 0; i < PageLayout_type.formatALLVALUES.length; i++) if (PageLayout_type.formatALLVALUES[i].equals(f)) { format = PAGEFORMATS[i];/*from w w w . j av a 2 s .c o m*/ break; } return (layout.getLandscape()) ? format.rotate() : format; }
From source file:com.masscustsoft.service.ToPdf.java
License:Open Source License
private void createPdf(Map rpt, Map<String, String> i18n, File pdf) throws Exception { OutputStream out = new FileOutputStream(pdf); ThreadHelper.set("_fonts_", new HashMap<String, BaseFont>()); ThreadHelper.set("_defaultFont_", BaseFont.createFont()); String pageSize = MapUtil.getStr(rpt, "pageSize", "A4"); int defaultFontSize = MapUtil.getInt(rpt, "defaultFontSize", 6); ThreadHelper.set("_defaultFontSize_", defaultFontSize); ThreadHelper.set("_rpt_", rpt); int i = pageSize.indexOf(';'); String margins = "36 36 36 36"; if (i > 0) { margins = pageSize.substring(i + 1); pageSize = pageSize.substring(0, i); }/*w w w . j a v a2s . c om*/ boolean rotate = false; if (pageSize.startsWith("@")) { rotate = true; pageSize = pageSize.substring(1); } Rectangle pSize = PageSize.getRectangle(pageSize); if (rotate) pSize = pSize.rotate(); String mars[] = margins.split(" "); float ml = 0, mt = 0, mr = 0, mb = 0; mr = mt = mb = ml = LightUtil.decodeFloat(mars[0]); if (mars.length > 1) { mt = mb = LightUtil.decodeFloat(mars[1]); } if (mars.length > 2) { mr = LightUtil.decodeFloat(mars[2]); } if (mars.length > 3) { mb = LightUtil.decodeFloat(mars[3]); } Document doc = new Document(pSize, ml, mr, mt, mb); MapUtil.setIfStr(rpt, "author", doc, "addAuthor"); MapUtil.setIfStr(rpt, "creator", doc, "addCreator"); MapUtil.setIfStr(rpt, "title", doc, "addTitle"); MapUtil.setIfStr(rpt, "keyWords", doc, "addKeywords"); MapUtil.setIfStr(rpt, "subject", doc, "addSubject"); PdfWriter writer = PdfWriter.getInstance(doc, out); writer.setPageEvent(this); writer.setStrictImageSequence(true); ThreadHelper.set("_writer_", writer); ThreadHelper.set("_doc_", doc); doc.open(); List<Map> items = (List) rpt.get("items"); for (Map row : items) { Element el = getElement(row); if (el != null) doc.add(el); } doc.close(); out.close(); writer.close(); ThreadHelper.set("_writer_", null); ThreadHelper.set("_doc_", null); }
From source file:jdbreport.model.io.pdf.itext5.PdfWriter.java
License:Apache License
public void save(OutputStream out, ReportBook reportBook) throws SaveReportException { double oldScaleX = GraphicUtil.getScaleX(); double oldScaleY = GraphicUtil.getScaleY(); try {/* w w w. jav a 2s. com*/ GraphicUtil.setScaleX(1); GraphicUtil.setScaleY(1); ReportPage pageFormat; int i = 0; while (i < reportBook.size() - 1 && !reportBook.getReportModel(i).isVisible()) { i++; } pageFormat = reportBook.getReportModel(i).getReportPage(); Paper paper = pageFormat.getPaper(); Rectangle pageSize = new Rectangle((float) paper.getWidth(), (float) paper.getHeight()); if (pageFormat.getOrientation() == ReportPage.LANDSCAPE) { pageSize = pageSize.rotate(); } Document document = new Document(pageSize, (float) pageFormat.getLeftMargin(Units.PT), (float) pageFormat.getRightMargin(Units.PT), (float) pageFormat.getTopMargin(Units.PT), (float) pageFormat.getBottomMargin(Units.PT)); try { com.itextpdf.text.pdf.PdfWriter.getInstance(document, out); document.addTitle(reportBook.getReportCaption()); document.addCreator("JDBReport using iText"); document.addAuthor(System.getProperty("user.name")); document.open(); int listCount = 0; try { for (ReportModel model : reportBook) { if (model.isVisible()) { listCount = saveSheet(document, listCount, model); } } document.close(); } catch (IOException e) { e.printStackTrace(); } } catch (DocumentException e) { throw new SaveReportException(e); } } finally { GraphicUtil.setScaleX(oldScaleX); GraphicUtil.setScaleY(oldScaleY); } }
From source file:jdbreport.model.io.pdf.itext5.PdfWriter.java
License:Apache License
private int saveSheet(Document document, int listCount, ReportModel model) throws DocumentException, IOException, SaveReportException { model.updatePages(0);/*from w w w . java 2 s .c o m*/ ReportPage pageFormat = model.getReportPage(); Paper paper = pageFormat.getPaper(); Rectangle pageSize = new Rectangle((float) paper.getWidth(), (float) paper.getHeight()); if (pageFormat.getOrientation() == ReportPage.LANDSCAPE) { pageSize = pageSize.rotate(); } document.setPageSize(pageSize); document.setMargins((float) pageFormat.getLeftMargin(Units.PT), (float) pageFormat.getRightMargin(Units.PT), (float) pageFormat.getTopMargin(Units.PT), (float) pageFormat.getBottomMargin(Units.PT)); if (listCount > 0) { document.newPage(); } listCount++; TableRowModel rowModel = model.getRowModel(); float columnMargin = (float) Units.PT.setXPixels(model.getColumnModel().getColumnMargin()); ReportPrintable printable = new ReportPrintable(model); int pageCount = printable.calcCountPage(model.getReportPage()); Map<Integer, PageClip> clips = printable.getPageClips(); int leftCol; int topRow; int rightCol; int bottomRow; for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) { PageClip pageClip = clips.get(pageIndex); if (pageClip == null) break; leftCol = pageClip.getLeftCol(); rightCol = pageClip.getRightCol(); topRow = pageClip.getTopRow(); bottomRow = pageClip.getBottomRow(); int columnCount = rightCol - leftCol; float[] widths = new float[columnCount]; for (int c = 0; c < widths.length; c++) { ReportColumn column = (ReportColumn) model.getColumnModel().getColumn(leftCol + c); widths[c] = (float) column.getNativeWidth() + columnMargin; } PdfPTable table = createPdfTable(columnCount, widths, document.getPageSize()); for (int row = topRow; row < bottomRow; row++) { TableRow reportRow = rowModel.getRow(row); for (int col = leftCol; col < rightCol; col++) { jdbreport.model.Cell srcCell = reportRow.getCellItem(col); if (!srcCell.isChild()) { PdfPCell pdfCell = writeCell(model, srcCell, row, col); table.addCell(pdfCell); } } } document.add(table); if (pageIndex < clips.size()) { document.newPage(); } } return listCount; }
From source file:org.fhaes.neofhchart.PDFExportOptionsDialog.java
License:Open Source License
/** * Performs the export operation using the currentChart as the source. * /*from www .j a v a 2 s . c om*/ * @return true if the operation completed successfully, false otherwise */ private boolean doExportToPDF() { boolean completedSuccessfully = false; if (currentChart != null) { log.debug("Exporting to PDF..."); Document document = null; if (cboPaperSize.getSelectedItem() instanceof Rectangle) { Rectangle rect = (Rectangle) cboPaperSize.getSelectedItem(); if (radLandscape.isSelected()) { rect = rect.rotate(); } document = new Document(rect, 10, 10, 10, 10); } else { Rectangle rect = new Rectangle(currentChart.getTotalWidth(), currentChart.getTotalHeight()); document = new Document(rect, 10, 10, 10, 10); } try { currentChart.setVisibilityOfNoExportElements(false); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile.getAbsolutePath())); document.open(); int width = (int) document.getPageSize().getWidth(); int height = (int) document.getPageSize().getHeight(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate template = cb.createTemplate(width, height); @SuppressWarnings("deprecation") Graphics2D g2 = template.createGraphics(width, height); PrintTranscoder prm = new PrintTranscoder(); TranscoderInput ti = new TranscoderInput(currentChart.getSVGDocument()); prm.transcode(ti, null); PageFormat pg = new PageFormat(); Paper pp = new Paper(); pp.setSize(width, height); pp.setImageableArea(0, 0, width, height); pg.setPaper(pp); prm.print(g2, pg, 0); g2.dispose(); ImgTemplate img = new ImgTemplate(template); document.add(img); completedSuccessfully = true; } catch (DocumentException e) { System.err.println(e); } catch (IOException e) { System.err.println(e); } finally { currentChart.setVisibilityOfNoExportElements(true); } document.close(); } return completedSuccessfully; }
From source file:org.ganttproject.impex.htmlpdf.itext.ThemeImpl.java
License:GNU General Public License
void run(IGanttProject project, UIFacade facade, OutputStream out) throws ExportException { myProject = project;/*from w w w .j av a 2s.co m*/ myUIFacade = facade; Rectangle pageSize = PageSize.getRectangle(myPageSizeOption.getValue()); if (myLandscapeOption.isChecked()) { pageSize = pageSize.rotate(); } myDoc = new Document(pageSize, 20, 20, 70, 40); try { myWriter = PdfWriter.getInstance(myDoc, out); myWriter.setPageEvent(this); myDoc.open(); writeProject(); } catch (Throwable e) { e.printStackTrace(); throw new ExportException("Export failed", e); } finally { myDoc.close(); } }
From source file:ro.nextreports.engine.exporter.PdfExporter.java
License:Apache License
protected void initExport() throws QueryException { Padding margins = bean.getReportLayout().getPagePadding(); if (!bean.isSubreport()) { float footerHeight = computeFooterHeight(); Rectangle rectangle; if (ReportLayout.CUSTOM.equals(bean.getReportLayout().getPageFormat())) { PaperSize customSize = bean.getReportLayout().getPaperSize(); rectangle = new Rectangle(customSize.getWidthPoints(), customSize.getHeightPoints()); } else {// w ww . j a v a 2s . c om rectangle = PageSize.getRectangle(bean.getReportLayout().getPageFormat()); } document = new Document(rectangle, getPoints(margins.getLeft()), getPoints(margins.getRight()), getPoints(margins.getTop()), getPoints(margins.getBottom()) + footerHeight); if (bean.getReportLayout().getOrientation() == LANDSCAPE) { document.setPageSize(rectangle.rotate()); } } PdfWriter wr = null; try { if (!bean.isSubreport()) { wr = PdfWriter.getInstance(document, getOut()); wr.setPageEvent(new PdfPageEvent()); addMetaData(); document.open(); } table = buildPdfTable(PRINT_DOCUMENT); } catch (DocumentException e) { e.printStackTrace(); throw new QueryException(e); } }