List of usage examples for com.itextpdf.text.pdf PdfContentByte setTextMatrix
public void setTextMatrix(final float x, final float y)
From source file:bouttime.report.boutsheet.BoutSheetReport.java
License:Open Source License
/** * Add the header string to the document. * @param writer PdfWriter object to use. * @param document Document object to add the header to. *///w w w. java 2s . c o m private void addHeader(PdfWriter writer, Document document) { if (this.headerString == null) { return; } PdfContentByte cb = writer.getDirectContent(); float textBase = document.top() + 5; cb.beginText(); cb.setFontAndSize(this.baseFont, 12); cb.setTextMatrix(document.left(), textBase); cb.showText(this.headerString); cb.endText(); }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawString(PdfContentByte cb, BaseFont bf, float x, float y, float fontSize, String string) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }//from w w w. j a v a2s.co m cb.setFontAndSize(bf, fontSize); cb.beginText(); cb.setTextMatrix(x, y); cb.showText(string); cb.endText(); cb.stroke(); }
From source file:co.ordinate.printer.NewJFrame.java
private void A4BTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_A4BTNActionPerformed new SwingWorker<Object, Object>() { String filename;// w w w. j av a 2s . c o m @Override protected void done() { ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. "); } @Override protected Object doInBackground() throws Exception { Document doc = new Document(); try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("A4.pdf")); doc.open(); doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : "); doc.addSubject("Confidential Report Eyes Only"); doc.addKeywords(""); doc.addAuthor("SOS"); doc.addCreator("SOS"); // A4 = 210mm x 297mm ~ 605points x 855points doc.setPageSize(PageSize.A4); doc.setMargins(10f, 10f, 10f, 10f); ///////////////////////////////////////////////////////////// int pageno = 1; for (int i = 0; i == pageno; i++) { // doc.add(imageRight); } PdfContentByte cb = writer.getDirectContent(); int i = 1; while (i <= pageno) { doc.newPage(); i++; } BaseFont labelFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", true); float width = doc.getPageSize().getWidth(); float height = doc.getPageSize().getHeight(); for (float h = 0; h <= height; h++) { for (float w = 0; w <= width; w++) { cb.beginText(); // cb.setColorFill(TITLE_COLOR); cb.setFontAndSize(labelFont, 2); cb.setTextMatrix(w, h); cb.showText(String.valueOf(h) + ":" + String.valueOf(w)); cb.endText(); w += 15; } h += 2; } cb.beginText(); // cb.setColorFill(TITLE_COLOR); cb.setFontAndSize(labelFont, 4); cb.setTextMatrix(20f, 220f); cb.showText("abcd"); cb.endText(); } catch (Exception e) { System.err.println(e.getMessage()); ConsoleMsg(e.getMessage()); } finally { doc.close(); } ConsoleMsg("PDF... GENERATED"); return null; // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }.execute(); // TODO add your handling code here: }
From source file:co.ordinate.printer.NewJFrame.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed new SwingWorker<Object, Object>() { String filename;//from w w w .j av a 2 s . c o m @Override protected void done() { ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. "); } @Override protected Object doInBackground() throws Exception { Document doc = new Document(); try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("letter.pdf")); doc.open(); doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : "); doc.addSubject("Confidential Report Eyes Only"); doc.addKeywords(""); doc.addAuthor("SOS"); doc.addCreator("SOS"); // A4 = 210mm x 297mm ~ 605points x 855points doc.setPageSize(PageSize.LETTER); doc.setMargins(10f, 10f, 10f, 10f); ///////////////////////////////////////////////////////////// int pageno = 1; for (int i = 0; i == pageno; i++) { // doc.add(imageRight); } PdfContentByte cb = writer.getDirectContent(); int i = 1; while (i <= pageno) { doc.newPage(); i++; } BaseFont labelFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", true); float width = doc.getPageSize().getWidth(); float height = doc.getPageSize().getHeight(); for (float h = 0; h <= height; h++) { for (float w = 0; w <= width; w++) { cb.beginText(); // cb.setColorFill(TITLE_COLOR); cb.setFontAndSize(labelFont, 4); cb.setTextMatrix(w, h); cb.showText(String.valueOf(h) + ":" + String.valueOf(w)); cb.endText(); w += 25; } h += 5; } cb.beginText(); // cb.setColorFill(TITLE_COLOR); cb.setFontAndSize(labelFont, 4); cb.setTextMatrix(20f, 220f); cb.showText("abcd"); cb.endText(); } catch (Exception e) { System.err.println(e.getMessage()); ConsoleMsg(e.getMessage()); } finally { doc.close(); } ConsoleMsg("PDF... GENERATED"); return null; // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }.execute(); // TODO add your handling code here: }
From source file:co.ordinate.printer.NewJFrame.java
private void printA6Sheet() { new SwingWorker<Object, Object>() { String filename;// ww w. j a va 2 s. c om @Override protected void done() { ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. "); System.err.println("Printing Done"); } @Override protected Object doInBackground() throws Exception { Document doc = new Document(); try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("A6.pdf")); doc.open(); doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : "); doc.addSubject("Confidential Report Eyes Only"); doc.addKeywords(""); doc.addAuthor("SOS"); doc.addCreator("SOS"); // A4 = 210mm x 297mm ~ 605points x 855points doc.setPageSize(PageSize.A5); doc.setMargins(10f, 10f, 10f, 10f); ///////////////////////////////////////////////////////////// int pageno = 1; for (int i = 0; i == pageno; i++) { // doc.add(imageRight); } PdfContentByte cb = writer.getDirectContent(); int i = 1; while (i <= pageno) { doc.newPage(); i++; } BaseFont labelFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", true); float width = doc.getPageSize().getWidth(); float height = doc.getPageSize().getHeight(); for (float h = 0; h <= height; h++) { for (float w = 0; w <= width; w++) { cb.beginText(); // cb.setColorFill(TITLE_COLOR); cb.setFontAndSize(labelFont, 4); cb.setTextMatrix(w, h); cb.showText(String.valueOf(h) + ":" + String.valueOf(w)); cb.endText(); w += 30; } h += 8; } cb.beginText(); // cb.setColorFill(TITLE_COLOR); cb.setFontAndSize(labelFont, 4); cb.setTextMatrix(20f, 220f); cb.showText("abcd"); cb.endText(); } catch (Exception e) { System.err.println(e.getMessage()); ConsoleMsg(e.getMessage()); } finally { doc.close(); } ConsoleMsg("PDF... GENERATED"); System.err.println("Printing Done"); return null; // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }.execute(); // TODO add your handling code here: }
From source file:com.automaster.autoview.server.servlet.TextStateOperators.java
/** * Creates a PDF document.//ww w .j a v a 2 s.co m * @param filename the path to the new PDF document * @throws DocumentException * @throws IOException */ public void createPdf(String filename) throws IOException, DocumentException { // step 1 Rectangle rect = new Rectangle(595, 842); Document document = new Document(rect, 30, 30, 30, 30); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 document.open(); // step 4 //PdfAcroForm canva = writer.getAcroForm(); BaseFont bf = BaseFont.createFont(); //canva.addMultiLineTextField("txtTeste", "texto de teste vamos ver se le quebra a linha", bf, 15, 300, 800, 100, 100); PdfContentByte canvas = writer.getDirectContent(); String text = "AWAY again"; String text1 = "TESTE Rua alameda luis de sousa santos, N 52, castanhal, CEP: 68742-783, ao lado do posto adriano"; canvas.beginText(); // line 1 canvas.setFontAndSize(bf, 16); canvas.moveText(36, 800); canvas.moveTextWithLeading(0, -24); canvas.setTextRise(10); canvas.showText(text); // line 2 canvas.setWordSpacing(20); canvas.newlineShowText(text); // line 3 canvas.setCharacterSpacing(10); canvas.newlineShowText(text); canvas.setWordSpacing(0); canvas.setCharacterSpacing(0); // line 4 canvas.setHorizontalScaling(50); canvas.newlineShowText(text); canvas.setHorizontalScaling(100); // line 5 canvas.newlineShowText(text); canvas.setTextRise(15); canvas.setFontAndSize(bf, 12); canvas.setColorFill(BaseColor.RED); canvas.showText("2"); canvas.setColorFill(GrayColor.GRAYBLACK); // line 6 canvas.setLeading(56); canvas.setMiterLimit(5); canvas.newlineShowText( "Rua alameda luis de sousa santos, N 52, castanhal, CEP: 68742-783, ao lado do posto" + text); canvas.setLeading(24); canvas.newlineText(); Paragraph paragraph = new Paragraph("teste"); PdfWriter pdfWriter = canvas.getPdfWriter(); PdfAcroForm pdfAcroForm = pdfWriter.getAcroForm(); //pdfAcroForm.addMultiLineTextField("txtTeste", "Changing the adriano leading: Rua alameda luis de sousa santos, N 52, castanhal, CEP: 68742-783, ao lado do posto", bf, 12, 30, 650, 550, 750); //pdfAcroForm.addHiddenField("txtTeste", text); PdfFormField pdfFormField = new PdfFormField(pdfWriter, 30, 650, 550, 750, null); pdfFormField.setFieldName("txtTeste"); pdfFormField.setValueAsString(text1); //TextField textField = new TextField(canvas.getPdfWriter(), new Rectangle(30, 650, 550, 750), "txtTest"); //textField.setText(text); pdfAcroForm.addFormField(pdfFormField); // line 7 PdfTextArray array = new PdfTextArray("A"); array.add(120); array.add("W"); array.add(120); array.add("A"); array.add(95); array.add("Y again"); canvas.showText(array); canvas.endText(); canvas.setColorFill(BaseColor.BLUE); canvas.beginText(); canvas.setTextMatrix(360, 770); canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); canvas.setFontAndSize(bf, 24); canvas.showText(text); canvas.endText(); canvas.beginText(); canvas.setTextMatrix(360, 730); canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE); canvas.setFontAndSize(bf, 24); canvas.showText(text); canvas.endText(); canvas.beginText(); canvas.setTextMatrix(360, 690); canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE); canvas.setFontAndSize(bf, 24); canvas.showText(text); canvas.endText(); canvas.beginText(); canvas.setTextMatrix(360, 650); canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE); canvas.setFontAndSize(bf, 24); canvas.showText(text); canvas.endText(); PdfTemplate template = canvas.createTemplate(200, 36); template.setLineWidth(2); for (int i = 0; i < 6; i++) { template.moveTo(0, i * 6); template.lineTo(200, i * 6); } template.stroke(); canvas.saveState(); canvas.beginText(); canvas.setTextMatrix(360, 610); canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_CLIP); canvas.setFontAndSize(bf, 24); canvas.showText(text); canvas.endText(); canvas.addTemplate(template, 360, 610); canvas.restoreState(); canvas.saveState(); canvas.beginText(); canvas.setTextMatrix(360, 570); canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE_CLIP); canvas.setFontAndSize(bf, 24); canvas.showText(text); canvas.endText(); canvas.addTemplate(template, 360, 570); canvas.restoreState(); canvas.saveState(); canvas.beginText(); canvas.setTextMatrix(360, 530); canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE_CLIP); canvas.setFontAndSize(bf, 24); canvas.showText(text); canvas.endText(); canvas.addTemplate(template, 360, 530); canvas.restoreState(); canvas.saveState(); canvas.beginText(); canvas.setTextMatrix(360, 490); canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_CLIP); canvas.setFontAndSize(bf, 24); canvas.showText(text); canvas.endText(); canvas.addTemplate(template, 360, 490); canvas.restoreState(); // step 5 //document.add((Element) pdfAcroForm); document.close(); }
From source file:com.dandymadeproductions.ajqvue.io.PDFDataTableDumpThread.java
License:Open Source License
public void onEndPage(PdfWriter writer, Document document) { PdfContentByte cb; String text;/* www.j a va2 s . co m*/ float textSize; float textBase; float adjust; cb = writer.getDirectContent(); textBase = document.bottom() - 20; cb.beginText(); cb.setFontAndSize(BASE_FONT, 12); adjust = BASE_FONT.getWidthPoint("000", 12); cb.setTextMatrix(document.bottom(), textBase); cb.showText("Produced by iTextpdf"); text = "Page " + writer.getPageNumber() + " of "; textSize = BASE_FONT.getWidthPoint(text, 12); cb.setTextMatrix(document.right() - textSize - adjust, textBase); cb.showText(text); cb.endText(); if (pdfTemplate != null) cb.addTemplate(pdfTemplate, document.right() - adjust, textBase); }
From source file:com.dandymadeproductions.myjsqlview.io.PDFDataTableDumpThread.java
License:Open Source License
public void onEndPage(PdfWriter writer, Document document) { PdfContentByte cb = writer.getDirectContent(); String text = "Page " + writer.getPageNumber() + " of "; float textSize = BASE_FONT.getWidthPoint(text, 12); float textBase = document.bottom() - 20; cb.beginText();/*from w w w . j a va 2s .co m*/ cb.setFontAndSize(BASE_FONT, 12); float adjust = BASE_FONT.getWidthPoint("000", 12); cb.setTextMatrix(document.right() - textSize - adjust, textBase); cb.showText(text); cb.endText(); cb.addTemplate(pdfTemplate, document.right() - adjust, textBase); }
From source file:com.example.admin.avoidq.billGenerated.java
private void createHeadings(PdfContentByte cb, float x, float y, String text) { cb.beginText();/*ww w.j a v a2s .co m*/ cb.setFontAndSize(bfBold, 8); cb.setTextMatrix(x, y); cb.showText(text.trim()); cb.endText(); }
From source file:dbedit.actions.ExportPdfAction.java
License:Open Source License
/** * Print page numbers on right bottom corner * @param writer/* w w w . jav a 2 s. co m*/ * @param document */ @Override public void onEndPage(PdfWriter writer, Document document) { PdfContentByte cb = writer.getDirectContent(); String text = String.format("Page %d of ", writer.getPageNumber()); float textSize = BASE_FONT.getWidthPoint(text, 12); float textBase = document.bottom() - 20; cb.beginText(); cb.setFontAndSize(BASE_FONT, 12); float adjust = BASE_FONT.getWidthPoint("000", 12); cb.setTextMatrix(document.right() - textSize - adjust, textBase); cb.showText(text); cb.endText(); cb.addTemplate(pdfTemplate, document.right() - adjust, textBase); }