List of usage examples for com.itextpdf.text.pdf PdfStamper getUnderContent
public PdfContentByte getUnderContent(final int pageNum)
PdfContentByte
to write under the page of the original document. From source file:fattura.Fattura.java
public void setFattura(String cliente, String data, AtomicInteger numerofattura, PdfStamper s) throws SQLException, DocumentException, FileNotFoundException, IOException { //Ho messo che il numero della fattura va passato come parametro, voglio capire se si pu fare altrimenti (con un contatore) try {/*from w w w.j av a2 s . com*/ s.getAcroFields().setField("Num", numerofattura.toString()); // sistemare s.getAcroFields().setField("Data", data); s.getAcroFields().setField("Nome", cliente); PdfContentByte content = s.getUnderContent(1);//1 for the first page BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 7); inserisciDatiMaglie(cliente, data, s); inserisciDatiBorse(cliente, data, s); inserisciDatiPanta(cliente, data, s); inserisciDatiGiubb(cliente, data, s); inserisciDatiFelpe(cliente, data, s); inserisciDatiPubb(cliente, data, s); setImporti(s); content.endText(); s.close(); } catch (IOException | DocumentException e) { } }
From source file:fattura.Fattura.java
public void inserisciDatiMaglie(String cliente, String data, PdfStamper s) throws SQLException, IOException, DocumentException { ArrayMaglia arraymaglia = new ArrayMaglia(); arraymaglia.ArrayIDmaglia(cliente, data); float importo; PdfContentByte content = s.getUnderContent(1);//1 for the first page BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); content.setFontAndSize(bf, 7);/*ww w . j ava 2 s . c o m*/ for (int j = 0; j < arraymaglia.IDmaglie.length; j++) { arraymaglia.accessoMaglie(j); importo = arraymaglia.importoMaglia(j); String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo, solo un appoggio importi.add(importo); //salva l'importo maglia nella prima posizione array i cui elementi poi andranno sommati per calcolare il totale for (int z = 0; z < arraymaglia.riga.length; z++) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, arraymaglia.riga[z] + " ", 95 + x, 538 - y, 0); x += 97; //sposta la coordinata y ad ogni stampa } content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Maglia", 95 + x, 538 - y, 0); x += 96; content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0); x = 0; y += 20; } }
From source file:fattura.Fattura.java
public void inserisciDatiBorse(String cliente, String data, PdfStamper s) throws SQLException, IOException, DocumentException { ArrayBorsa arrayborsa = new ArrayBorsa(); arrayborsa.ArrayIDborsa(cliente, data); float importo; PdfContentByte content = s.getUnderContent(1);//1 for the first page BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); content.setFontAndSize(bf, 7);/*from ww w. j a va 2 s . co m*/ for (int j = 0; j < arrayborsa.IDborse.length; j++) { arrayborsa.accessoBorse(j); importo = arrayborsa.importoBorsa(j); String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo, solo un appoggio importi.add(importo); for (int z = 0; z < arrayborsa.riga.length; z++) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, arrayborsa.riga[z] + " ", 95 + x, 538 - y, 0); x += 97; //sposta la coordinata y ad ogni stampa } content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Borsa", 95 + x, 538 - y, 0); x += 97; content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0); x = 0; y += 20; } //MI calcolar il prezzo totale man mano che calcolo i preventivi lo agggiungo! }
From source file:fattura.Fattura.java
public void inserisciDatiPanta(String cliente, String data, PdfStamper s) throws SQLException, IOException, DocumentException { ArrayPantalone arraypanta = new ArrayPantalone(); arraypanta.ArrayIDpantalone(cliente, data); float importo = (float) 0.00; PdfContentByte content = s.getUnderContent(1);//1 for the first page BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); content.setFontAndSize(bf, 7);/*from ww w.j a v a2s .c om*/ for (int j = 0; j < arraypanta.IDpantaloni.length; j++) { arraypanta.accessoPantaloni(j); importo = arraypanta.importoPanta(j); String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo, solo un appoggio importi.add(importo); for (int z = 0; z < arraypanta.riga.length; z++) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, arraypanta.riga[z] + " ", 95 + x, 538 - y, 0); x += 97; //sposta la coordinata y ad ogni stampa } content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Pantalone", 95 + x, 538 - y, 0); x += 97; content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0); x = 0; y += 20; } }
From source file:fattura.Fattura.java
public void inserisciDatiGiubb(String cliente, String data, PdfStamper s) throws SQLException, IOException, DocumentException { ArrayGiubbotto arraygiubb = new ArrayGiubbotto(); arraygiubb.ArrayIDgiubbotto(cliente, data); float importo; PdfContentByte content = s.getUnderContent(1);//1 for the first page BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); content.setFontAndSize(bf, 7);//from w ww . j a v a2 s.co m for (int j = 0; j < arraygiubb.IDgiubbotti.length; j++) { arraygiubb.accessoGiubbotti(j); importo = arraygiubb.importoGiubbotto(j); String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo, solo un appoggio importi.add(importo); for (int z = 0; z < arraygiubb.riga.length; z++) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, arraygiubb.riga[z] + " ", 95 + x, 538 - y, 0); x += 97; //sposta la coordinata y ad ogni stampa } content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Giubbotto", 95 + x, 538 - y, 0); x += 97; content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0); x = 0; y += 20; } }
From source file:fattura.Fattura.java
public void inserisciDatiFelpe(String cliente, String data, PdfStamper s) throws SQLException, IOException, DocumentException { ArrayFelpa arrayfelpa = new ArrayFelpa(); arrayfelpa.ArrayIDfelpa(cliente, data); float importo; PdfContentByte content = s.getUnderContent(1);//1 for the first page BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); content.setFontAndSize(bf, 7);// w w w . j a v a 2 s .co m for (int j = 0; j < arrayfelpa.IDfelpe.length; j++) { arrayfelpa.accessoFelpe(j); importo = arrayfelpa.importoFelpa(j); String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo, solo un appoggio importi.add(importo); for (int z = 0; z < arrayfelpa.riga.length; z++) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, arrayfelpa.riga[z] + " ", 95 + x, 538 - y, 0); x += 97; //sposta la coordinata y ad ogni stampa } content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Felpa", 95 + x, 538 - y, 0); x += 97; content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0); x = 0; y += 20; } //MI calcolar il prezzo totale man mano che calcolo i preventivi lo agggiungo! }
From source file:fattura.Fattura.java
public void inserisciDatiPubb(String cliente, String data, PdfStamper s) throws SQLException, IOException, DocumentException { ArrayPubblicita arraypubb = new ArrayPubblicita(); arraypubb.ArrayIDpubb(cliente, data); float importo; PdfContentByte content = s.getUnderContent(1);//1 for the first page BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); content.setFontAndSize(bf, 7);//from w w w . j av a2 s . c o m for (int j = 0; j < arraypubb.IDpubb.length; j++) { arraypubb.accessoPubb(j); importo = arraypubb.importoPubblicita(j); String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo, solo un appoggio importi.add(importo); //salva l'importo maglia nella prima posizione array i cui elementi poi andranno sommati per calcolare il totale for (int z = 0; z < arraypubb.riga.length; z++) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, arraypubb.riga[z] + " ", 95 + x, 538 - y, 0); x += 97; //sposta la coordinata y ad ogni stampa } content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Mat. Pubb.", 95 + x, 538 - y, 0); x += 101; content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0); x = 0; y += 20; } }
From source file:managedbeans.descargas.PDFConversionDemo.java
public static void main(String[] args) { try {/* ww w. j a v a2 s . co m*/ //Read file using PdfReader PdfReader pdfReader = new PdfReader("HelloWorld.pdf"); //Modify file using PdfReader PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream("HelloWorld-modified.pdf")); Image image = Image.getInstance("temp.png"); image.scaleAbsolute(100, 50); image.setAbsolutePosition(100f, 700f); for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte content = pdfStamper.getUnderContent(i); content.addImage(image); } pdfStamper.close(); } catch (IOException | DocumentException e) { logger.warn("failed to ...." + e); } }
From source file:me.Aron.Heinecke.fbot.lib.Converter.java
License:Apache License
/*** * Add a note to the bottom of a pdf file in italic font * @param rfile file to be read from//from w w w . j a v a2 s . c o m * @param wfile file to be written to * @param text text to add * @return path to the resulting pdf, null if it failed */ private String addPDFNote(File rfile, File wfile, String text) { try { PdfReader pdfReader = new PdfReader(rfile.getAbsolutePath()); PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(wfile)); for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte cb = pdfStamper.getUnderContent(i); BaseFont bf = BaseFont.createFont(); bf.setPostscriptFontName("ITALIC"); cb.beginText(); cb.setFontAndSize(bf, 12); cb.setTextMatrix(10, 20); cb.showText(text); cb.endText(); } pdfStamper.close(); return wfile.getAbsolutePath(); } catch (IOException | DocumentException e) { fbot.getLogger().exception("converter", e); return null; } }
From source file:net.algem.edition.PdfHandler.java
License:Open Source License
public void createPdf(String fileName, ByteArrayOutputStream out, short templateType) throws IOException, DocumentException { try {/*w w w . ja va2s.c o m*/ File tmpFile = File.createTempFile(fileName, ".pdf"); final String target = tmpFile.getPath(); PageTemplate pt = getTemplate(templateType); PdfReader reader = new com.itextpdf.text.pdf.PdfReader(out.toByteArray()); if (pt != null) { PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(target)); // PdfStamper stamper = new PdfStamper(reader, new PrintStream(new FileOutputStream(target), true, "UTF-8")); PdfReader model = new com.itextpdf.text.pdf.PdfReader(pt.getContent()); PdfImportedPage importedPage = stamper.getImportedPage(model, 1); for (int i = 1; i <= reader.getNumberOfPages(); i++) { PdfContentByte canvas = stamper.getUnderContent(i); canvas.addTemplate(importedPage, 0, 0); } stamper.getWriter().freeReader(model); model.close(); stamper.close(); } else { PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(target)); //PdfStamper stamper = new PdfStamper(reader, new PrintStream(new FileOutputStream(target), true, "UTF-8")); stamper.close(); } preview(target, null); } catch (SQLException ex) { GemLogger.logException(ex); } }