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:net.ionescu.jhocr2pdf.Jhocr2pdf.java
License:Open Source License
public void addSpan(String coords, String text) { // parse the coordinates String[] coord = coords.split(" "); Rectangle rect = new Rectangle(Float.valueOf(coord[1]), Float.valueOf(coord[4]), Float.valueOf(coord[3]), Float.valueOf(coord[2])); canvas.saveState();/* w w w . j a v a2 s . com*/ canvas.beginText(); canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); canvas.setRGBColorFill(0xFF, 0, 0); canvas.setLineWidth(0); // calculate the font size float width = rect.getWidth() * xScaling; float tenWidth = bf.getWidthPointKerned(text, 10); float fontSize = 10 * width / tenWidth; canvas.setFontAndSize(bf, fontSize); canvas.showTextAlignedKerned(Element.ALIGN_LEFT, text, rect.getLeft() * xScaling, PageSize.A4.getHeight() - rect.getBottom() * yScaling - bf.getDescentPoint(text, fontSize), 0); canvas.endText(); canvas.restoreState(); }
From source file:net.vzurczak.timesheetgenerator.PdfGenerator.java
License:Apache License
/** * Creates a PDF document.//ww w . j a v a 2 s. c o m * @param bean a generation bean (not null) * @throws DocumentException * @throws FileNotFoundException */ public void createDocument(GenerationDataBean bean) throws FileNotFoundException, DocumentException { // Create the document File outputFile = new File("./Feuille-De-Temps.pdf"); final Document doc = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(doc, new FileOutputStream(outputFile)); doc.open(); doc.addAuthor(bean.getName()); doc.addCreator(bean.getName()); String s; if (bean.getEndWeek() - bean.getStartWeek() > 1) s = "Feuilles de Temps - Semaines " + bean.getStartWeek() + " " + bean.getEndWeek(); else s = "Feuille de Temps - Semaine " + bean.getStartWeek(); doc.addTitle(s); doc.addSubject(s); // Add pages for (int i = bean.getStartWeek(); i <= bean.getEndWeek(); i++) addPageForWeek(i, doc, bean); // That's it! doc.close(); }
From source file:nl.ctmm.trait.proteomics.qcviewer.utils.ReportPDFExporter.java
License:Apache License
/** * Export a report to a pdf file.//from w w w .j a va 2 s. c o m * * @param allMetricsMap map of all QC metrics - keys and description. * @param selectedReports the report units to be exported in PDF format. * @param preferredPDFDirectory the directory the pdf document should be exported to. * @return Path of the created PDF document if it is successfully created - otherwise return empty string. */ public static String exportReportUnitInPDFFormat(final Map<String, String> allMetricsMap, final ArrayList<ReportUnit> selectedReports, final String preferredPDFDirectory) { //Obtain current timestamp. final java.util.Date date = new java.util.Date(); final String timestampString = CREATION_DATE_TIME_FORMAT.format(date); //Replace all occurrences of special character ':' from time stamp since ':' is not allowed in filename. final String filenameTimestamp = timestampString.replace(':', '-'); //Instantiation of document object - landscape format using the rotate() method final Document document = new Document(PageSize.A4.rotate(), PDF_PAGE_MARGIN, PDF_PAGE_MARGIN, PDF_PAGE_MARGIN, PDF_PAGE_MARGIN); final String pdfFileName = preferredPDFDirectory + "\\QCReports-" + filenameTimestamp + FILE_TYPE_EXTENSION; try { //Creation of PdfWriter object // PdfWriter writer; // writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFileName)); document.open(); for (ReportUnit reportUnit : selectedReports) { //New page for each report. document.newPage(); //Creation of chapter object final Paragraph pageTitle = new Paragraph( String.format(PDF_PAGE_TITLE, reportUnit.getMsrunName(), timestampString), Constants.PDF_TITLE_FONT); pageTitle.setAlignment(Element.ALIGN_CENTER); final Chapter chapter1 = new Chapter(pageTitle, 1); chapter1.setNumberDepth(0); //Creation of TIC graph section object final String graphTitle = String.format(TIC_GRAPH_SECTION_TITLE, reportUnit.getMsrunName()); final Paragraph ticGraphSection = new Paragraph(graphTitle, Constants.PDF_SECTION_FONT); ticGraphSection.setSpacingBefore(PDF_PARAGRAPH_SPACING); ticGraphSection.add(Chunk.NEWLINE); //Insert TIC Graph in ticGraphSection. ticGraphSection.add(createTICChartImage(reportUnit)); chapter1.addSection(ticGraphSection); final String metricsTitle = String.format(METRICS_VALUES_SECTION_TITLE, reportUnit.getMsrunName()); final Paragraph metricsValuesSection = new Paragraph(metricsTitle, Constants.PDF_SECTION_FONT); metricsValuesSection.setSpacingBefore(PDF_PARAGRAPH_SPACING); //Reference: http://www.java-connect.com/itext/add-table-in-PDF-document-using-java-iText-library.html //TODO: Insert metrics values table in metricsValuesSection metricsValuesSection.add(createMetricsValuesTable(allMetricsMap, reportUnit)); chapter1.addSection(metricsValuesSection); //Addition of a chapter to the main document document.add(chapter1); } document.close(); return pdfFileName; } catch (final DocumentException e) { // TODO Explain when these exception can occur. /* FileNotFoundException will be thrown by the FileInputStream, FileOutputStream, and * RandomAccessFile constructors when a file with the specified path name does not exist. * It will also be thrown by these constructors if the file does exist but for some reason * is inaccessible, for example when an attempt is made to open a read-only file for writing. * DocumentException Signals that an error has occurred in a Document. */ logger.log(Level.SEVERE, PDF_EXPORT_EXCEPTION_MESSAGE, e); return ""; } }
From source file:nl.infosys.hartigehap.barSystem.domain.Bon.java
/** * Creates a PDF document./*w ww . ja v a 2s. co m*/ * * @param filename the path to the new PDF document * @throws DocumentException * @throws IOException */ private void create() { try { Document document = new Document(PageSize.A4); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); document.add(header()); document.add(Chunk.NEWLINE); document.add(table()); document.setMargins(0, 0, 0, 100); document.close(); } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:nl.infosys.hartigehap.barSystem.presentation.BonGui.java
/** * Creates a PDF document./*from www . jav a 2 s .co m*/ * * @param filename the path to the new PDF document * @throws DocumentException * @throws IOException */ private void createPdf() { try { Document document = new Document(PageSize.A4); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); document.add(header()); document.add(Chunk.NEWLINE); document.add(table()); document.setMargins(0, 0, 0, 100); document.close(); } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:nwk.com.br.documents.ClienteMaisComprouPdf.java
public void getClienteMaisComprou() throws Exception { Document doc = null;//from w w w.j a v a 2 s . c om OutputStream os = null; try { //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4, 35, 35, 35, 35); //cria a stream de sada os = new FileOutputStream("C:\\PoolOrc\\Consultas\\ClienteMaisComprou.pdf"); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //Definindo a font coamily.COURIER, 20, Font.BOLD);mo Courier, tamanho 20 em negrito //Font f = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD); Paragraph orc = new Paragraph("CLIENTE QUE MAIS COMPROU", f); orc.setAlignment(Element.ALIGN_CENTER); /*AREA DE TESTES**************************************************/ /*AREA DE TESTES**************************************************/ doc.add(cabecalho());//adiciona o cabecalho com informaes da empresa doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(orc);//esreve oramento doc.add(new Paragraph(" ")); doc.add(getCliente());//adiciona os produtos //doc.add(new Paragraph(" ")); doc.add(new Paragraph( "______________________________________________________________________________")); //doc.add(new Paragraph(" ")); /*doc.add(dadosPagamento(orcamento));//adiciona os dados de valores e forma de pagamento doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(dadosRodape(orcamento));//adiciona o rodape ao oramento*/ //abrindo o arquivo File arquivo = new File("C:\\PoolOrc\\Consultas\\ClienteMaisComprou.pdf"); Desktop.getDesktop().open(arquivo); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } System.out.println("done"); }
From source file:nwk.com.br.documents.OrcamentoPdf.java
public void gerarPdf(Orcamento orcamento) throws Exception { Document doc = null;/*from w w w . j a va 2 s . com*/ OutputStream os = null; cliente = clientedao.select(orcamento.getIdCliente()); try { //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4, 35, 35, 35, 35); //cria a stream de sada String caminho = "C:\\PoolOrc\\OrcPdf\\ORC" + orcamento.getId() + " " + cliente.getNome() + ".pdf"; os = new FileOutputStream(caminho); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //Definindo a font coamily.COURIER, 20, Font.BOLD);mo Courier, tamanho 20 em negrito //Font f = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD); Paragraph orc = new Paragraph("ORAMENTO", f); orc.setAlignment(Element.ALIGN_CENTER); /*AREA DE TESTES**************************************************/ /*AREA DE TESTES**************************************************/ doc.add(numPed(orcamento));//adiciona numero do pedido doc.add(new Paragraph(" ")); doc.add(cabecalho(orcamento));//adiciona o cabecalho com informaes da empresa doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(dadosCliente(orcamento));//adiciona os dados do cliente doc.add(new Paragraph(" ")); doc.add(orc);//esreve oramento doc.add(new Paragraph(" ")); doc.add(dadosProdutos(orcamento));//adiciona os produtos //doc.add(new Paragraph(" ")); doc.add(new Paragraph( "______________________________________________________________________________")); //doc.add(new Paragraph(" ")); doc.add(dadosPagamento(orcamento));//adiciona os dados de valores e forma de pagamento doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(dadosRodape(orcamento));//adiciona o rodape ao oramento //abrindo o arquivo File arquivo = new File(caminho); Desktop.getDesktop().open(arquivo); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } System.out.println("done"); }
From source file:nwk.com.br.documents.ProdutoMaisVendidoPdf.java
public void getProdutoMaisVendido() throws Exception { Document doc = null;/*from www. j av a2s . co m*/ OutputStream os = null; try { //cria o documento tamanho A4, margens de 2,54cm doc = new Document(PageSize.A4, 35, 35, 35, 35); //cria a stream de sada os = new FileOutputStream("C:\\PoolOrc\\Consultas\\ProdutoMaisVendido.pdf"); //associa a stream de sada ao PdfWriter.getInstance(doc, os); //abre o documento doc.open(); //Definindo a font coamily.COURIER, 20, Font.BOLD);mo Courier, tamanho 20 em negrito //Font f = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD); Paragraph orc = new Paragraph("PRODUTO MAIS VENDIDO", f); orc.setAlignment(Element.ALIGN_CENTER); /*AREA DE TESTES**************************************************/ /*AREA DE TESTES**************************************************/ doc.add(cabecalho());//adiciona o cabecalho com informaes da empresa doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(orc);//esreve oramento doc.add(new Paragraph(" ")); doc.add(getProduto());//adiciona os produtos //doc.add(new Paragraph(" ")); doc.add(new Paragraph( "______________________________________________________________________________")); //doc.add(new Paragraph(" ")); /*doc.add(dadosPagamento(orcamento));//adiciona os dados de valores e forma de pagamento doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(dadosRodape(orcamento));//adiciona o rodape ao oramento*/ //abrindo o arquivo File arquivo = new File("C:\\PoolOrc\\Consultas\\ProdutoMaisVendido.pdf"); Desktop.getDesktop().open(arquivo); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } System.out.println("done"); }
From source file:org.alfresco.repo.content.transform.ITextPDFWorker.java
License:Apache License
/** * Creates pdf from input stream that contains text. * * @param text/* w w w . j a v a 2s. c o m*/ * is the input stream - should character stream * @param encoding * the encoding * @param output * is the output stream to store pdf in * @return the created pdf or null on exception * @throws DocumentException * on error while adding data * @throws IOException * on read/write exception */ public Document createPDFFromText(InputStream text, String encoding, OutputStream output) throws DocumentException, IOException { Document doc = null; try { // new pdf doc = new Document(PageSize.A4); // it is needed PdfWriter.getInstance(doc, output); doc.open(); // get utf8 reader BufferedReader data = new BufferedReader(new InputStreamReader(text, encoding)); String nextLine = null; while ((nextLine = data.readLine()) != null) { if (nextLine.isEmpty()) { // add the empty rows nextLine = " \r\n"; } else if (nextLine.length() > MAX_LINE_SIZE) { // add the empty rows nextLine = nextLine.substring(0, 5000) + "...Text too long... \r\n"; } Paragraph element = new Paragraph(nextLine, textFont); element.setFirstLineIndent(getTrimSize(nextLine) * DEFAULT_FONT_SIZE); doc.add(element); } return doc; } finally { // if (writer != null) { // writer.close(); // } } }
From source file:org.alfresco.repo.content.transform.ITextPDFWorker.java
License:Apache License
/** * Creates pdf that is empty./*ww w . j av a 2 s . c om*/ * * @param output * is the output stream to store pdf in * @return the created pdf or null on exception * @throws DocumentException * on error while adding data */ public Document createEmptyPDF(OutputStream output) throws DocumentException { Document doc = null; // new pdf doc = new Document(PageSize.A4); // it is needed PdfWriter.getInstance(doc, output); doc.open(); return doc; }