List of usage examples for com.lowagie.text PageSize A4
Rectangle A4
To view the source code for com.lowagie.text PageSize A4.
Click Source Link
From source file:org.sonar.report.pdf.Toc.java
License:Open Source License
public Toc() { toc = new Document(PageSize.A4, 50, 50, 110, 50); content = new PdfPTable(2); Rectangle page = toc.getPageSize(); content.setTotalWidth(page.getWidth() - toc.leftMargin() - toc.rightMargin()); content.getDefaultCell().setUseVariableBorders(true); content.getDefaultCell().setBorderColorBottom(Color.WHITE); content.getDefaultCell().setBorderColorRight(Color.WHITE); content.getDefaultCell().setBorderColorLeft(Color.WHITE); content.getDefaultCell().setBorderColorTop(Color.WHITE); content.getDefaultCell().setBorderWidthBottom(2f); }
From source file:org.tn5250j.spoolfile.SpoolExportWizard.java
License:Open Source License
/** * Open the correct type of output file depending on selection(s) *///from w ww . j av a 2 s .c om public void openOutputFile() { try { // update status updateStatus("Opening File"); // default to txt extention String suffix = ".txt"; String fileName = ""; // if pdf then change to pdf extenstion if (cvtType.getSelectedIndex() == 0) suffix = ".pdf"; // for e-mailing setup a temporary file if (email.isSelected()) { File dir = new File(System.getProperty("user.dir")); // setup the temp file name String tempFile = spooledFile.getText().trim() + '_' + jobName.getText().trim() + '_' + user.getText().trim() + '_' + spooledFileNumber.getText().trim() + '_' + number.getText().trim(); // create the temporary file File f = File.createTempFile(tempFile, suffix, dir); System.out.println(f.getName()); System.out.println(f.getCanonicalPath()); conicalPath = f.getCanonicalPath(); // set it to delete on exit f.deleteOnExit(); // create the file fw = new FileOutputStream(f); } else if (ifs.isSelected()) { fileName = ifsPathInfo.getText().trim(); ifsfw = new IFSFileOutputStream(splfile.getSystem(), fileName); } else { fileName = pcPathInfo.getText().trim(); fw = new FileOutputStream(fileName); } // if not PDF then this is all we have to do so return if (cvtType.getSelectedIndex() > 0) return; // On pdf's then we need to create a PDF document if (document == null) { document = new Document(); // create the pdf writer based on selection of pc or ifs file if (ifs.isSelected()) { bos = PdfWriter.getInstance(document, ifsfw); } else { bos = PdfWriter.getInstance(document, fw); } // create the base font BaseFont bf = BaseFont.createFont("Courier", "Cp1252", false); // set the default size of the font to 9.0 float fontsize = 9.0f; // if we have a font selectd then try to use it if (fontSize.getText().length() > 0) fontsize = Float.parseFloat(fontSize.getText().trim()); // create the pdf font to use within the document font = new com.lowagie.text.Font(bf, fontsize, com.lowagie.text.Font.NORMAL); // set the PDF properties of the supplied properties if (author.getText().length() > 0) document.addAuthor(author.getText()); if (title.getText().length() > 0) document.addTitle(title.getText()); if (subject.getText().length() > 0) document.addSubject(subject.getText()); // set the page sizes and the page orientation String ps = (String) pageSize.getSelectedItem(); if (ps.equals("A3")) { if (portrait.isSelected()) document.setPageSize(PageSize.A3); else document.setPageSize(PageSize.A3.rotate()); } if (ps.equals("A4")) { if (portrait.isSelected()) document.setPageSize(PageSize.A4); else document.setPageSize(PageSize.A4.rotate()); } if (ps.equals("A5")) { if (portrait.isSelected()) document.setPageSize(PageSize.A5); else document.setPageSize(PageSize.A5.rotate()); } if (ps.equals("LETTER")) { if (portrait.isSelected()) document.setPageSize(PageSize.LETTER); else document.setPageSize(PageSize.LETTER.rotate()); } if (ps.equals("LEGAL")) { if (portrait.isSelected()) document.setPageSize(PageSize.LEGAL); else document.setPageSize(PageSize.LEGAL.rotate()); } if (ps.equals("LEDGER")) { if (portrait.isSelected()) document.setPageSize(PageSize.LEDGER); else document.setPageSize(PageSize.LEDGER.rotate()); } } } catch (IOException _ex) { System.out.println("Cannot open 1 " + _ex.getMessage()); } catch (Exception _ex2) { System.out.println("Cannot open 2 " + _ex2.getMessage()); } }
From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java
License:Open Source License
public void pdfTableForInstructionalOffering(OutputStream out, ClassAssignmentProxy classAssignment, ExamAssignmentProxy examAssignment, Long instructionalOfferingId, SessionContext context, Comparator classComparator) throws Exception { if (instructionalOfferingId != null && context != null) { InstructionalOfferingDAO idao = new InstructionalOfferingDAO(); InstructionalOffering io = idao.get(instructionalOfferingId); Long subjectAreaId = io.getControllingCourseOffering().getSubjectArea().getUniqueId(); // Get Configuration TreeSet ts = new TreeSet(); ts.add(io);// w w w.ja va2 s.c o m WebInstructionalOfferingTableBuilder iotbl = new WebInstructionalOfferingTableBuilder(); iotbl.setDisplayDistributionPrefs(false); setVisibleColumns(COLUMNS); iDocument = new Document(PageSize.A4, 30f, 30f, 30f, 30f); iWriter = PdfEventHandler.initFooter(iDocument, out); pdfTableForInstructionalOfferings(out, classAssignment, examAssignment, ts, subjectAreaId, context, false, false, classComparator); iDocument.close(); } }
From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java
License:Open Source License
public void pdfTableForInstructionalOfferings(OutputStream out, ClassAssignmentProxy classAssignment, ExamAssignmentProxy examAssignment, InstructionalOfferingListForm form, String[] subjectAreaIds, SessionContext context, boolean displayHeader, boolean allCoursesAreGiven) throws Exception { setVisibleColumns(form);/*from ww w .j a v a2s .c o m*/ iDocument = new Document(PageSize.A4, 30f, 30f, 30f, 30f); iWriter = PdfEventHandler.initFooter(iDocument, out); for (String subjectAreaId : subjectAreaIds) { pdfTableForInstructionalOfferings(out, classAssignment, examAssignment, form.getInstructionalOfferings(Long.valueOf(subjectAreaId)), Long.valueOf(subjectAreaId), context, displayHeader, allCoursesAreGiven, new ClassCourseComparator(form.getSortBy(), classAssignment, false)); } iDocument.close(); }
From source file:org.webguitoolkit.ui.util.export.PDFTableExport.java
License:Apache License
public void writeTo(Table table, OutputStream out) { TableExportOptions exportOptions = table.getExportOptions(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); // set the page orientation Din-A4 Portrait or Landscape Rectangle page = PageSize.A4; if (exportOptions.getPdfPosition() != null && exportOptions.getPdfPosition().equals(TableExportOptions.PDF_LANDSCAPE)) { // landscape position page = PageSize.A4.rotate();//from w ww . ja va 2 s . c o m } else if (exportOptions.getPdfPosition() != null && exportOptions.getPdfPosition().equals(TableExportOptions.PDF_PORTRAIT)) { // portrait position page = PageSize.A4; } if (exportOptions.getPdfPageColour() != null) { // page.setBackgroundColor(exportOptions.getPdfPageColour()); } Document document = new Document(page); document.setMargins(36f, 36f, 50f, 40f); try { PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new PDFEvent(table)); document.open(); if (StringUtils.isNotEmpty(exportOptions.getHeadline())) { Font titleFont = new Font(Font.UNDEFINED, 18, Font.BOLD); Paragraph paragraph = new Paragraph(exportOptions.getHeadline(), titleFont); paragraph.setAlignment(Element.ALIGN_CENTER); document.add(paragraph); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); } PdfPTable pdftable = pdfExport(table); document.add(pdftable); document.newPage(); document.close(); baos.writeTo(out); out.flush(); baos.close(); } catch (DocumentException e) { logger.error("Error creating document!", e); throw new RuntimeException(e); } catch (IOException e) { logger.error("Error creating document!", e); throw new RuntimeException(e); } finally { } }
From source file:oscar.form.pdfservlet.FrmCustomedPDFServlet.java
License:Open Source License
protected ByteArrayOutputStream generatePDFDocumentBytes(final HttpServletRequest req, final ServletContext ctx) throws DocumentException { logger.debug("***in generatePDFDocumentBytes2 FrmCustomedPDFServlet.java***"); // added by vic, hsfo Enumeration<String> em = req.getParameterNames(); while (em.hasMoreElements()) { logger.debug("para=" + em.nextElement()); }//from w ww. j a va 2s. c o m em = req.getAttributeNames(); while (em.hasMoreElements()) logger.debug("attr: " + em.nextElement()); if (HSFO_RX_DATA_KEY.equals(req.getParameter("__title"))) { return generateHsfoRxPDF(req); } String newline = System.getProperty("line.separator"); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter writer = null; String method = req.getParameter("__method"); String origPrintDate = null; String numPrint = null; if (method != null && method.equalsIgnoreCase("rePrint")) { origPrintDate = req.getParameter("origPrintDate"); numPrint = req.getParameter("numPrints"); } logger.debug("method in generatePDFDocumentBytes " + method); String clinicName; String clinicTel; String clinicFax; // check if satellite clinic is used String useSatelliteClinic = req.getParameter("useSC"); logger.debug(useSatelliteClinic); if (useSatelliteClinic != null && useSatelliteClinic.equalsIgnoreCase("true")) { String scAddress = req.getParameter("scAddress"); logger.debug("clinic detail" + "=" + scAddress); HashMap<String, String> hm = parseSCAddress(scAddress); clinicName = hm.get("clinicName"); clinicTel = hm.get("clinicTel"); clinicFax = hm.get("clinicFax"); } else { // parameters need to be passed to header and footer clinicName = req.getParameter("clinicName"); logger.debug("clinicName" + "=" + clinicName); clinicTel = req.getParameter("clinicPhone"); clinicFax = req.getParameter("clinicFax"); } String patientPhone = req.getParameter("patientPhone"); String patientCityPostal = req.getParameter("patientCityPostal"); String patientAddress = req.getParameter("patientAddress"); String patientName = req.getParameter("patientName"); String sigDoctorName = req.getParameter("sigDoctorName"); String rxDate = req.getParameter("rxDate"); String rx = req.getParameter("rx"); String patientDOB = req.getParameter("patientDOB"); String showPatientDOB = req.getParameter("showPatientDOB"); String imgFile = req.getParameter("imgFile"); String patientHIN = req.getParameter("patientHIN"); String patientChartNo = req.getParameter("patientChartNo"); String pracNo = req.getParameter("pracNo"); Locale locale = req.getLocale(); boolean isShowDemoDOB = false; if (showPatientDOB != null && showPatientDOB.equalsIgnoreCase("true")) { isShowDemoDOB = true; } if (!isShowDemoDOB) patientDOB = ""; if (rx == null) { rx = ""; } String additNotes = req.getParameter("additNotes"); String[] rxA = rx.split(newline); List<String> listRx = new ArrayList<String>(); String listElem = ""; // parse rx and put into a list of rx; for (String s : rxA) { if (s.equals("") || s.equals(newline) || s.length() == 1) { listRx.add(listElem); listElem = ""; } else { listElem = listElem + s; listElem += newline; } } // get the print prop values Properties props = new Properties(); StringBuilder temp = new StringBuilder(); for (Enumeration<String> e = req.getParameterNames(); e.hasMoreElements();) { temp = new StringBuilder(e.nextElement().toString()); props.setProperty(temp.toString(), req.getParameter(temp.toString())); } for (Enumeration<String> e = req.getAttributeNames(); e.hasMoreElements();) { temp = new StringBuilder(e.nextElement().toString()); props.setProperty(temp.toString(), req.getAttribute(temp.toString()).toString()); } Document document = new Document(); try { String title = req.getParameter("__title") != null ? req.getParameter("__title") : "Unknown"; // specify the page of the picture using __graphicPage, it may be used multiple times to specify multiple pages // however the same graphic will be applied to all pages // ie. __graphicPage=2&__graphicPage=3 String[] cfgGraphicFile = req.getParameterValues("__cfgGraphicFile"); int cfgGraphicFileNo = cfgGraphicFile == null ? 0 : cfgGraphicFile.length; if (cfgGraphicFile != null) { // for (String s : cfgGraphicFile) { // p("cfgGraphicFile", s); // } } String[] graphicPage = req.getParameterValues("__graphicPage"); ArrayList<String> graphicPageArray = new ArrayList<String>(); if (graphicPage != null) { // for (String s : graphicPage) { // p("graphicPage", s); // } graphicPageArray = new ArrayList<String>(Arrays.asList(graphicPage)); } // A0-A10, LEGAL, LETTER, HALFLETTER, _11x17, LEDGER, NOTE, B0-B5, ARCH_A-ARCH_E, FLSA // and FLSE // the following shows a temp way to get a print page size Rectangle pageSize = PageSize.LETTER; String pageSizeParameter = req.getParameter("rxPageSize"); if (pageSizeParameter != null) { if ("PageSize.HALFLETTER".equals(pageSizeParameter)) { pageSize = PageSize.HALFLETTER; } else if ("PageSize.A6".equals(pageSizeParameter)) { pageSize = PageSize.A6; } else if ("PageSize.A4".equals(pageSizeParameter)) { pageSize = PageSize.A4; } } /* * if ("PageSize.HALFLETTER".equals(props.getProperty(PAGESIZE))) { pageSize = PageSize.HALFLETTER; } else if ("PageSize.A6".equals(props.getProperty(PAGESIZE))) { pageSize = PageSize.A6; } else if * ("PageSize.A4".equals(props.getProperty(PAGESIZE))) { pageSize = PageSize.A4; } */ // p("size of page ", props.getProperty(PAGESIZE)); document.setPageSize(pageSize); // 285=left margin+width of box, 5f is space for looking nice document.setMargins(15, pageSize.getWidth() - 285f + 5f, 170, 60);// left, right, top , bottom writer = PdfWriter.getInstance(document, baosPDF); writer.setPageEvent(new EndPage(clinicName, clinicTel, clinicFax, patientPhone, patientCityPostal, patientAddress, patientName, patientDOB, sigDoctorName, rxDate, origPrintDate, numPrint, imgFile, patientHIN, patientChartNo, pracNo, locale)); document.addTitle(title); document.addSubject(""); document.addKeywords("pdf, itext"); document.addCreator("OSCAR"); document.addAuthor(""); document.addHeader("Expires", "0"); document.open(); document.newPage(); PdfContentByte cb = writer.getDirectContent(); BaseFont bf; // = normFont; cb.setRGBColorStroke(0, 0, 255); // render prescriptions for (String rxStr : listRx) { bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Paragraph p = new Paragraph(new Phrase(rxStr, new Font(bf, 10))); p.setKeepTogether(true); p.setSpacingBefore(5f); document.add(p); } // render additional notes if (additNotes != null && !additNotes.equals("")) { bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Paragraph p = new Paragraph(new Phrase(additNotes, new Font(bf, 10))); p.setKeepTogether(true); p.setSpacingBefore(10f); document.add(p); } // render optometristEyeParam if (req.getAttribute("optometristEyeParam") != null) { bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Paragraph p = new Paragraph( new Phrase("Eye " + (String) req.getAttribute("optometristEyeParam"), new Font(bf, 10))); p.setKeepTogether(true); p.setSpacingBefore(15f); document.add(p); } // render QrCode if (PrescriptionQrCodeUIBean.isPrescriptionQrCodeEnabledForCurrentProvider()) { Integer scriptId = Integer.parseInt(req.getParameter("scriptId")); byte[] qrCodeImage = PrescriptionQrCodeUIBean.getPrescriptionHl7QrCodeImage(scriptId); Image qrCode = Image.getInstance(qrCodeImage); document.add(qrCode); } } catch (DocumentException dex) { baosPDF.reset(); throw dex; } catch (Exception e) { logger.error("Error", e); } finally { if (document != null) { document.close(); } if (writer != null) { writer.close(); } } logger.debug("***END in generatePDFDocumentBytes2 FrmCustomedPDFServlet.java***"); return baosPDF; }
From source file:oscar.util.Doc2PDF.java
License:Open Source License
public static String GetPDFBin(HttpServletResponse response, String docText) { // step 1: creation of a document-object Document document = new Document(PageSize.A4, 36, 36, 36, 36); // Document document = new Document(PageSize.A4.rotate()); try {/*from ww w .j a v a 2 s. co m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // step 3: we create a parser and set the document handler SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); // step 4: we parse the document // use input stream parser.parse(new ByteArrayInputStream(docText.getBytes()), new SAXmyHtmlHandler(document)); document.close(); return (new String(Base64.encodeBase64(baos.toByteArray()))); } catch (Exception e) { logger.error("Unexpected error", e); } return null; }
From source file:oscar.util.Doc2PDF.java
License:Open Source License
public static void PrintPDFFromHTMLString(HttpServletResponse response, String docText) { // step 1: creation of a document-object Document document = new Document(PageSize.A4, 36, 36, 36, 36); //Document document = new Document(PageSize.A4.rotate()); try {/*from ww w . j ava 2s .co m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // step 3: we create a parser and set the document handler SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); // step 4: we parse the document // use input stream parser.parse(new ByteArrayInputStream(docText.getBytes()), new SAXmyHtmlHandler(document)); document.close(); // String yourString = new String(theBytesOfYourString, "UTF-8"); // byte[] theBytesOfYourString = yourString.getBytes("UTF-8"); byte[] binArray = baos.toByteArray(); PrintPDFFromBytes(response, binArray); } catch (Exception e) { logger.error("Unexpected error", e); } }
From source file:ppro.contoller.ExportController.java
public void preProcessPDF(Object document) throws IOException, DocumentException { final Document pdf = (Document) document; pdf.setPageSize(PageSize.A4.rotate()); pdf.open();//from ww w.j a va 2 s . com String logo = getAbsolutePath("logo_1663576_web.jpg"); pdf.add(Image.getInstance(logo)); }
From source file:ppro.contoller.ExportController.java
public void postProcessPDF(Object document) throws IOException, DocumentException { final Document pdf = (Document) document; pdf.setPageSize(PageSize.A4.rotate()); }