List of usage examples for com.lowagie.text Rectangle rotate
public Rectangle rotate()
From source file:com.krawler.esp.servlets.ExportProjectReportServlet.java
License:Open Source License
private ByteArrayOutputStream exportToPdfTimeline(HttpServletRequest request, String as) throws ServiceException { JSONObject s = null;/*from www . j a va 2 s .c om*/ ByteArrayOutputStream os = new ByteArrayOutputStream(); try { config = new com.krawler.utils.json.base.JSONObject(request.getParameter("config")); s = new JSONObject(as); JSONArray head = s.getJSONArray("columnheader"); JSONArray store = s.getJSONArray("data"); String[] colwidth2 = new String[head.length() + 3]; String[] colnm = { "info", "level", "flag" }; for (int i = 0; i < colwidth2.length; i++) { if (i < 3) colwidth2[i] = colnm[i]; else { if (head.getJSONObject(i - 3).has("0")) colwidth2[i] = head.getJSONObject(i - 3).getString("0"); else colwidth2[i] = head.getJSONObject(i - 3).getString("1"); } } int maxlevel = 0; for (int k = 0; k < store.length(); k++) { for (int j = 0; j < colwidth2.length; j++) { if (!store.getJSONObject(k).has(colwidth2[j])) store.getJSONObject(k).put(colwidth2[j], ""); } if (store.getJSONObject(k).getInt("level") > maxlevel) maxlevel = store.getJSONObject(k).getInt("level"); } int len = colwidth2.length - 3; int p = 0; if (len <= 5) p = colwidth2.length; else p = 8; Rectangle recPage = new Rectangle(PageSize.A4); recPage.setBackgroundColor(new java.awt.Color(Integer.parseInt(config.getString("bgColor"), 16))); Document document = null; if (config.getBoolean("landscape")) document = new Document(recPage.rotate(), 15, 15, 30, 30); else document = new Document(recPage, 15, 15, 30, 30); PdfWriter writer = PdfWriter.getInstance(document, os); writer.setPageEvent(new EndPage()); document.open(); if (config.getBoolean("showLogo")) { getCompanyDetails(request); addComponyLogo(document, request); } addTitleSubtitle(document); document.add(new Paragraph("\u00a0")); addTableTimeLine(3, p, 0, store.length(), store, colwidth2, maxlevel, document); document.close(); writer.close(); os.close(); } catch (ConfigurationException ex) { throw ServiceException.FAILURE("ExportProjectReport.exportToPdfTimeline", ex); } catch (IOException ex) { throw ServiceException.FAILURE("ExportProjectReport.exportToPdfTimeline", ex); } catch (DocumentException ex) { throw ServiceException.FAILURE("ExportProjectReport.exportToPdfTimeline", ex); } catch (JSONException e) { throw ServiceException.FAILURE("ExportProjectReport.exportToPdfTimeline", e); } return os; }
From source file:com.pureinfo.srm.patent.action.PatentPrintPdfAction.java
License:Open Source License
/** * @see com.pureinfo.ark.interaction.ActionBase#executeAction() */// ww w . ja v a2 s .c o m public ActionForward executeAction() throws PureException { int nYear = request.getRequiredInt("year", ""); Rectangle rectPageSize = new Rectangle(PageSize.A4); rectPageSize.setBackgroundColor(Color.WHITE); rectPageSize.setBorderColor(Color.BLACK); rectPageSize = rectPageSize.rotate(); Document doc = new Document(rectPageSize, 10, 10, 10, 10); doc.addTitle(nYear + ""); doc.addAuthor("PureInfo"); try { BaseFont bfontTitle = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font fontTitle = new Font(bfontTitle, 18, Font.NORMAL); Paragraph paraTitle = new Paragraph(nYear + "", fontTitle); paraTitle.setAlignment(ElementTags.ALIGN_CENTER); BaseFont bfontContent = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font fontContent = new Font(bfontContent, 10, Font.NORMAL); FileFactory fileFactory = FileFactory.getInstance(); String sPath = fileFactory.lookupPathConfigByFlag(FileFactory.FLAG_DOWNLOADTEMP, true).getLocalPath(); FileUtil.insurePathExists(sPath); PdfWriter.getInstance(doc, new FileOutputStream(new File(sPath, "patent.pdf"))); doc.open(); doc.add(paraTitle); doc.add(new Paragraph(" ")); String[] arrTitles = new String[] { "", "", "", "", "", "", "", "", "" }; PdfPTable pTable = new PdfPTable(arrTitles.length); pTable.setWidths(new int[] { 5, 10, 9, 9, 20, 15, 12, 10, 10 }); for (int i = 0; i < arrTitles.length; i++) { PdfPCell pCell = new PdfPCell(); Paragraph para = new Paragraph(arrTitles[i], fontContent); para.setAlignment(ElementTags.ALIGN_CENTER); pCell.addElement(para); pTable.addCell(pCell); } /** * */ IPatentMgr mgr = (IPatentMgr) ArkContentHelper.getContentMgrOf(Patent.class); List patents = mgr.findAllAuthorizedOf(nYear); int i = 0; for (Iterator iter = patents.iterator(); iter.hasNext(); i++) { Patent patent = (Patent) iter.next(); this.addPatentCell(pTable, String.valueOf(i + 1), fontContent); this.addPatentCell(pTable, patent.getPatentSid(), fontContent); this.addPatentCell(pTable, ForceConstants.DATE_FORMAT.format(patent.getApplyDate()), fontContent); this.addPatentCell(pTable, patent.getWarrantDate() == null ? "" : ForceConstants.DATE_FORMAT.format(patent.getWarrantDate()), fontContent); this.addPatentCell(pTable, patent.getName(), fontContent); this.addPatentCell(pTable, patent.getAllAuthosName(), fontContent); this.addPatentCell(pTable, patent.getRightPerson(), fontContent); this.addPatentCell(pTable, getCollegeName(patent), fontContent); this.addPatentCell(pTable, patent.getPatentTypeName(), fontContent); } doc.add(pTable); doc.close(); } catch (DocumentException ex) { // TODO Auto-generated catch block ex.printStackTrace(System.err); } catch (IOException ex) { // TODO Auto-generated catch block ex.printStackTrace(System.err); } List list = new ArrayList(); list.add(new Pair("/download/patent.pdf", "")); request.setAttribute("forward", list); return mapping.findForward("success"); }
From source file:include.nseer_cookie.MakePdf.java
License:Open Source License
public void make(String database, String tablename, String sql1, String sql2, String filename, int everypage, HttpSession session) {/* w ww . jav a2 s .co m*/ try { nseer_db aaa = new nseer_db(database); nseer_db demo_db = new nseer_db(database); ServletContext context = session.getServletContext(); String path = context.getRealPath("/"); Masking reader = new Masking(configFile); Vector columnNames = new Vector(); Vector tables = reader.getTableNicks(); Iterator loop = tables.iterator(); while (loop.hasNext()) { String tablenick = (String) loop.next(); columnNames = reader.getColumnNames(tablenick); } int cpage = 1; //? int spage = 1; int ipage = everypage; String pagesql = sql1; //? ResultSet pagers = demo_db.executeQuery(pagesql); pagers.next(); int allCol = pagers.getInt("A"); allpage = (int) Math.ceil((allCol + ipage - 1) / ipage); // for (int m = 1; m <= allpage; m++) { spage = (m - 1) * ipage; String sql = sql2 + " limit " + spage + "," + ipage; ResultSet bbb = aaa.executeQuery(sql); //ResultSetMetaData tt=bbb.getMetaData(); // int b = columnNames.size(); // int a = 0; while (bbb.next()) { a++; } // bbb.first(); // ?? Rectangle rectPageSize = new Rectangle(PageSize.A4);// rectPageSize = rectPageSize.rotate(); Document document = new Document(rectPageSize, 20, 20, 20, 20); //? Document PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path + filename + m + ".pdf")); //?PDF?? document.open(); // BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); //? com.lowagie.text.Font FontChinese = new com.lowagie.text.Font(bfChinese, 8, com.lowagie.text.Font.NORMAL); // Paragraph title1 = new Paragraph("nseer ERP", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC)); Chapter chapter1 = new Chapter(title1, 1); // ? chapter1.setNumberDepth(0); Paragraph title11 = new Paragraph(tablename, FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD)); Section section1 = chapter1.addSection(title11); //? Table t = new Table(b, a); // ? t.setPadding(1); // t.setSpacing(0); // ? t.setBorderWidth(1); // do { // // for (int k = 0; k < b; k++) { // Cell cell = new Cell( new Paragraph(bbb.getString((String) columnNames.elementAt(k)), FontChinese)); //? // t.addCell(cell); // ? // } // } while (bbb.next()); // section1.add(t); // document.add(chapter1); // document.close(); } // ? } catch (Exception pp) { pp.printStackTrace(); } }
From source file:jdbreport.model.io.pdf.itext2.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. j av a 2 s . c o m 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(Math.round((float) paper.getWidth()), Math.round((float) paper.getHeight())); if (pageFormat.getOrientation() == ReportPage.LANDSCAPE) { pageSize = pageSize.rotate(); } Document document = new Document(pageSize, Math.round((float) pageFormat.getLeftMargin(Units.PT)), Math.round((float) pageFormat.getRightMargin(Units.PT)), Math.round((float) pageFormat.getTopMargin(Units.PT)), Math.round((float) pageFormat.getBottomMargin(Units.PT))); try { com.lowagie.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.itext2.PdfWriter.java
License:Apache License
private int saveSheet(Document document, int listCount, ReportModel model) throws DocumentException, IOException, SaveReportException { model.updatePages(0);/*from ww w . j a v a 2s .c om*/ ReportPage pageFormat = model.getReportPage(); Paper paper = pageFormat.getPaper(); Rectangle pageSize = new Rectangle(Math.round((float) paper.getWidth()), Math.round((float) paper.getHeight())); if (pageFormat.getOrientation() == ReportPage.LANDSCAPE) { pageSize = pageSize.rotate(); } document.setPageSize(pageSize); document.setMargins(Math.round((float) pageFormat.getLeftMargin(Units.PT)), Math.round((float) pageFormat.getRightMargin(Units.PT)), Math.round((float) pageFormat.getTopMargin(Units.PT)), Math.round((float) pageFormat.getBottomMargin(Units.PT))); Rectangle viewPageSize = new Rectangle( document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(), document.getPageSize().getHeight() - document.topMargin() - document.bottomMargin()); if (listCount > 0) { document.newPage(); } listCount++; //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 + 1]; widths[0] = 1; for (int c = 0; c < columnCount; c++) { ReportColumn column = (ReportColumn) model.getColumnModel().getColumn(leftCol + c); widths[c + 1] = (float) Math.round(column.getNativeWidth()); } PdfPTable table = createPdfTable(columnCount + 1, widths, viewPageSize); fillTable(model, leftCol, topRow, rightCol, bottomRow, table); document.add(table); if (pageIndex < clips.size()) { document.newPage(); } } return listCount; }
From source file:net.bull.javamelody.internal.web.pdf.PdfDocumentFactory.java
License:Apache License
private Rectangle getPageSize(boolean landscape) { Rectangle pageSize; if (Locale.US.getCountry().equals(I18N.getCurrentLocale().getCountry())) { // Letter size paper is used in the US instead of the ISO standard A4 pageSize = PageSize.LETTER;/* w ww . j a va 2 s . c o m*/ } else { pageSize = PageSize.A4; } if (landscape) { pageSize = pageSize.rotate(); } return pageSize; }
From source file:org.mapfish.print.config.layout.Page.java
License:Open Source License
public Rectangle getPageSizeRect(RenderingContext context, PJsonObject params) { final Rectangle result = PageSize.getRectangle(getPageSize(context, params)); if (landscape) { return result.rotate(); } else {/*from w w w. j a v a 2 s . c o m*/ return result; } }
From source file:org.oss.pdfreporter.pdf.Document.java
License:Open Source License
private IPage newPage(PageOrientation orientation, Rectangle pageSize) { // TODO (25.05.2013, Donat, Open Software Solutions): Verify if rotating is due to iText or Jasper (LANDSCAPE && WIDTH < HEIGHT) delegate.setPageSize(orientation == PageOrientation.LANDSCAPE ? pageSize.rotate() : pageSize); delegate.newPage();/*from w ww.ja v a 2 s . c o m*/ return new Page(pdfWriter.getDirectContent()); }
From source file:ro.nextreports.engine.exporter.RtfExporter.java
License:Apache License
protected void initExport() throws QueryException { if (!bean.isSubreport()) { Padding margins = bean.getReportLayout().getPagePadding(); Rectangle rectangle; if (ReportLayout.CUSTOM.equals(bean.getReportLayout().getPageFormat())) { PaperSize customSize = bean.getReportLayout().getPaperSize(); rectangle = new Rectangle(customSize.getWidthPoints(), customSize.getHeightPoints()); } else {/*ww w . j a v a2 s. c o m*/ rectangle = PageSize.getRectangle(getPageFormat()); } document = new Document(rectangle, getPoints(margins.getLeft()), getPoints(margins.getRight()), getPoints(margins.getTop()), getPoints(margins.getBottom())); if (bean.getReportLayout().getOrientation() == LANDSCAPE) { document.setPageSize(rectangle.rotate()); } RtfWriter2 writer2 = RtfWriter2.getInstance(document, getOut()); } try { if (!bean.isSubreport()) { buildHeader(); buildFooter(); addMetaData(); document.open(); } table = buildRtfTable(PRINT_DOCUMENT); } catch (DocumentException e) { e.printStackTrace(); throw new QueryException(e); } }