List of usage examples for com.lowagie.text HeaderFooter setAlignment
public void setAlignment(int alignment)
From source file:net.bull.javamelody.swing.print.MRtfWriter.java
License:Apache License
/** * We create a writer that listens to the document and directs a RTF-stream to out * * @param table/*from ww w. j av a 2 s .c om*/ * MBasicTable * @param document * Document * @param out * OutputStream * @return DocWriter */ @Override protected DocWriter createWriter(final MBasicTable table, final Document document, final OutputStream out) { final RtfWriter2 writer = RtfWriter2.getInstance(document, out); // title final String title = buildTitle(table); if (title != null) { final HeaderFooter header = new RtfHeaderFooter(new Paragraph(title)); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); document.addTitle(title); } // advanced page numbers : x/y final Paragraph footerParagraph = new Paragraph(); final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL); footerParagraph.add(new RtfPageNumber(font)); footerParagraph.add(new Phrase(" / ", font)); footerParagraph.add(new RtfTotalPageNumber(font)); footerParagraph.setAlignment(Element.ALIGN_CENTER); final HeaderFooter footer = new RtfHeaderFooter(footerParagraph); footer.setBorder(Rectangle.TOP); document.setFooter(footer); return writer; }
From source file:open.dolphin.client.AuditController.java
License:Open Source License
private void makePDF() { //- ?/*from w w w. j a v a 2 s. c o m*/ Document doc = new Document(PageSize.A4, 20.0F, 20.0F, 40.0F, 40.0F); try { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); String fileName = "_" + sdf.format(new java.util.Date()) + ".pdf"; //()?? FileOutputStream fos = new FileOutputStream(outputDir.getText() + fileName); PdfWriter pdfwriter = PdfWriter.getInstance(doc, fos); Font font_header = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 15.0F, 1); Font font_g11 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 11.0F); Font font_g10 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 10.0F); //- ? Font font_m8 = new Font(BaseFont.createFont("HeiseiMin-W3", "UniJIS-UCS2-HW-H", false), 8.0F); Font font_underline_11 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 11.0F, 4); Font font_red_11 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 11.0F); font_red_11.setColor(new Color(255, 0, 0)); Font font_empty = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 9.0F); font_empty.setColor(new Color(255, 255, 255)); Paragraph para_NF = new Paragraph(5, "\r\n", new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 13, Font.NORMAL)); para_NF.setAlignment(Element.ALIGN_CENTER); // ?? String author = Project.getProjectStub().getUserModel().getCommonName(); doc.addAuthor(author); doc.addSubject(""); HeaderFooter header = new HeaderFooter(new Phrase("", font_header), false); header.setAlignment(1); doc.setHeader(header); HeaderFooter footer = new HeaderFooter(new Phrase("--"), new Phrase("--")); footer.setAlignment(1); footer.setBorder(0); doc.setFooter(footer); doc.open(); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy''MM''dd'' HH''mm''"); String today = sdf1.format(new java.util.Date()); Paragraph para_0 = new Paragraph("?" + today, font_g11); para_0.setAlignment(2); doc.add(para_0); Paragraph para_1 = new Paragraph("?" + author, font_g11); para_1.setAlignment(2); doc.add(para_1); doc.add(new Paragraph("")); // doc.add(para_NF); doc.add(para_NF); for (int cnt = 0; cnt < outputList.size(); cnt++) { InnerBean bean = outputList.get(cnt); Person person = bean.getPerson(); Paragraph para_2 = new Paragraph("ID" + person.idProperty().get(), font_underline_11); para_2.setAlignment(0); doc.add(para_2); Paragraph para_3 = new Paragraph("???" + person.nameProperty().get(), font_underline_11); para_3.setAlignment(0); doc.add(para_3); Paragraph para_4 = new Paragraph("" + person.nameKanaProperty().get(), font_underline_11); para_4.setAlignment(0); doc.add(para_4); Paragraph para_5 = new Paragraph("" + person.sexProperty().get(), font_underline_11); para_5.setAlignment(0); doc.add(para_5); Paragraph para_6 = new Paragraph("" + person.birthdayProperty().get(), font_underline_11); para_6.setAlignment(0); doc.add(para_6); Table karteHistoryTable = new Table(5); karteHistoryTable.setWidth(100.0F); int[] uriage_table_width = { 25, 20, 30, 20, 25 }; karteHistoryTable.setWidths(uriage_table_width); //karteHistoryTable.setDefaultHorizontalAlignment(1); //karteHistoryTable.setDefaultVerticalAlignment(5); karteHistoryTable.setPadding(3.0F); karteHistoryTable.setSpacing(0.0F); karteHistoryTable.setBorderColor(new Color(0, 0, 0)); Cell cell_01 = new Cell(new Phrase("?", font_g10)); cell_01.setGrayFill(0.8F); cell_01.setHorizontalAlignment(Element.ALIGN_CENTER); Cell cell_11 = new Cell(new Phrase("?", font_g10)); cell_11.setGrayFill(0.8F); cell_11.setHorizontalAlignment(Element.ALIGN_CENTER); Cell cell_21 = new Cell(new Phrase("", font_g10)); cell_21.setGrayFill(0.8F); cell_21.setHorizontalAlignment(Element.ALIGN_CENTER); Cell cell_31 = new Cell(new Phrase("", font_g10)); cell_31.setGrayFill(0.8F); cell_31.setHorizontalAlignment(Element.ALIGN_CENTER); Cell cell_41 = new Cell(new Phrase("", font_g10)); cell_41.setGrayFill(0.8F); cell_41.setHorizontalAlignment(Element.ALIGN_CENTER); karteHistoryTable.addCell(cell_01); karteHistoryTable.addCell(cell_11); karteHistoryTable.addCell(cell_21); karteHistoryTable.addCell(cell_31); karteHistoryTable.addCell(cell_41); List<KarteBean> list = bean.getResult(); KarteBean karteInfo = list.get(0); List<DocInfoModel> docInfoList = karteInfo.getDocInfoList(); //- ??? int stepCount = 22; int tempCount = 0; int pageCount = 0; String firstKarteMaker = null; String karteMakeDate = null; if (docInfoList != null) { for (int i = 0; i < docInfoList.size(); ++i) { DocInfoModel docInfo = docInfoList.get(i); Cell cell = new Cell(new Phrase(docInfo.getFirstConfirmDateTime(), font_m8)); if (karteMakeDate == null || !karteMakeDate.equals(docInfo.getFirstConfirmDateTime())) { karteMakeDate = docInfo.getFirstConfirmDateTime(); firstKarteMaker = docInfo.getPurpose(); } cell.setHorizontalAlignment(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); karteHistoryTable.addCell(cell); cell = new Cell(new Phrase(firstKarteMaker, font_m8)); cell.setHorizontalAlignment(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); karteHistoryTable.addCell(cell); //- String addTitle = docInfo.getTitle(); addTitle = addTitle.replace("\r\n", ""); addTitle = addTitle.replace("\n", ""); cell = new Cell(new Phrase(addTitle, font_m8)); cell.setHorizontalAlignment(0); karteHistoryTable.addCell(cell); cell = new Cell(new Phrase(docInfo.getPurpose(), font_m8)); cell.setHorizontalAlignment(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); karteHistoryTable.addCell(cell); cell = new Cell(new Phrase(docInfo.getConfirmDateTime(), font_m8)); cell.setHorizontalAlignment(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); karteHistoryTable.addCell(cell); if (stepCount == tempCount) { if (pageCount == 0) { stepCount += 5; pageCount++; } tempCount = 0; doc.add(karteHistoryTable); doc.newPage(); karteHistoryTable.deleteAllRows(); karteHistoryTable.addCell(cell_01); karteHistoryTable.addCell(cell_11); karteHistoryTable.addCell(cell_21); karteHistoryTable.addCell(cell_31); karteHistoryTable.addCell(cell_41); } else { tempCount++; } } // Cell Empty_Cell = new Cell(new Phrase("empty", font_empty)); // for (int i = docInfoList.size(); i < docInfoList.size() + 4; ++i) { // for (int j = 0; j < 4; ++j) { // karteHistoryTable.addCell(Empty_Cell); // } // } // // Cell cell_goukei = new Cell(new Phrase("?", font_g10)); // cell_goukei.setGrayFill(0.8F); // cell_goukei.setColspan(3); // karteHistoryTable.addCell(cell_goukei); // Cell cell_sum = new Cell(new Phrase("136,900", font_m10)); // cell_sum.setHorizontalAlignment(2); // karteHistoryTable.addCell(cell_sum); doc.add(karteHistoryTable); doc.newPage(); } else { // doc.add(para_NF); Paragraph noData = new Paragraph("??", font_m8); noData.setAlignment(0); doc.add(noData); doc.newPage(); } } } catch (DocumentException | IOException e) { Logger.getLogger(AuditController.class.getName()).log(Level.SEVERE, null, e); } finally { doc.close(); } }
From source file:org.displaytag.export.PdfView.java
License:Artistic License
/** * @see org.displaytag.export.BinaryExportView#doExport(OutputStream) *///from w ww .jav a 2s .c o m public void doExport(OutputStream out) throws JspException { try { // Initialize the table with the appropriate number of columns initTable(); // Initialize the Document and register it with PdfWriter listener and the OutputStream Document document = new Document(PageSize.A4.rotate(), 60, 60, 40, 40); document.addCreationDate(); HeaderFooter footer = new HeaderFooter(new Phrase(TagConstants.EMPTY_STRING, smallFont), true); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); PdfWriter.getInstance(document, out); // Fill the virtual PDF table with the necessary data generatePDFTable(); document.open(); document.setFooter(footer); document.add(this.tablePDF); document.close(); } catch (Exception e) { throw new PdfGenerationException(e); } }
From source file:org.drools.verifier.doc.DroolsDocsComponentFactory.java
License:Apache License
public static HeaderFooter createFooter(String packageName) { HeaderFooter footer = new HeaderFooter(new Phrase(packageName + "-", HEADER_FOOTER_TEXT), true); footer.setBorder(1);//w w w. j av a 2 s. c om footer.setAlignment(Element.ALIGN_RIGHT); return footer; }
From source file:org.egov.infra.web.displaytag.export.EGovPdfView.java
License:Open Source License
@Override public void doExport(final OutputStream out) throws JspException { try {/*from w ww .j a va2 s . co m*/ // Initialize the table with the appropriate number of columns initTable(); // Initialize the Document and register it with PdfWriter listener and the OutputStream final Document document = new Document(PageSize.A4.rotate(), 60, 60, 40, 40); document.addCreationDate(); final HeaderFooter footer = new HeaderFooter(new Phrase(TagConstants.TAGNAME_CAPTION, this.smallFont), true); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); // PdfWriter.getInstance(document, out); PdfWriter.getInstance(document, out).setPageEvent(new PageNumber()); // Fill the virtual PDF table with the necessary data generatePDFTable(); document.open(); // Table table = new Table(this.model.getNumberOfColumns()); // ItextTableWriter writer = new ItextTableWriter(tablePDF, document); // writer.writeTable(this.model, "-1"); // document.setFooter(footer); // document.setHeader(footer); document.add(this.tableCaption); document.add(this.tablePDF); document.close(); } catch (final Exception e) { throw new PdfGenerationException(e); } }
From source file:org.gtdfree.addons.PDFExportAddOn.java
License:Open Source License
@Override public void export(GTDModel model, ActionsCollection collection, OutputStream out, ExportAddOn.ExportOrder order, FileFilter ff, boolean compact) throws Exception { fontSelector = new FontSelector(); fontSelectorB = new FontSelector(); fontSelectorB2 = new FontSelector(); fontSelectorB4 = new FontSelector(); baseFont = fontModel.getBaseFont();/*from ww w.j av a 2 s. c o m*/ for (BaseFont bf : fontModel.getFonts()) { fontSelector.addFont(new Font(bf, baseFontSize)); fontSelectorB.addFont(new Font(bf, baseFontSize, Font.BOLD)); fontSelectorB2.addFont(new Font(bf, baseFontSize + 2, Font.BOLD)); fontSelectorB4.addFont(new Font(bf, baseFontSize + 4, Font.BOLD)); } boolean emptyH2 = false; boolean emptyH3 = false; PdfPTable actionTable = null; Document doc = new Document(); if (sizeSet) { doc.setPageSize(pageSize); } if (marginSet) { doc.setMargins(marginLeft, marginRight, marginTop, marginBottom); } //System.out.println("PDF size "+doc.getPageSize().toString()); //System.out.println("PDF m "+marginLeft+" "+marginRight+" "+marginTop+" "+marginBottom); @SuppressWarnings("unused") PdfWriter pw = PdfWriter.getInstance(doc, out); doc.addCreationDate(); doc.addTitle("GTD-Free PDF"); doc.addSubject("GTD-Free data exported as PDF"); HeaderFooter footer = new HeaderFooter(newParagraph(), true); footer.setAlignment(HeaderFooter.ALIGN_CENTER); footer.setBorder(HeaderFooter.TOP); doc.setFooter(footer); doc.open(); Phrase ch = newTitle("GTD-Free Data"); Paragraph p = new Paragraph(ch); p.setAlignment(Paragraph.ALIGN_CENTER); PdfPTable t = new PdfPTable(1); t.setWidthPercentage(100f); PdfPCell c = newCell(p); c.setBorder(Table.BOTTOM); c.setBorderWidth(2.5f); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setPadding(5f); t.addCell(c); doc.add(t); Iterator<Object> it = collection.iterator(order); while (it.hasNext()) { Object o = it.next(); if (o == ActionsCollection.ACTIONS_WITHOUT_PROJECT) { if (order == ExportAddOn.ExportOrder.FoldersProjectsActions) { doc.add(newSubSection(ActionsCollection.ACTIONS_WITHOUT_PROJECT)); emptyH2 = false; emptyH3 = true; } else { doc.add(newSection(ActionsCollection.ACTIONS_WITHOUT_PROJECT)); emptyH2 = true; emptyH3 = false; } continue; } if (o instanceof Folder) { Folder f = (Folder) o; if (actionTable != null) { doc.add(actionTable); actionTable = null; } if (f.isProject()) { if (order == ExportAddOn.ExportOrder.ProjectsActions || order == ExportAddOn.ExportOrder.ProjectsFoldersActions) { if (emptyH2 || emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } doc.add(newSection(f.getName())); if (compact) { if (f.getDescription() != null && f.getDescription().length() > 0) { p = newParagraph(f.getDescription()); p.setIndentationLeft(10f); p.setIndentationRight(10f); doc.add(p); } } else { t = new PdfPTable(2); t.setKeepTogether(true); t.setSpacingBefore(5f); t.setWidthPercentage(66f); t.setWidths(new float[] { 0.33f, 0.66f }); c = newCell("ID"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.getId()))); t.addCell(c); c = newCell("Type"); t.addCell(c); c = newCell(newStrongParagraph("Project")); t.addCell(c); c = newCell("Open"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.getOpenCount()))); t.addCell(c); c = newCell("All"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.size()))); t.addCell(c); c = newCell("Description"); t.addCell(c); c = newDescriptionCell(f.getDescription()); t.addCell(c); doc.add(t); } emptyH2 = true; emptyH3 = false; } else { if (emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } doc.add(newSubSection("Project:" + " " + f.getName())); emptyH2 = false; emptyH3 = true; } continue; } if (order == ExportAddOn.ExportOrder.FoldersActions || order == ExportAddOn.ExportOrder.FoldersProjectsActions) { if (emptyH2 || emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } doc.add(newSection(f.getName())); if (compact) { if (f.getDescription() != null && f.getDescription().length() > 0) { p = newParagraph(f.getDescription()); p.setIndentationLeft(10f); p.setIndentationRight(10f); doc.add(p); } } else { t = new PdfPTable(2); t.setKeepTogether(true); t.setSpacingBefore(5f); t.setWidthPercentage(66f); t.setWidths(new float[] { 0.33f, 0.66f }); c = newCell("ID"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.getId()))); t.addCell(c); String type = ""; if (f.isAction()) { type = "Action list"; } else if (f.isInBucket()) { type = "In-Bucket"; } else if (f.isQueue()) { type = "Next action queue"; } else if (f.isReference()) { type = "Reference list"; } else if (f.isSomeday()) { type = "Someday/Maybe list"; } else if (f.isBuildIn()) { type = "Default list"; } c = newCell("Type"); t.addCell(c); c = newCell(newStrongParagraph(type)); t.addCell(c); c = newCell("Open"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.getOpenCount()))); t.addCell(c); c = newCell("All"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.size()))); t.addCell(c); c = newCell("Description"); t.addCell(c); c = newDescriptionCell(f.getDescription()); t.addCell(c); doc.add(t); } emptyH2 = true; emptyH3 = false; } else { if (emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } doc.add(newSubSection("List:" + " " + f.getName())); emptyH2 = false; emptyH3 = true; } continue; } if (o instanceof Action) { emptyH2 = false; emptyH3 = false; Action a = (Action) o; if (compact) { if (actionTable == null) { actionTable = new PdfPTable(5); actionTable.setWidthPercentage(100f); actionTable.setHeaderRows(1); actionTable.setSpacingBefore(5f); c = newHeaderCell("ID"); actionTable.addCell(c); c = newHeaderCell("Pri."); actionTable.addCell(c); c = newHeaderCell("Description"); actionTable.addCell(c); c = newHeaderCell("Reminder"); actionTable.addCell(c); c = newHeaderCell(CHECK_RESOLVED); actionTable.addCell(c); float width = doc.getPageSize().getWidth() - doc.getPageSize().getBorderWidthLeft() - doc.getPageSize().getBorderWidthRight(); int i = model.getLastActionID(); float step = baseFontSize - 1; int steps = (int) Math.floor(Math.log10(i)) + 1; // ID column float col1 = 8 + steps * step; // Priority column float col2 = 4 + 3 * (baseFontSize + 4); // Reminder column float col4 = 10 + step * 11; // Resolved column float col5 = 8 + baseFontSize; // Description column float col3 = width - col1 - col2 - col4 - col5; actionTable.setWidths(new float[] { col1, col2, col3, col4, col5 }); } addSingleActionRow(a, actionTable); } else { addSingleActionTable(model, doc, a); } } } if (actionTable != null) { doc.add(actionTable); actionTable = null; } if (emptyH2 || emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } //w.writeCharacters("Exported: "+ApplicationHelper.toISODateTimeString(new Date())); doc.close(); }
From source file:org.jsondoc.springmvc.pdf.PdfExportView.java
License:Open Source License
public File getPdfFile(String filename) { try {//from w w w.j a v a2 s. c o m File file = new File(filename + "-v" + jsonDoc.getVersion() + FILE_EXTENSION); FileOutputStream fileout = new FileOutputStream(file); Document document = new Document(); PdfWriter.getInstance(document, fileout); // Header HeaderFooter header = new HeaderFooter(new Phrase("Copyright " + Calendar.getInstance().get(Calendar.YEAR) + " Paybay Networks - All rights reserved"), false); header.setBorder(Rectangle.NO_BORDER); header.setAlignment(Element.ALIGN_LEFT); document.setHeader(header); // Footer HeaderFooter footer = new HeaderFooter(new Phrase("Page "), true); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); document.setFooter(footer); document.open(); //init documentation apiDocs = buildApiDocList(); apiMethodDocs = buildApiMethodDocList(apiDocs); Phrase baseUrl = new Phrase("Base url: " + jsonDoc.getBasePath()); document.add(baseUrl); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); int pos = 1; for (ApiMethodDoc apiMethodDoc : apiMethodDocs) { Phrase phrase = new Phrase(/*"Description: " + */apiMethodDoc.getDescription()); document.add(phrase); document.add(Chunk.NEWLINE); PdfPTable table = new PdfPTable(2); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.setWidthPercentage(100); table.setWidths(new int[] { 50, 200 }); // HEADER CELL START TABLE table.addCell(ITextUtils.getHeaderCell("URL")); table.addCell(ITextUtils.getHeaderCell("<baseUrl> " + apiMethodDoc.getPath())); table.completeRow(); // FIRST CELL table.addCell(ITextUtils.getCell("Http Method", 0)); table.addCell(ITextUtils.getCell(apiMethodDoc.getVerb().name(), pos)); pos++; table.completeRow(); // PRODUCES if (!apiMethodDoc.getProduces().isEmpty()) { table.addCell(ITextUtils.getCell("Produces", 0)); table.addCell(ITextUtils.getCell(buildApiMethodProduces(apiMethodDoc), pos)); pos++; table.completeRow(); } // CONSUMES if (!apiMethodDoc.getConsumes().isEmpty()) { table.addCell(ITextUtils.getCell("Consumes", 0)); table.addCell(ITextUtils.getCell(buildApiMethodConsumes(apiMethodDoc), pos)); pos++; table.completeRow(); } // HEADERS if (!apiMethodDoc.getHeaders().isEmpty()) { table.addCell(ITextUtils.getCell("Request headers", 0)); PdfPTable pathParamsTable = new PdfPTable(3); pathParamsTable.setWidths(new int[] { 30, 20, 40 }); pathParamsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); pathParamsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); for (ApiHeaderDoc apiHeaderDoc : apiMethodDoc.getHeaders()) { PdfPCell boldCell = new PdfPCell(); Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD); boldCell.setPhrase(new Phrase(apiHeaderDoc.getName(), fontbold)); boldCell.getPhrase().setFont(new Font(Font.BOLD)); boldCell.setBorder(Rectangle.NO_BORDER); pathParamsTable.addCell(boldCell); PdfPCell paramCell = new PdfPCell(); StringBuilder builder = new StringBuilder(); for (String value : apiHeaderDoc.getAllowedvalues()) builder.append(value).append(", "); paramCell.setPhrase(new Phrase("Allowed values: " + builder.toString())); paramCell.setBorder(Rectangle.NO_BORDER); pathParamsTable.addCell(paramCell); paramCell.setPhrase(new Phrase(apiHeaderDoc.getDescription())); pathParamsTable.addCell(paramCell); pathParamsTable.completeRow(); } PdfPCell bluBorderCell = new PdfPCell(pathParamsTable); bluBorderCell.setBorder(Rectangle.NO_BORDER); bluBorderCell.setBorderWidthRight(1f); bluBorderCell.setBorderColorRight(Colors.CELL_BORDER_COLOR); table.addCell(ITextUtils.setOddEvenStyle(bluBorderCell, pos)); pos++; table.completeRow(); } // PATH PARAMS if (!apiMethodDoc.getPathparameters().isEmpty()) { table.addCell(ITextUtils.getCell("Path params", 0)); PdfPTable pathParamsTable = new PdfPTable(3); pathParamsTable.setWidths(new int[] { 30, 15, 40 }); pathParamsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); pathParamsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); for (ApiParamDoc apiParamDoc : apiMethodDoc.getPathparameters()) { PdfPCell boldCell = new PdfPCell(); Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD); boldCell.setPhrase(new Phrase(apiParamDoc.getName(), fontbold)); boldCell.getPhrase().setFont(new Font(Font.BOLD)); boldCell.setBorder(Rectangle.NO_BORDER); pathParamsTable.addCell(boldCell); PdfPCell paramCell = new PdfPCell(); paramCell.setPhrase(new Phrase(apiParamDoc.getJsondocType().getOneLineText())); paramCell.setBorder(Rectangle.NO_BORDER); pathParamsTable.addCell(paramCell); paramCell.setPhrase(new Phrase(apiParamDoc.getDescription())); pathParamsTable.addCell(paramCell); pathParamsTable.completeRow(); } PdfPCell bluBorderCell = new PdfPCell(pathParamsTable); bluBorderCell.setBorder(Rectangle.NO_BORDER); bluBorderCell.setBorderWidthRight(1f); bluBorderCell.setBorderColorRight(Colors.CELL_BORDER_COLOR); table.addCell(ITextUtils.setOddEvenStyle(bluBorderCell, pos)); pos++; table.completeRow(); } // QUERY PARAMS if (!apiMethodDoc.getQueryparameters().isEmpty()) { table.addCell(ITextUtils.getCell("Query params", 0)); PdfPTable queryParamsTable = new PdfPTable(3); queryParamsTable.setWidths(new int[] { 30, 15, 40 }); queryParamsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); queryParamsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); for (ApiParamDoc apiParamDoc : apiMethodDoc.getQueryparameters()) { PdfPCell boldCell = new PdfPCell(); Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD); boldCell.setPhrase(new Phrase(apiParamDoc.getName(), fontbold)); boldCell.getPhrase().setFont(new Font(Font.BOLD)); boldCell.setBorder(Rectangle.NO_BORDER); queryParamsTable.addCell(boldCell); PdfPCell paramCell = new PdfPCell(); paramCell.setPhrase(new Phrase(apiParamDoc.getJsondocType().getOneLineText())); paramCell.setBorder(Rectangle.NO_BORDER); queryParamsTable.addCell(paramCell); paramCell.setPhrase(new Phrase( apiParamDoc.getDescription() + ", mandatory: " + apiParamDoc.getRequired())); queryParamsTable.addCell(paramCell); queryParamsTable.completeRow(); } PdfPCell bluBorderCell = new PdfPCell(queryParamsTable); bluBorderCell.setBorder(Rectangle.NO_BORDER); bluBorderCell.setBorderWidthRight(1f); bluBorderCell.setBorderColorRight(Colors.CELL_BORDER_COLOR); table.addCell(ITextUtils.setOddEvenStyle(bluBorderCell, pos)); pos++; table.completeRow(); } // BODY OBJECT if (null != apiMethodDoc.getBodyobject()) { table.addCell(ITextUtils.getCell("Body object:", 0)); String jsonObject = buildJsonFromTemplate(apiMethodDoc.getBodyobject().getJsondocTemplate()); table.addCell(ITextUtils.getCell(jsonObject, pos)); pos++; table.completeRow(); } // RESPONSE OBJECT table.addCell(ITextUtils.getCell("Json response:", 0)); table.addCell( ITextUtils.getCell(apiMethodDoc.getResponse().getJsondocType().getOneLineText(), pos)); pos++; table.completeRow(); // RESPONSE STATUS CODE table.addCell(ITextUtils.getCell("Status code:", 0)); table.addCell(ITextUtils.getCell(apiMethodDoc.getResponsestatuscode(), pos)); pos++; table.completeRow(); table.setSpacingAfter(10f); table.setSpacingBefore(5f); document.add(table); } document.close(); return file; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } return null; }
From source file:org.kuali.coeus.common.impl.print.PrintingServiceImpl.java
License:Open Source License
/** * @param pdfBytesList List containing the PDF data bytes * @param bookmarksList List of bookmarks corresponding to the PDF bytes. * @return/*w ww .j ava 2s .c om*/ * @throws PrintingException */ protected byte[] mergePdfBytes(List<byte[]> pdfBytesList, List<String> bookmarksList, boolean headerFooterRequired) throws PrintingException { Document document = null; PdfWriter writer = null; ByteArrayOutputStream mergedPdfReport = new ByteArrayOutputStream(); int totalNumOfPages = 0; PdfReader[] pdfReaderArr = new PdfReader[pdfBytesList.size()]; int pdfReaderCount = 0; for (byte[] fileBytes : pdfBytesList) { LOG.debug("File Size " + fileBytes.length + " For " + bookmarksList.get(pdfReaderCount)); PdfReader reader = null; try { reader = new PdfReader(fileBytes); pdfReaderArr[pdfReaderCount] = reader; pdfReaderCount = pdfReaderCount + 1; totalNumOfPages += reader.getNumberOfPages(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } HeaderFooter footer = null; if (headerFooterRequired) { Calendar calendar = dateTimeService.getCurrentCalendar(); String dateString = formateCalendar(calendar); StringBuilder footerPhStr = new StringBuilder(); footerPhStr.append(" of "); footerPhStr.append(totalNumOfPages); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76)); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76)); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_60)); footerPhStr.append(dateString); Font font = FontFactory.getFont(FontFactory.TIMES, 8, Font.NORMAL, Color.BLACK); Phrase beforePhrase = new Phrase("Page ", font); Phrase afterPhrase = new Phrase(footerPhStr.toString(), font); footer = new HeaderFooter(beforePhrase, afterPhrase); footer.setAlignment(Element.ALIGN_BASELINE); footer.setBorderWidth(0f); } for (int count = 0; count < pdfReaderArr.length; count++) { PdfReader reader = pdfReaderArr[count]; int nop; if (reader == null) { LOG.debug("Empty PDF byetes found for " + bookmarksList.get(count)); continue; } else { nop = reader.getNumberOfPages(); } if (count == 0) { document = nop > 0 ? new com.lowagie.text.Document(reader.getPageSizeWithRotation(1)) : new com.lowagie.text.Document(); try { writer = PdfWriter.getInstance(document, mergedPdfReport); } catch (DocumentException e) { LOG.error(e.getMessage(), e); throw new PrintingException(e.getMessage(), e); } if (footer != null) { document.setFooter(footer); } // writer.setPageEvent(new Watermark()); // add watermark object here document.open(); } PdfContentByte cb = writer.getDirectContent(); int pageCount = 0; while (pageCount < nop) { document.setPageSize(reader.getPageSize(++pageCount)); document.newPage(); if (footer != null) { document.setFooter(footer); } PdfImportedPage page = writer.getImportedPage(reader, pageCount); cb.addTemplate(page, 1, 0, 0, 1, 0, 0); PdfOutline root = cb.getRootOutline(); if (pageCount == 1) { String pageName = bookmarksList.get(count); cb.addOutline(new PdfOutline(root, new PdfDestination(PdfDestination.FITH), pageName), pageName); } } } if (document != null) { try { document.close(); return mergedPdfReport.toByteArray(); } catch (Exception e) { LOG.error("Exception occured because the generated PDF document has no pages", e); } } return null; }
From source file:org.kuali.coeus.s2sgen.impl.print.S2SPrintingServiceImpl.java
License:Educational Community License
/** * @param pdfBytesList List containing the PDF data bytes * @param bookmarksList List of bookmarks corresponding to the PDF bytes. *//*from w ww . j a v a 2 s . c o m*/ protected byte[] mergePdfBytes(List<byte[]> pdfBytesList, List<String> bookmarksList, boolean headerFooterRequired) { Document document = null; PdfWriter writer = null; ByteArrayOutputStream mergedPdfReport = new ByteArrayOutputStream(); int totalNumOfPages = 0; PdfReader[] pdfReaderArr = new PdfReader[pdfBytesList.size()]; int pdfReaderCount = 0; for (byte[] fileBytes : pdfBytesList) { LOG.debug("File Size " + fileBytes.length + " For " + bookmarksList.get(pdfReaderCount)); PdfReader reader = null; try { reader = new PdfReader(fileBytes); pdfReaderArr[pdfReaderCount] = reader; pdfReaderCount = pdfReaderCount + 1; totalNumOfPages += reader.getNumberOfPages(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } HeaderFooter footer = null; if (headerFooterRequired) { Calendar calendar = Calendar.getInstance(); String dateString = formateCalendar(calendar); StringBuilder footerPhStr = new StringBuilder(); footerPhStr.append(" of "); footerPhStr.append(totalNumOfPages); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76)); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76)); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_60)); footerPhStr.append(dateString); Font font = FontFactory.getFont(FontFactory.TIMES, 8, Font.NORMAL, Color.BLACK); Phrase beforePhrase = new Phrase("Page ", font); Phrase afterPhrase = new Phrase(footerPhStr.toString(), font); footer = new HeaderFooter(beforePhrase, afterPhrase); footer.setAlignment(Element.ALIGN_BASELINE); footer.setBorderWidth(0f); } for (int count = 0; count < pdfReaderArr.length; count++) { PdfReader reader = pdfReaderArr[count]; int nop; if (reader == null) { LOG.debug("Empty PDF byetes found for " + bookmarksList.get(count)); continue; } else { nop = reader.getNumberOfPages(); } if (count == 0) { document = nop > 0 ? new Document(reader.getPageSizeWithRotation(1)) : new Document(); try { writer = PdfWriter.getInstance(document, mergedPdfReport); } catch (DocumentException e) { LOG.error(e.getMessage(), e); throw new S2SException(e.getMessage(), e); } if (footer != null) { document.setFooter(footer); } document.open(); } PdfContentByte cb = writer.getDirectContent(); int pageCount = 0; while (pageCount < nop) { document.setPageSize(reader.getPageSize(++pageCount)); document.newPage(); if (footer != null) { document.setFooter(footer); } PdfImportedPage page = writer.getImportedPage(reader, pageCount); cb.addTemplate(page, 1, 0, 0, 1, 0, 0); PdfOutline root = cb.getRootOutline(); if (pageCount == 1) { String pageName = bookmarksList.get(count); cb.addOutline(new PdfOutline(root, new PdfDestination(PdfDestination.FITH), pageName), pageName); } } } if (document != null) { try { document.close(); return mergedPdfReport.toByteArray(); } catch (Exception e) { LOG.error("Exception occured because the generated PDF document has no pages", e); } } return null; }
From source file:org.kuali.kfs.module.endow.report.util.TransactionSummaryReportPrint.java
License:Educational Community License
/** * Generates the report in PDF using iText * /*from w w w.j a v a 2 s. co m*/ * @param reportRequestHeaderDataHolder * @param transactionStatementDataReportHolders * @return pdfStream */ public ByteArrayOutputStream printTransactionSummaryReport( EndowmentReportHeaderDataHolder reportRequestHeaderDataHolder, List<TransactionSummaryReportDataHolder> transactionSummaryDataReportHolders, String listKemidsInHeader, String reportOption, String summaryTotalsOnly) { Document document = new Document(); document.setPageSize(LETTER_PORTRAIT); document.addTitle("Endowment Transaction Summary"); ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); try { PdfWriter.getInstance(document, pdfStream); document.open(); // page HeaderFooter header = new HeaderFooter(new Phrase(new Date().toString() + " Page: ", headerFont), true); header.setBorder(Rectangle.NO_BORDER); header.setAlignment(Element.ALIGN_RIGHT); header.setPageNumber(0); document.setHeader(header); // print the report header if (printReportHeaderPage(reportRequestHeaderDataHolder, document, listKemidsInHeader)) { if (transactionSummaryDataReportHolders != null && transactionSummaryDataReportHolders.size() > 0) { if ("Y".equalsIgnoreCase(summaryTotalsOnly)) { printReportBodyBySummaryTotals(transactionSummaryDataReportHolders, document, reportOption); } else { printReportBodyByAllTotals(transactionSummaryDataReportHolders, document, reportOption); } } } else { LOG.error("Transaction Summary Report Header Error"); } document.close(); } catch (Exception e) { LOG.error("PDF Error: " + e.getMessage()); return null; } return pdfStream; }