List of usage examples for org.apache.pdfbox.pdmodel.common PDRectangle PDRectangle
public PDRectangle(float width, float height)
From source file:mail.java
private void bonos() throws SQLException { //**//from w w w . ja v a 2 s. c om double total = 0; ListaBono.clear(); if (idmatricula != "0") { Connection conn; try { conn = Conector.Connect(); System.out.println("Bonos"); PreparedStatement resultado; PreparedStatement bono; String sql1 = "select * from bonos b left join juzgados j on b.ID_JUZGADO=j.id_juzgado where ID_MATRICULA=? ORDER BY ANO "; bono = conn.prepareStatement(sql1); bono.setString(1, idmatricula); ResultSet ds = bono.executeQuery(); DecimalFormatSymbols simbolos = new DecimalFormatSymbols(); SimpleDateFormat formatofecha = new SimpleDateFormat("dd-MM-yyyy"); simbolos.setDecimalSeparator('.'); DecimalFormat decim = new DecimalFormat("0.00", simbolos); if (ds.first()) { ds.beforeFirst();//regresa el puntero al primer registro while (ds.next()) { int numero_expediente = ds.getInt("NUMERO_EXPTE"); String ano = ds.getString("ANO"); String caratula = ds.getString("cara"); String fecha_actuacion = ds.getString("FECHA_ACTUACION"); String juzgado = ds.getString("descripcion"); double importe = ds.getDouble("MONTOBONO"); Double monto_bono = Double.valueOf(decim.format(importe)); caratula = caratula.replaceAll("\r\n", " "); caratula = caratula.replaceAll("\n", " "); caratula = caratula.replaceAll("\\\\\\\\", ""); // Date per =formatofecha.parse(fecha_pa); // String fecha_pago = formatofecha.format(per); System.out.println(idmatricula); System.out.format("%s,%s,%s,%s,%s,%s\n", numero_expediente, ano, caratula.toLowerCase(), juzgado.toLowerCase(), fecha_actuacion, importe); ListaBono.add( new Bonos(numero_expediente, ano, caratula, juzgado, fecha_actuacion, monto_bono)); total = total + monto_bono; botones(true); } ds.close(); System.out.println(total); System.out.println(ListaBono.size()); } } catch (SQLException ex) { Logger.getLogger(mail.class.getName()).log(Level.SEVERE, null, ex); } } //** int alto = 595; int ancho = 842; PDDocument documento = new PDDocument(); PDPage paginablanco = new PDPage(new PDRectangle(ancho, alto)); documento.addPage(paginablanco); PDPageContentStream content; System.out.println(paginablanco.getMediaBox().getHeight() + "--" + paginablanco.getMediaBox().getWidth()); try { content = new PDPageContentStream(documento, paginablanco); content.beginText(); content.setFont(PDType1Font.HELVETICA, 9); content.newLineAtOffset(50, alto - 20); content.showText("Consejo Profesional de Abogacia"); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 9); content.newLineAtOffset(450, alto - 20); Locale espanol = new Locale("es", "ES"); SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE MMMM d HH:mm:ss z yyyy", espanol); String fecha = dateFormat.format(new Date()); content.showText(fecha); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 6); content.newLineAtOffset(50, alto - 28); content.showText("Direccin: San Martin 457 - Formosa"); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 10); content.newLineAtOffset(200, alto - 38); content.showText("BONOS DE ACCCIN LETRADA"); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(200, alto - 45); content.showText("Estado de Gestin de bonos del Profesional"); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 9); content.newLineAtOffset(50, alto - 60); // para que no tenga errores las tabla de mysql cotejamiento en utf8_bin al cargar en la PDF da error si esta con el tema de las content.showText("Matricula N: " + idmatricula + " Nombre: " + nombre + "," + apellido);// content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(50, alto - 75); content.showText("Item"); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(70, alto - 75); content.showText("Expte"); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(100, alto - 75); content.showText("Ao"); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(130, alto - 75); content.showText("Caratula"); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(500, alto - 75); content.showText("Juzgado"); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(650, alto - 75); content.showText("Monto"); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(680, alto - 75); content.showText("Vencimiento"); content.endText(); content.setNonStrokingColor(Color.DARK_GRAY); content.addRect(25, 45, 700, 400); // content.fill(); int j = 0; int renglon = alto - 100; for (int i = 0; i < ListaBono.size(); i++) { content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); j++; content.newLineAtOffset(50, renglon); content.showText(String.valueOf(i + 1)); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(70, renglon); content.showText(String.valueOf(ListaBono.get(i).getNumero_expediente())); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(100, renglon); content.showText(ListaBono.get(i).getAno()); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(130, renglon); content.showText(String.valueOf(ListaBono.get(i).getCaratula())); content.endText(); content.setFont(PDType1Font.COURIER, 8); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(500, renglon); content.showText(ListaBono.get(i).getJuzgado()); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(650, renglon); content.showText(String.valueOf(ListaBono.get(i).getMonto_bono())); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 8); content.newLineAtOffset(680, renglon); content.showText(ListaBono.get(i).getFecha_pago()); content.endText(); renglon = renglon - 13; } content.beginText(); content.newLineAtOffset(100, renglon - 20); DecimalFormatSymbols simbolos = new DecimalFormatSymbols(); simbolos.setDecimalSeparator('.'); DecimalFormat decim = new DecimalFormat("0.00", simbolos); content.showText("Total Bonos Adeudados :$ " + String.valueOf(decim.format(total))); content.endText(); content.close(); documento.save("matricula_" + idmatricula + "_bonos.pdf"); documento.close(); System.out.println("guardo archivo matricula_" + idmatricula + "_bonos.pdf"); // System.out.println(String.valueOf(decim.format(total))); EnviarMail.setEnabled(true); } catch (IOException ex) { EnviarMail.setEnabled(false); Logger.getLogger(mail.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ambroafb.general.PDFHelper.java
public void replace(BufferedImage img, int index) throws IOException { PDPage old = doc.getPage(index);// www. j a v a 2 s .co m float width, height; if (img.getWidth() > img.getHeight()) { width = PDRectangle.LETTER.getHeight(); height = PDRectangle.LETTER.getWidth(); } else { height = PDRectangle.LETTER.getHeight(); width = PDRectangle.LETTER.getWidth(); } PDPage newPage = new PDPage(new PDRectangle(width, height)); doc.getPages().insertAfter(newPage, old); doc.removePage(old); PDImageXObject pdImage = JPEGFactory.createFromImage(doc, img); try (PDPageContentStream contents = new PDPageContentStream(doc, newPage)) { contents.drawImage(pdImage, 0, 0, width, height); } }
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureBuilder.java
License:EUPL
public void createMyPage(PDFAsVisualSignatureDesigner properties) { PDPage page = properties.getSignaturePage(); if (page == null) { page = new PDPage(); page.setMediaBox(new PDRectangle(properties.getPageWidth(), properties.getPageHeight())); }//from www . j a v a 2 s.c o m getStructure().setPage(page); logger.info("PDF page has been created"); }
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureBuilder.java
License:EUPL
public void createPage(PDFAsVisualSignatureDesigner properties) { PDPage page = new PDPage(); page.setMediaBox(new PDRectangle(properties.getPageWidth(), properties.getPageHeight())); page.setRotation(properties.getPageRotation()); getStructure().setPage(page);/*www .jav a 2s .c o m*/ logger.debug("PDF page has been created"); }
From source file:au.org.alfred.icu.pdf.services.factories.ICUDischargeSummaryFactory.java
public static String createContent(PDDocument pdf, String icuVisitNumber, String visitNumber, String patientId, String userName, String userId) { InputStream is = null;//from w w w .j a v a2 s .c o m int yCursor = 137; int temp = yCursor; DischargeSummaryData data = new DischargeSummaryData(); PDPage pg_content; PDPageContentStream cs; String pdfName = DischargeSummaryDataBuilder.buildData(icuVisitNumber, visitNumber, patientId, userName, userId, data); try { pg_content = new PDPage(new PDRectangle(pageWidth, pageHeight)); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); Paragraph para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, data.getFinalDiagnosis()); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); temp += para.getParaHeight(); cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString("Final Diagnosis"); cs.endText(); yCursor += para.getFontHeight() * para.getLines().size(); if (yCursor > (pageHeight - footerHeight)) { pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); } write(cs, para); yCursor += 25; para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, data.getPresentingHx()); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); temp = yCursor; temp += para.getParaHeight(); if (temp > (pageHeight - footerHeight)) { pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, data.getPresentingHx()); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); } cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString("Presenting History"); cs.endText(); yCursor += para.getFontHeight() * para.getLines().size(); write(cs, para); yCursor += 25; para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, data.getPastHx()); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); temp = yCursor; temp += para.getParaHeight(); if (temp > (pageHeight - footerHeight)) { pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, data.getPastHx()); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); } cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString("Past History"); cs.endText(); yCursor += para.getFontHeight() * para.getLines().size(); write(cs, para); yCursor += 25; para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, data.getDisSumm()); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); temp = yCursor; temp += para.getParaHeight(); if (temp > (pageHeight - footerHeight)) { List<String> pages = new ArrayList<String>(); int hght = para.getParaHeight(); System.out.println("height " + hght); if (hght > pageHeight - footerHeight) { while (hght > pageHeight - footerHeight) { String div = data.getDisSumm().substring(0, data.getDisSumm().length() / 2); Paragraph p = new Paragraph(leftMargin + 5, pageHeight - 147 - 15, div); hght = p.getParaHeight(); pages.add(div); } } System.out.println("Pages: " + pages.size()); if (pages.size() > 1) { Iterator itr = pages.iterator(); while (itr.hasNext()) { String inner = (String) itr.next(); pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, inner); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString("ICU Stay Summary"); cs.endText(); yCursor += para.getFontHeight() * para.getLines().size(); write(cs, para); } } else { pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, data.getDisSumm()); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); } } cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString("ICU Stay Summary"); cs.endText(); yCursor += para.getFontHeight() * para.getLines().size(); write(cs, para); yCursor += 25; para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, data.getPendingInvestigations()); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); temp = yCursor; temp += para.getParaHeight(); if (temp > (pageHeight - footerHeight)) { pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, data.getPendingInvestigations()); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); } cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString("Current Pending Investigations"); cs.endText(); yCursor += para.getFontHeight() * para.getLines().size(); write(cs, para); yCursor += 25; if (yCursor > (pageHeight - footerHeight)) { pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); } if (data.getMicro() != null) { int k = 0; String[][] table = new String[data.getMicro().size() + 1][6]; table[k][0] = "Date"; table[k][1] = "Site"; table[k][2] = "Organism"; table[k][3] = "Sensitivity"; table[k][4] = ""; table[k][5] = ""; k++; for (Iterator<TblMicroResults> i = data.getMicro().iterator(); i.hasNext();) { TblMicroResults m = i.next(); table[k][0] = m.getMTime() == null ? "N/A" : new SimpleDateFormat("dd/MM/yy").format(m.getMTime()); table[k][1] = m.getMSite() == null ? "N/A" : m.getMSite(); table[k][2] = m.getMOrg() == null ? "N/A" : m.getMOrg(); table[k][3] = m.getMSens() == null ? "N/A" : m.getMSens(); table[k][4] = ""; table[k][5] = ""; k++; } //System.out.println(yCursor); temp = getTableHeight(pg_content, cs, pageHeight - yCursor, leftMargin, table, PDType1Font.TIMES_BOLD, PDType1Font.TIMES_ROMAN, 10); if ((yCursor + temp + 30) > (pageHeight - footerHeight)) { pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); } yCursor += 25; cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString("Microbiology Results"); cs.endText(); yCursor += 10; yCursor += drawTable(pg_content, cs, pageHeight - yCursor, leftMargin, table, PDType1Font.TIMES_BOLD, PDType1Font.TIMES_ROMAN, 10); } if (data.getOther() != null) { int k = 0; String[][] table = new String[data.getOther().size() + 1][6]; table[k][0] = "Date"; table[k][1] = "Investigation"; table[k][2] = "Results"; table[k][3] = ""; table[k][4] = ""; table[k][5] = ""; k++; for (Iterator<TblOtherResults> i = data.getOther().iterator(); i.hasNext();) { TblOtherResults m = i.next(); table[k][0] = m.getOTime() == null ? "N/A" : new SimpleDateFormat("dd/MM/yy").format(m.getOTime()); table[k][1] = m.getOInv() == null ? "N/A" : m.getOInv(); table[k][2] = m.getOResult() == null ? "N/A" : m.getOResult(); table[k][3] = ""; table[k][4] = ""; table[k][5] = ""; k++; } yCursor += 10; temp = getTableHeight(pg_content, cs, pageHeight - yCursor, leftMargin, table, PDType1Font.TIMES_BOLD, PDType1Font.TIMES_ROMAN, 10); if ((yCursor + temp + 30) > (pageHeight - footerHeight)) { pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); } yCursor += 25; cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString("Other Significant Results"); cs.endText(); yCursor += 10; yCursor += drawTable(pg_content, cs, pageHeight - yCursor, leftMargin, table, PDType1Font.TIMES_BOLD, PDType1Font.TIMES_ROMAN, 10); } if (data.getAntibiotics() != null) { int k = 0; String[][] table = new String[data.getAntibiotics().size() + 1][6]; table[k][0] = "Start Date"; table[k][1] = "Suggested End Date"; table[k][2] = "Antibiotic"; table[k][3] = "Indication"; table[k][4] = ""; table[k][5] = ""; k++; for (Iterator<TblAntibiotic> i = data.getAntibiotics().iterator(); i.hasNext();) { TblAntibiotic m = i.next(); table[k][0] = m.getAStart() == null ? "N/A" : new SimpleDateFormat("dd/MM/yy").format(m.getAStart()); table[k][1] = m.getAEnd() == null ? "N/A" : m.getAEnd(); table[k][2] = m.getAAntibiotic() == null ? "N/A" : m.getAAntibiotic(); table[k][3] = m.getAIndication() == null ? "N/A" : m.getAIndication(); table[k][4] = ""; table[k][5] = ""; k++; } temp = getTableHeight(pg_content, cs, pageHeight - yCursor, leftMargin, table, PDType1Font.TIMES_BOLD, PDType1Font.TIMES_ROMAN, 10); if ((yCursor + temp + 30) > (pageHeight - footerHeight)) { pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); } yCursor += 25; cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString("Current Antibiotic Plans"); cs.endText(); yCursor += 10; yCursor += drawTable(pg_content, cs, pageHeight - yCursor, leftMargin, table, PDType1Font.TIMES_BOLD, PDType1Font.TIMES_ROMAN, 10); } if (data.getNeuro() != null) { int k = 0; String[][] table = new String[data.getNeuro().size() + 1][7]; table[k][0] = "GCS-E"; table[k][1] = "GCS-V"; table[k][2] = "GCS-M"; table[k][3] = "Upper Motor"; table[k][4] = "Upper Sensation"; table[k][5] = "Lower Motor"; table[k][6] = "Lower Sensation"; k++; for (TblNeurology m : data.getNeuro()) { table[k][0] = m.getNGcsE() != null ? m.getNGcsE() : "N/A"; table[k][1] = m.getNGcsV() != null ? m.getNGcsV() : "N/A"; table[k][2] = m.getNGcsM() != null ? m.getNGcsM() : "N/A"; table[k][3] = m.getNUpperMotor() != null ? m.getNUpperMotor() : "N/A"; table[k][4] = m.getNUpperSens() != null ? m.getNUpperSens() : "N/A"; table[k][5] = m.getNLowerMotor() != null ? m.getNLowerMotor() : "N/A"; table[k][6] = m.getNLowerSense() != null ? m.getNLowerSense() : "N/A"; k++; } //System.out.println(table[1][1]); temp = getTableHeight(pg_content, cs, pageHeight - yCursor, leftMargin, table, PDType1Font.TIMES_BOLD, PDType1Font.TIMES_ROMAN, 10); if ((yCursor + temp + 30) > (pageHeight - footerHeight)) { pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); } yCursor += 25; cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString("Current Neurological Exam"); cs.endText(); yCursor += 10; yCursor += drawTable(pg_content, cs, pageHeight - yCursor, leftMargin, table, PDType1Font.TIMES_BOLD, PDType1Font.TIMES_ROMAN, 10); } if (data.getProcs() != null) { int k = 0; String[][] table = new String[data.getProcs().size() + 1][6]; table[k][0] = "Start Date"; table[k][1] = "System"; table[k][2] = "Intervention"; table[k][3] = "Type"; table[k][4] = "Site"; table[k][5] = "Side"; k++; for (Iterator<VwSiss> i = data.getProcs().iterator(); i.hasNext();) { VwSiss m = i.next(); if (m.getSissEndDate() == null) { table[k][0] = new SimpleDateFormat("dd/MM/yy").format(m.getSissStartDate()); table[k][1] = m.getSissSystemDesc() == null ? "-" : m.getSissSystemDesc(); table[k][2] = m.getSissInterventionDesc() == null ? "-" : m.getSissInterventionDesc(); table[k][3] = m.getSissTypeDesc() == null ? "-" : m.getSissTypeDesc(); table[k][4] = m.getSissSiteDesc() == null ? "-" : m.getSissSiteDesc(); table[k][5] = m.getSissSideDesc() == null ? "-" : m.getSissSideDesc(); //System.out.println(table[k][2]); k++; } } temp = getTableHeight(pg_content, cs, pageHeight - yCursor, leftMargin, table, PDType1Font.TIMES_BOLD, PDType1Font.TIMES_ROMAN, 10); if ((yCursor + temp + 30) > (pageHeight - footerHeight)) { pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); } yCursor += 25; cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString("Current In-Situ Devices"); cs.endText(); yCursor += 10; yCursor += drawTable(pg_content, cs, pageHeight - yCursor, leftMargin, table, PDType1Font.TIMES_BOLD, PDType1Font.TIMES_ROMAN, 10); } yCursor += 25; para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, data.getActiveProblems()); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); temp = yCursor; temp += para.getParaHeight(); if (temp > (pageHeight - footerHeight)) { pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, data.getActiveProblems()); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); } cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString("Ongoing Issues & Plan"); cs.endText(); yCursor += para.getFontHeight() * para.getLines().size(); write(cs, para); // Add Nursing Plan pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString("Nursing Plan"); cs.endText(); Iterator itr = data.getNursingPlans().keySet().iterator(); while (itr.hasNext()) { String heading = (String) itr.next(); //System.out.println(heading); List<TblCarePlan> plans = (List<TblCarePlan>) data.getNursingPlans().get(heading); if (plans.size() > 0) { TblCarePlan plan = plans.get(0); yCursor += 25; para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, plan.getCarePlanNote()); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); temp = yCursor; temp += para.getParaHeight(); if (temp > (pageHeight - footerHeight)) { pg_content = newPageBuilder(pdf, pg_content, cs, data, yCursor); cs = new PDPageContentStream(pdf, pg_content); yCursor = createNewPage(pdf, pg_content, cs, yCursor, data); para = new Paragraph(leftMargin + 5, pageHeight - yCursor - 15, plan.getCarePlanNote()); para.withColor(Color.BLACK); para.withFont(PDType1Font.TIMES_ROMAN, 12); para.withWidth(500); } cs.beginText(); cs.setFont(PDType1Font.TIMES_BOLD, 14); cs.moveTextPositionByAmount(leftMargin, pageHeight - yCursor); cs.setNonStrokingColor(darkGreen); cs.drawString(heading + " [" + DateFormat.getInstance().format(plan.getUpdateDate()) + "]"); cs.endText(); yCursor += para.getFontHeight() * para.getLines().size(); write(cs, para); } } cs.close(); pdf.addPage(pg_content); } catch (IOException ex) { java.util.logging.Logger.getLogger(ICUDischargeSummaryFactory.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (is != null) { is.close(); } } catch (IOException ex) { java.util.logging.Logger.getLogger(ICUDischargeSummaryFactory.class.getName()).log(Level.SEVERE, null, ex); } } return pdfName; }
From source file:au.org.alfred.icu.pdf.services.factories.ICUDischargeSummaryFactory.java
public static PDPage newPageBuilder(PDDocument pdf, PDPage pg_content, PDPageContentStream cs, DischargeSummaryData data, int yCursor) throws IOException { pdf.addPage(pg_content);//from w ww . j av a2s.co m cs.close(); PDPage pg = new PDPage(new PDRectangle(pageWidth, pageHeight)); return pg; }
From source file:br.com.techne.gluonsoft.pdfgenerator.PDFGenerator.java
License:Apache License
/** * Create a page with table./*from w ww .j a v a 2 s. c o m*/ * @param tableTitle Table Title * @param tableColumnsName Array of Strings with table columns titles. * @param strTableContent Array of Strings with the table data. * @throws IOException */ @SuppressWarnings("deprecation") public void addNewTable(String tableTitle, ArrayList<String> tableColumnsName, ArrayList<String> strTableContent) throws IOException { PDRectangle rectLandscapeOrientation = new PDRectangle(PDRectangle.A4.getHeight(), PDRectangle.A4.getWidth()); // Changed width to height to get Landscape Orientation PDPage tablePage = new PDPage(PDRectangle.A4); PDRectangle rect = tablePage.getMediaBox(); this.getPdfDocument().addPage(tablePage); PDPageContentStream pageContent = new PDPageContentStream(this.getPdfDocument(), tablePage); final float margin = 20f; final int tableRows = strTableContent != null ? strTableContent.size() : 0; final int tableColumns = tableColumnsName != null ? tableColumnsName.size() : 0; final float rowHeigth = 20f; final float tableWidth = rect.getWidth() - (2 * margin); final float tableHeight = rowHeigth * tableRows; final float tableColWidth = tableWidth / (float) tableColumns; final float tableCelMargin = 5f; // Draw the lines float nextY = PAGE_INITIAL_Y_POSITION; for (int r = 0; r <= tableRows; r++) { pageContent.drawLine(margin, nextY, margin + tableWidth, nextY); nextY -= rowHeigth; } // Draw the columns float nextX = margin; for (int i = 0; i <= tableColumns; i++) { pageContent.drawLine(nextX, PAGE_INITIAL_Y_POSITION, nextX, PAGE_INITIAL_Y_POSITION - tableHeight); nextX += tableColWidth; } pageContent.setFont(FONT_BOLD, FONT_SIZE_DEFAULT); // Initial Font for the columns' titles float textPosX = margin + tableCelMargin; float textPosY = PAGE_INITIAL_Y_POSITION - 15; // Title float centerX = tableWidth / 2 - (margin * 2); float xAlignLeft = margin; pageContent.beginText(); pageContent.newLineAtOffset(xAlignLeft, PAGE_INITIAL_Y_POSITION + 5); pageContent.showText(tableTitle); pageContent.endText(); // Columns' names for (int i = 0; i < tableColumnsName.size(); i++) { String columnName = tableColumnsName.get(i); System.out.println(columnName); pageContent.beginText(); pageContent.newLineAtOffset(textPosX, textPosY); pageContent.showText(columnName); pageContent.endText(); textPosX += tableColWidth; } // textPosY -= rowHeigth; // textPosX = margin + tableCelMargin; // Cels' content (Add the text) int actualCol = 0; pageContent.setFont(FONT_PLAIN, FONT_SIZE_DEFAULT); for (int i = 0; i < strTableContent.size(); i++) { if (actualCol % tableColumns == 0) { actualCol = 0; textPosY -= rowHeigth; textPosX = margin + tableCelMargin; } String celText = strTableContent.get(i); System.out.println(celText); pageContent.beginText(); pageContent.newLineAtOffset(textPosX, textPosY); pageContent.showText(celText); pageContent.endText(); textPosX += tableColWidth; actualCol++; } pageContent.close(); }
From source file:casmi.Applet.java
License:Open Source License
@Override public void drawWithGraphics(Graphics g) { setGLParam(g.getGL());//from ww w .j a v a2s . c o m drawObjects(g); updateObjects(); // Calculate real fps. { frame++; long now = System.currentTimeMillis(); long elapse = now - baseTime; if (1000 < elapse) { workingFPS = frame * 1000.0 / elapse; baseTime = now; frame = 0; } } // capture image if (saveImageFlag) { saveImageFlag = false; try { switch (imageType) { case JPG: case PNG: case BMP: case GIF: default: Screenshot.writeToFile(new File(saveFile), width, height, !saveBackground); break; case PDF: { BufferedImage bi = Screenshot.readToBufferedImage(width, height, !saveBackground); PDDocument doc = new PDDocument(); PDRectangle rect = new PDRectangle(width, height); PDPage page = new PDPage(rect); doc.addPage(page); PDXObjectImage ximage = new PDJpeg(doc, bi); PDPageContentStream contentStream = new PDPageContentStream(doc, page); contentStream.drawImage(ximage, 0, 0); contentStream.close(); doc.save(saveFile); doc.close(); break; } } } catch (GLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (COSVisitorException e) { e.printStackTrace(); } } }
From source file:ch.dowa.jassturnier.pdf.PdfGenerator.java
public PDRectangle getImageSizePdf(PDImageXObject img) { float actImageWidth = img.getWidth(); float actImageHeight = img.getHeight(); float actRatio = actImageWidth / actImageHeight; float imageWidth = 0F; float imageHeight = 0F; if (maxRatio() < actRatio) { imageWidth = imgMaxWidth();//from w ww . j a v a2 s.c o m imageHeight = imageWidth / actRatio; } else if (1 < actRatio && actRatio <= maxRatio()) { imageHeight = imgMaxHeight(); imageWidth = imageHeight * actRatio; } else if (actRatio <= 1) { imageHeight = imgMaxHeight(); imageWidth = imageHeight * actRatio; } return new PDRectangle(imageWidth, imageHeight); }
From source file:ch.rasc.downloadchart.DownloadChartServlet.java
License:Apache License
private static void handlePdf(HttpServletResponse response, byte[] imageData, Integer width, Integer height, String filename, PdfOptions options) throws IOException { response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + ".pdf\";"); try (PDDocument document = new PDDocument()) { PDRectangle format = PDPage.PAGE_SIZE_A4; if (options != null) { if ("A3".equals(options.format)) { format = PDPage.PAGE_SIZE_A3; } else if ("A5".equals(options.format)) { format = PDPage.PAGE_SIZE_A5; } else if ("Letter".equals(options.format)) { format = PDPage.PAGE_SIZE_LETTER; } else if ("Legal".equals(options.format)) { format = new PDRectangle(215.9f * MM_TO_UNITS, 355.6f * MM_TO_UNITS); } else if ("Tabloid".equals(options.format)) { format = new PDRectangle(279 * MM_TO_UNITS, 432 * MM_TO_UNITS); } else if (options.width != null && options.height != null) { Float pdfWidth = convertToPixel(options.width); Float pdfHeight = convertToPixel(options.height); if (pdfWidth != null && pdfHeight != null) { format = new PDRectangle(pdfWidth, pdfHeight); }/*from w w w .j a va 2 s . c o m*/ } } PDPage page = new PDPage(format); if (options != null && "landscape".equals(options.orientation)) { page.setRotation(90); } document.addPage(page); BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(imageData)); try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) { PDPixelMap ximage = new PDPixelMap(document, originalImage); Dimension newDimension = calculateDimension(originalImage, width, height); int imgWidth = ximage.getWidth(); int imgHeight = ximage.getHeight(); if (newDimension != null) { imgWidth = newDimension.width; imgHeight = newDimension.height; } Float border = options != null ? convertToPixel(options.border) : null; if (border == null) { border = 0.0f; } AffineTransform transform; if (page.getRotation() == null) { float scale = (page.getMediaBox().getWidth() - border * 2) / imgWidth; if (scale < 1.0) { transform = new AffineTransform(imgWidth, 0, 0, imgHeight, border, page.getMediaBox().getHeight() - border - imgHeight * scale); transform.scale(scale, scale); } else { transform = new AffineTransform(imgWidth, 0, 0, imgHeight, border, page.getMediaBox().getHeight() - border - imgHeight); } } else { float scale = (page.getMediaBox().getHeight() - border * 2) / imgWidth; if (scale < 1.0) { transform = new AffineTransform(imgHeight, 0, 0, imgWidth, imgHeight * scale + border, border); transform.scale(scale, scale); } else { transform = new AffineTransform(imgHeight, 0, 0, imgWidth, imgHeight + border, border); } transform.rotate(1.0 * Math.PI / 2.0); } contentStream.drawXObject(ximage, transform); } try { document.save(response.getOutputStream()); } catch (COSVisitorException e) { throw new IOException(e); } } }