List of usage examples for com.itextpdf.text PageSize A4
Rectangle A4
To view the source code for com.itextpdf.text PageSize A4.
Click Source Link
From source file:Modelo.RelatoriosBEAN.java
public static void notaDaDev(DevolucaoBEAN l) throws FileNotFoundException, DocumentException { String path = System.getProperty("user.home") + FRMEmitirRelatorios.local + ".pdf"; Document document = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(document, new FileOutputStream(path)); document.open();/*from w w w. j a va 2 s . c o m*/ document.addAuthor("TechSales"); document.addCreator("TechSales"); document.addSubject("TechSales - Sistema de gerenciamento de locadoras"); document.addCreationDate(); document.addTitle("TechSales"); HTMLWorker htmlWorker = new HTMLWorker(document); String frase; try { frase = "<html>" + "<head> <meta charset=\"utf-8\"> </head>" + "<body>" + "<h1 align=center>Nota de devoluo</h1>" + "<br/><br/>" + "<table BORDER RULES=rows border=0 style=\" width:100%; \">\n" + "<tr> " + "<th align=center><strong>Cdigo</strong></th> " + "<th align=center><strong>Cliente</strong></th> " + "<th align=center><strong>Data Devoluo</strong></th> " + "<th align=center><strong>Multa</strong></th> " + "<th align=center><strong>Valor Total</strong></th> " + "<th align=center><strong>Vendedor</strong></th> " + "</tr> "; frase += "<tr align=center><td>" + l.getDevCodigo() + "</td><td>" + l.getLocacao().getCliente().getCliNome() + "</td><td>" + l.getDevData() + "</td><td>" + l.getDevMulta() + "</td><td>" + l.getDevValor() + "</td><td>" + l.getLocacao().getVendedor().getFuncionario().getFunNome() + "</td></tr>" + "</table>"; frase += "<table BORDER RULES=rows border=0 style=\" width:100%; \">\n" + "<br/><br/>" + "<tr> " + "<th align=center><strong>Cdigo do Jogo</strong></th> " + "<th align=center><strong>Nome</strong></th> " + "<th align=center><strong>Quantidade Locao</strong></th> " + "</tr> "; for (JogoLocacaoBEAN jl : cJl.listarALL()) { if (jl.getChaveComposta().getLocacao().getLocCodigo() == l.getLocacao().getLocCodigo()) { frase += "<tr align=center><td>" + jl.getChaveComposta().getJogo().getJoCodigo() + "</td><td>" + jl.getChaveComposta().getJogo().getJoNome() + "</td><td>" + jl.getJlQtd() + "</td></tr>"; } } frase += "</table>"; frase += "</body></html>"; htmlWorker.parse(new StringReader(frase)); document.close(); if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().open(new File(path)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:Modelo.RelatoriosBEAN.java
public static void notaDeCompra(NotaDecompraBEAN n) throws FileNotFoundException, DocumentException { String path = System.getProperty("user.home") + FRMEmitirRelatorios.local + ".pdf"; Document document = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(document, new FileOutputStream(path)); document.open();/*from w w w . ja v a 2 s.c om*/ document.addAuthor("TechSales"); document.addCreator("TechSales"); document.addSubject("TechSales - Sistema de gerenciamento de locadoras"); document.addCreationDate(); document.addTitle("TechSales"); HTMLWorker htmlWorker = new HTMLWorker(document); String frase; try { frase = "<html>" + "<head> <meta charset=\"utf-8\"> </head>" + "<body>" + "<br/>" + "<h1 align=center>Relatrio de Jogos Comprados </h1>" + "<br/><br/>" + "<table BORDER RULES=rows border=0 style=\" width:100%; \">\n" + "<tr> " + "<th align=center><strong>Cdigo</strong></th> " + "<th align=center><strong>Custo Unitrio</strong></th> " + "<th align=center><strong>Data</strong></th> " + "<th align=center><strong>Valor da Entrada</strong></th> " + "<th align=center><strong>Nmero de parcelas</strong></th> " + "<th align=center><strong>Preo Total</strong></th> " + "<th align=center><strong>Quantidade Compradra</strong></th> " + "<th align=center><strong>Caixa</strong></th> " + "<th align=center><strong>Jogo</strong></th> " + "</tr> "; frase += "<tr align=center><td>" + n.getNdcCodigo() + "</td><td>" + n.getNdcCustoUnitario() + "</td><td>" + n.getNdcData() + "</td><td>" + n.getNdcEntrada() + "</td><td>" + n.getNdcParcelas() + "</td><td>" + n.getNdcPrecoTotal() + "</td><td>" + n.getNdcQtdComprada() + "</td><td>" + n.getCaixa().getCaixaCodigo() + "</td><td>" + n.getJogo().getJoNome() + "</td></tr>" + "</table>"; ; frase += "<table BORDER RULES=rows border=0 style=\" width:100%; \">\n" + "<br/><br/>" + "<tr> " + "<th align=center><strong>Parcela</strong></th> " + "<th align=center><strong>Data</strong></th> " + "<th align=center><strong>Valor</strong></th> " + "<th align=center><strong>Situao</strong></th> " + "</tr> "; for (NotaDeCompraPrazoBEAN nap : cNdcap.listarALL()) { if (nap.getNota().getNdcCodigo() == n.getNdcCodigo()) { frase += "<tr align=center><td>" + nap.getNapNumParcela() + "</td><td>" + nap.getNapData() + "</td><td>" + nap.getNapValor() + "</td><td>" + nap.getNapSituacao() + "</td></tr>"; } } frase += "</table>"; frase += "</body></html>"; htmlWorker.parse(new StringReader(frase)); document.close(); if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().open(new File(path)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:net.algem.billing.InvoiceView.java
License:Open Source License
private void createPdf() throws IOException, DocumentException { Document document = new Document(PageSize.A4); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.open();//ww w.ja v a 2s. c om drawPdf(document, writer); document.close(); String prefix = invoice.getClass() == Quote.class ? BundleUtil.getLabel("Quotation.label") : BundleUtil.getLabel("Invoice.label"); String tmpFileName = prefix.toLowerCase() + "-" + invoice.getNumber() + "_"; pdfHandler.createPdf(tmpFileName, outputStream, PageTemplate.QUOTE_PAGE_MODEL); }
From source file:net.algem.enrolment.TrainingService.java
License:Open Source License
void preview(Properties props, String fileName, short templateKey, int idper) throws DocumentException, IOException { InputStream tpl = getClass().getResourceAsStream("/resources/doc/tpl/" + fileName + ".html"); String defPath = "/resources/doc/tpl/def/" + fileName + ".html"; if (tpl == null) { tpl = getClass().getResourceAsStream(defPath); }//from w w w . ja v a 2s. c o m if (tpl == null) { MessagePopup.warning(null, MessageUtil.getMessage("html.template.not.found.warning", fileName + ".html")); return; } String content = FileUtil.scanContent(tpl, props); //tpl = new ByteArrayInputStream(content.getBytes()); tpl = new ByteArrayInputStream(content.getBytes("UTF-8")); ByteArrayOutputStream out = new ByteArrayOutputStream(); //step 1 Document doc = new Document(PageSize.A4); doc.setMargins(40, 40, 40, 40); //step 2 /*OutputStream printStream = new PrintStream(out, true, "UTF-8"); PdfWriter writer = PdfWirter.getInstance(doc, printStream);*/ PdfWriter writer = PdfWriter.getInstance(doc, out); //writer.addViewerPreference(PdfName.PRINTSCALING, PdfName.NONE); //writer.addViewerPreference(PdfName.PRINTSCALING, PdfName.FIT); //writer.addViewerPreference(PdfName.DUPLEX, PdfName.DUPLEXFLIPLONGEDGE); doc.open(); // step 4 PdfHandler handler = new PdfHandler(templateIO); // IMPORTANT !! : set Charset here handler.createParser(doc, writer).parse(tpl, Charset.forName("UTF-8")); // step 5 doc.close(); handler.createPdf(fileName + "-" + idper + "_", out, templateKey); }
From source file:net.atomique.ksar.export.FilePDF.java
License:Open Source License
public void run() { total_pages += mysar.get_page_to_print(); switch (Config.getPDFPageFormat()) { case "A4": document = new Document(PageSize.A4.rotate()); break;// ww w . ja va 2 s . c om case "LEGAL": document = new Document(PageSize.LEGAL.rotate()); break; case "LETTER": document = new Document(PageSize.LETTER.rotate()); break; default: document = new Document(PageSize.A4.rotate()); break; } pdfheight = document.getPageSize().getHeight(); pdfwidth = document.getPageSize().getWidth(); pageheight = pdfheight - (2 * pdfmargins); pagewidth = pdfwidth - (2 * pdfmargins); try { writer = PdfWriter.getInstance(document, new FileOutputStream(pdffilename)); } catch (DocumentException | FileNotFoundException ex) { log.error("Parser Exception", ex); } writer.setPageEvent(this); writer.setCompressionLevel(0); // document parameter before open document.addTitle("kSar Grapher"); //document.addSubject("SAR Statistics of " + mysar.hostName); //document.addKeywords("https://github.com/vlsi/ksar"); //document.addKeywords(mysar.hostName); //document.addKeywords(mysar.myOS.sarStartDate); //document.addKeywords(mysar.myOS.sarEndDate); document.addCreator("kSar Version:" + VersionNumber.getVersionString()); document.addAuthor("https://github.com/vlsi/ksar"); // open the doc document.open(); pdfcb = writer.getDirectContent(); PdfOutline root = pdfcb.getRootOutline(); IndexPage(document); export_treenode(mysar.graphtree, root); document.close(); if (dialog != null) { dialog.dispose(); } }
From source file:net.carting.web.SHKPController.java
@RequestMapping(value = "start", method = RequestMethod.POST) @ResponseBody/*from w w w.ja va 2 s. co m*/ public int createStartStatement(@RequestParam(value = "table") String table, @RequestParam(value = "raceId") int raceId, @RequestParam(value = "startId") int startId) { int result; try { CarClassCompetition carClassCompetition = carClassCompetitionService.getCarClassCompetitionById(raceId); File start; if (startId == 1) { if (carClassCompetition.getFirstRaceStartStatement() == null) { start = new File(); } else { start = carClassCompetition.getFirstRaceStartStatement(); } } else { if (carClassCompetition.getSecondRaceStartStatement() == null) { start = new File(); } else { start = carClassCompetition.getSecondRaceStartStatement(); } } start.setFile(PdfWriter.getFileBytes(table, PageSize.A4.rotate())); String fileName = "StartStatement_" + raceId + "_" + "_" + startId + Calendar.getInstance().getTimeInMillis() + ".pdf"; start.setName(fileName); if (startId == 1) { carClassCompetition.setFirstRaceStartStatement(start); } else { carClassCompetition.setSecondRaceStartStatement(start); } carClassCompetitionService.updateCarClassCompetition(carClassCompetition); if (startId == 1) { result = carClassCompetitionService.getCarClassCompetitionById(raceId).getFirstRaceStartStatement() .getId(); } else { result = carClassCompetitionService.getCarClassCompetitionById(raceId).getSecondRaceStartStatement() .getId(); } } catch (Exception e) { result = 0; e.printStackTrace(); } return result; }
From source file:net.carting.web.SHKPController.java
@RequestMapping(value = "/personal", method = RequestMethod.POST) @ResponseBody/*from w ww . ja v a2 s . co m*/ public int createPersonalOffsetStatement(@RequestParam(value = "table") String table, @RequestParam(value = "carClassCompetitionId") int carClassCompetitionId) { int result; try { CarClassCompetition carClassCompetition = carClassCompetitionService .getCarClassCompetitionById(carClassCompetitionId); File personalOffset; if (carClassCompetition.getPersonalOffset() == null) { personalOffset = new File(); } else { personalOffset = carClassCompetition.getPersonalOffset(); } personalOffset.setFile(PdfWriter.getFileBytes(table, PageSize.A4.rotate())); // create pdf file, created from valid xhtml data String fileName = "PersonalOffset_" + carClassCompetitionId + "_" + Calendar.getInstance().getTimeInMillis() + ".pdf"; personalOffset.setName(fileName); carClassCompetition.setPersonalOffset(personalOffset); // set personal offset file to rhis car class competition carClassCompetitionService.updateCarClassCompetition(carClassCompetition); // and update car class competition result = carClassCompetitionService.getCarClassCompetitionById(carClassCompetitionId) .getPersonalOffset().getId(); } catch (Exception e) { result = 0; LOG.error("Errors in creating PDF for personalOffset", e); } return result; }
From source file:net.carting.web.SHKPController.java
@RequestMapping(value = "maneuver", method = RequestMethod.POST) @ResponseBody//from ww w . j a va 2 s . com public int createManeuverStatement(@RequestParam(value = "table") String table, @RequestParam(value = "raceId") int raceId, @RequestParam(value = "ids") List<Integer> idArray, @RequestParam(value = "times") List<Double> timeArray) { int result; try { CarClassCompetition carClassCompetition = carClassCompetitionService.getCarClassCompetitionById(raceId); File maneuver; if (carClassCompetition.getManeuverStatement() == null) { maneuver = new File(); } else { maneuver = carClassCompetition.getManeuverStatement(); } maneuver.setFile(PdfWriter.getFileBytes(table, PageSize.A4.rotate())); String fileName = "ManeuverStatement_" + raceId + "_" + Calendar.getInstance().getTimeInMillis() + ".pdf"; maneuver.setName(fileName); carClassCompetition.setManeuverStatement(maneuver); List<CarClassCompetitionResult> competitionResults = carClassCompetitionResultService .getCarClassCompetitionResultsByCarClassCompetition(carClassCompetition); for (CarClassCompetitionResult competitionResult : competitionResults) { for (int i = 0; i < idArray.size(); i++) { int racerId = idArray.get(i); double maneuverTime = timeArray.get(i); if (competitionResult.getRacerCarClassCompetitionNumber().getNumberInCompetition() == racerId) { competitionResult.setManeuverTime(maneuverTime); carClassCompetitionResultService.updateCarClassCompetitionResult(competitionResult); } } } carClassCompetitionService.updateCarClassCompetition(carClassCompetition); result = carClassCompetitionService.getCarClassCompetitionById(raceId).getManeuverStatement().getId(); } catch (Exception e) { result = 0; e.printStackTrace(); } return result; }
From source file:net.digitstar.vanadio.AbstractReportPdf.java
License:Apache License
private Document initPageLayout(Document document) { if (getReportOptions().getPageType() != ReportOptions.PageType.TYPE_AUTO) { if (getReportOptions().getPageType() == ReportOptions.PageType.TYPE_A4) { document.setPageSize(//from w w w . jav a2s. c o m getReportOptions().getPageOrientation() == ReportOptions.PageOrientation.PAGE_VERTICAL ? PageSize.A4 : PageSize.A4.rotate()); } else { document.setPageSize( getReportOptions().getPageOrientation() == ReportOptions.PageOrientation.PAGE_VERTICAL ? PageSize.A3 : PageSize.A3.rotate()); } } else { } document.open(); return document; }
From source file:net.ionescu.jhocr2pdf.Jhocr2pdf.java
License:Open Source License
@Override public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { text.setLength(0);//from w w w .j av a 2 s . c o m coords = null; if (localName.equals("span")) { log.finer("start of span, we encountered an OCR word"); String klass = atts.getValue("class"); if (null != klass && klass.equals("ocr_word")) { coords = atts.getValue("title"); } } if (localName.equals("div")) { String klass = atts.getValue("class"); if (null != klass && klass.equals("ocr_page")) { log.finer("start div, start of page, load the corresponding page of the PDF file"); int pageNum = siglePageOCRNum; if (pageNum < 0) { String id = atts.getValue("id"); pageNum = Integer.valueOf(id.split("_")[1], 10); log.log(FINE, "extracted page number from the div id attribute: {0}", pageNum); } if (visible) { canvas = stamper.getOverContent(pageNum); } else { canvas = stamper.getUnderContent(pageNum); } /* * Calculate the scaling of the image. * Tesseract coordinates differ from the PDF coordinates so we can't use them directly. * But Tesseract gives us the dimension of the scanned image and we also know that the * image is as large as the page. So we calculate a scaling factor to translate from * Tesseract coordinates into PDF coordinates. */ String title[] = atts.getValue("title").split(" "); float imgWidth = Float.valueOf(title[title.length - 2]) - Float.valueOf(title[title.length - 4]); float imgHeight = Float.valueOf(title[title.length - 1]) - Float.valueOf(title[title.length - 3]); xScaling = PageSize.A4.getWidth() / imgWidth; yScaling = PageSize.A4.getHeight() / imgHeight; log.log(FINE, "Load page {0} with scaling {1}x{2}", new Object[] { pageNum, xScaling, yScaling }); } } }