List of usage examples for org.apache.pdfbox.pdmodel PDPageContentStream drawLine
@Deprecated public void drawLine(float xStart, float yStart, float xEnd, float yEnd) throws IOException
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox2.TableDrawUtils.java
License:EUPL
public static void drawBorder(PDPage page, PDPageContentStream contentStream, float x, float y, float width, float height, PDFBoxTable abstractTable, PDDocument doc, boolean subtable, ISettings settings) throws PdfAsException { try {// w ww .j a va2s . co m logger.debug("Drawing Table borders for " + abstractTable.getOrigTable().getName()); final int rows = abstractTable.getRowCount(); float border = abstractTable.style.getBorder(); float[] colsSizes = getColSizes(abstractTable); if (border > 0) { contentStream.setLineWidth(border); float x_from = x; float x_to = x + width; float y_from = y + height; float y_to = y + height; // draw first line logger.debug("ROW LINE: {} {} {} {}", x_from, y_from, x_to, y_from); contentStream.drawLine(x, y_from, x_to, y_from); // Draw all row borders for (int i = 0; i < rows; i++) { y_from -= abstractTable.getRowHeights()[i]; // Draw row border! logger.debug("ROW LINE: {} {} {} {}", x_from, y_from, x_to, y_from); contentStream.drawLine(x, y_from, x_to, y_from); } // reset y for "line feed" y_from = y + height; y_to = y_from - abstractTable.getRowHeights()[0]; // Draw all column borders for (int i = 0; i < rows; i++) { ArrayList<Entry> row = abstractTable.getRow(i); // reset x for "line feed" x_from = x; // draw first line logger.debug("COL LINE: {} {} {} {}", x_from, y_from, x_from, y_to); contentStream.drawLine(x_from, y_from, x_from, y_to); for (int j = 0; j < row.size(); j++) { Entry cell = (Entry) row.get(j); for (int k = 0; k < cell.getColSpan(); k++) { if (k + j < colsSizes.length) { x_from += colsSizes[k + j]; } } logger.debug("COL LINE: {} {} {} {}", x_from, y_from, x_from, y_to); contentStream.drawLine(x_from, y_from, x_from, y_to); } if (i + 1 < rows) { y_from = y_to; y_to = y_from - abstractTable.getRowHeights()[i + 1]; } } } } catch (Throwable e) { logger.warn("drawing table borders", e); throw new PdfAsException("drawing table borders", e); } }
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox2.TableDrawUtils.java
License:EUPL
private static void drawDebugLine(PDPageContentStream contentStream, float x, float y, float width, float height, ISettings settings) { if ("true".equals(settings.getValue(TABLE_DEBUG))) { try {/*from www . ja v a 2s .co m*/ contentStream.setStrokingColor(Color.RED); contentStream.drawLine(x, y, x + width, y); contentStream.setStrokingColor(Color.BLUE); contentStream.drawLine(x, y, x, y - height); contentStream.setStrokingColor(Color.GREEN); contentStream.drawLine(x + width, y, x + width, y - height); contentStream.setStrokingColor(Color.ORANGE); contentStream.drawLine(x, y - height, x + width, y - height); contentStream.setStrokingColor(Color.BLACK); } catch (Throwable e) { e.printStackTrace(); } } }
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox2.TableDrawUtils.java
License:EUPL
private static void drawDebugLineString(PDPageContentStream contentStream, float x, float y, float width, float height, float descent, ISettings settings) { if ("true".equals(settings.getValue(TABLE_DEBUG))) { try {//from w ww . j a v a 2s.co m contentStream.setStrokingColor(Color.RED); contentStream.drawLine(x, y, x + width, y); contentStream.setStrokingColor(Color.BLUE); contentStream.drawLine(x, y, x, y - height); contentStream.setStrokingColor(Color.GREEN); contentStream.drawLine(x + width, y, x + width, y - height); contentStream.setStrokingColor(Color.ORANGE); contentStream.drawLine(x, y - height, x + width, y - height); contentStream.setStrokingColor(Color.MAGENTA); contentStream.drawLine(x, y + (descent * (-1)) - height, x + width, y + (descent * (-1)) - height); contentStream.setStrokingColor(Color.BLACK); } catch (Throwable e) { e.printStackTrace(); } } }
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox2.TableDrawUtils.java
License:EUPL
private static void drawDebugPadding(PDPageContentStream contentStream, float x, float y, float padding, float width, float height, ISettings settings) { if ("true".equals(settings.getValue(TABLE_DEBUG))) { try {// w w w . j a v a 2 s. co m contentStream.setStrokingColor(Color.RED); contentStream.drawLine(x, y, x + padding, y - padding); contentStream.drawLine(x + width, y, x + width - padding, y - padding); contentStream.drawLine(x + width, y - height, x + width - padding, y - height + padding); contentStream.drawLine(x, y - height, x + padding, y - height + padding); contentStream.setStrokingColor(Color.BLACK); } catch (Throwable e) { e.printStackTrace(); } } }
From source file:br.com.techne.gluonsoft.pdfgenerator.PDFGenerator.java
License:Apache License
/** * Create a page with table./* w w w. j ava 2 s . c om*/ * @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:br.com.techne.gluonsoft.pdfgenerator.PDFGenerator.java
License:Apache License
/** * Create a page with table./*w w w. j a v a 2s . co m*/ * @param tableTitle Table Title * @param strTableContent Array of Strings, where the column's titles goes into the first array line and the data goes into others lines. * @throws IOException */ @SuppressWarnings("deprecation") public void addNewTable(String tableTitle, String[][] strTableContent) throws IOException { PDPage tablePage = new PDPage(PDRectangle.A4); PDRectangle rect = new PDRectangle(); rect = tablePage.getMediaBox(); this.getPdfDocument().addPage(tablePage); PDPageContentStream pageContent = new PDPageContentStream(this.getPdfDocument(), tablePage); final float margin = 20f; final int tableRows = strTableContent.length; final int tableColumns = strTableContent[0].length; 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); // Fonte inicial para o ttulo das colunas float textPosX = margin + tableCelMargin; float textPosY = PAGE_INITIAL_Y_POSITION - 15; // Title float centerX = tableWidth / 2 - (margin * 2); pageContent.beginText(); pageContent.newLineAtOffset(centerX, PAGE_INITIAL_Y_POSITION + 5); pageContent.showText(tableTitle); pageContent.endText(); // Cels' content (Add the text) for (int l = 0; l < strTableContent.length; l++) { for (int c = 0; c < strTableContent[l].length; c++) { String celText = strTableContent[l][c]; if (l > 0) { pageContent.setFont(FONT_PLAIN, FONT_SIZE_DEFAULT); } pageContent.beginText(); pageContent.newLineAtOffset(textPosX, textPosY); pageContent.showText(celText); pageContent.endText(); textPosX += tableColWidth; } textPosY -= rowHeigth; textPosX = margin + tableCelMargin; } pageContent.close(); }
From source file:ch.eggbacon.app.pdf.PDFCreator.java
License:Open Source License
public void drawTablePage(PDPageContentStream contentStream, String[][] content) throws IOException { final float y = PDFConstants.PAPER_HEIGHT - PDFConstants.MARGIN; final int margin = PDFConstants.MARGIN; final int rows = content.length; final int cols = content[0].length; final float rowHeight = 20f; final float tableWidth = PDFConstants.PAPER_WIDTH - (2 * margin); final float tableHeight = rowHeight * rows; final float colWidth = tableWidth / (float) cols; final float cellMargin = 5f; //draw the rows float nexty = y; for (int i = 0; i <= rows; i++) { contentStream.drawLine(margin, nexty, margin + tableWidth, nexty); nexty -= rowHeight;/*from w ww. ja v a2s . c o m*/ } //draw the columns float nextx = margin; for (int i = 0; i <= cols; i++) { contentStream.drawLine(nextx, y, nextx, y - tableHeight); nextx += colWidth; } //now add the text contentStream.setFont(PDType1Font.HELVETICA, 12); float textx = margin + cellMargin; float texty = y - 15; for (int i = 0; i < content.length; i++) { for (int j = 0; j < content[i].length; j++) { String text = content[i][j]; contentStream.beginText(); contentStream.moveTextPositionByAmount(textx, texty); contentStream.drawString(text); contentStream.endText(); textx += colWidth; } texty -= rowHeight; textx = margin + cellMargin; } }
From source file:controladores3.controladorGenerarLiquidaciones.java
public boolean generarLiquidaciones() throws FileNotFoundException, TransformerException, IOException, FOPException { Thread runnable = new Thread() { public void run() { try { modeloFacturas rutas = new modeloFacturas(); dfs.setCurrencySymbol("$ "); dfs.setGroupingSeparator('.'); dfs.setMonetaryDecimalSeparator('.'); ((DecimalFormat) FORMAT).setDecimalFormatSymbols(dfs); controladores.controladorPrincipal miControlador = new controladorPrincipal(); modelos.modeloEmpleados liquidaciones = new modeloEmpleados(); modelos3.modeloRemuneraciones remuneraciones = new modeloRemuneraciones(); String[][] data = liquidaciones.obtenerRemuneraciones2(getMes(), getYear()); String[][] imp2cat = remuneraciones.obtenerTablaImpuesto(); // float uf = remuneraciones.obtenerUF() / 100; double uf = remuneraciones.obtenerUF(); int numEmp = data.length; String path = "Liquidaciones " + per; File dir = new File(path); dir.mkdir();//from w ww . j ava2 s .c om // int bono300 = miControlador.obtenerBono300(); for (int i = 0; i < numEmp; i++) { String fileName = path + "/" + data[i][0] + ".pdf"; // name of our file try { PDDocument doc = new PDDocument(); // creating instance of pdfDoc PDPage page = new PDPage(); doc.addPage(page); // adding page in pdf doc file int base = Integer.parseInt(data[i][2]) * Integer.parseInt(data[i][28]) / 30; //GRATIFICACION int grat = (int) (base * 0.25); //BONO ANTIGUEDAD int bonoAnt = miControlador.obtenerBonoAnt(data[i][5]); //BONO 300 // int totalBon300 = bono300 * Integer.parseInt(data[i][9]); int totalBon300 = Integer.parseInt(data[i][27]); //BONO ADICIONAL int bonoAd = Integer.parseInt(data[i][11]); //BONO RESPONSABILIDAD int bonoResp = 0; //BONO ADICIONAL double bonoCol1 = Double.parseDouble(data[i][8]); double bonoCol30 = Double.parseDouble(data[i][9]); double bonoCol = bonoCol1 + bonoCol30 / 2; int totalBonCol = (int) Math.round(((double) base * 0.0077777) * bonoCol); //HORAS EXTRA double horasExNor = Double.parseDouble(data[i][12]); double horasExFes = Double.parseDouble(data[i][13]); double horasEx = 0; double bonoHor = 0; double cantHorEx = 0; //total de horas extras normales = 1; festivas = 2 double totalHorex = 0; double resHorEx = 0; if (horasExNor > 45) { cantHorEx = 45; totalHorex = 45; resHorEx = horasExNor - 45; } else { cantHorEx = horasExNor; totalHorex = cantHorEx; } if (cantHorEx + horasExFes > 45) { resHorEx = resHorEx + (horasExFes - 45 + cantHorEx) * 2; totalHorex = 45 - cantHorEx; cantHorEx = 45; } else { cantHorEx += horasExFes; totalHorex += horasExFes * 2; } //BONO ASIGNACION VOLUNTARIA double totalBonoAV = base * 0.0077777 * resHorEx; double valorHorEx = (int) ((double) base * 0.0077777 * totalHorex); //TOTAL IMPONIBLE double totImp = base + grat + bonoAnt + bonoAd + bonoResp + totalBonoAV + totalBonCol + totalBon300 + valorHorEx; //DESCUENTO AFP int descAFP = Integer.parseInt(data[i][21]); int totalAFP = (int) (totImp * ((double) descAFP / 10000)); int sis = (int) (totImp * 0.0141); //DESCUENTO SALUD double descSalud = 0, totalSalud = 0; String salud; if (data[i][4].toLowerCase().compareTo("fonasa") == 0) { salud = "FONASA"; descSalud = Integer.parseInt(data[i][22]); totalSalud = (int) (totImp * ((double) descSalud / 10000)); } else { if (data[i][23].compareTo("") == 0) { salud = data[i][4]; } else { salud = data[i][23]; } descSalud = ((double) Integer.parseInt(data[i][24]) / 1000) * uf; totalSalud = descSalud; } //DESCUENTO CESANTIA int ces = (int) (totImp * 0.006); int cesEmp = (int) (totImp * 0.024); //DESCUENTOS LEGALES double descLegales = ces + totalSalud + totalAFP; //TOTAL TRIBUTABLE double totTrib = totImp - totalAFP - totalSalud - ces; int descRenta = 0; double totAux = 0; for (String[] imp2cat1 : imp2cat) { if (totTrib > Float.parseFloat(imp2cat1[0]) / 10 && totTrib <= Float.parseFloat(imp2cat1[1]) / 10) { descRenta = (int) (totTrib * Float.parseFloat(imp2cat1[2]) / 1000 - Float.parseFloat(imp2cat1[3]) / 100); totAux = totTrib - descRenta; break; } } //CAJA COMPENSACION int caja = Integer.parseInt(data[i][15]); //ASIGNACION FAMILIAR int af = Integer.parseInt(data[i][16]); //LIQ ALCANZADO double liqAl = totAux - caja; //COLACION int col = Integer.parseInt(data[i][6]); //TRANSPORTE int trans = Integer.parseInt(data[i][7]); //TOTAL NO IMPONIBLE int noImp = trans + col + af; //ANTICIPO ADELANTO PRESTAMOS int antic = Integer.parseInt(data[i][17]); int adel = Integer.parseInt(data[i][18]); int pres = Integer.parseInt(data[i][19]); int cuo = Integer.parseInt(data[i][20]); int cuoPres = 0; int cuores = Math.max(0, Integer.parseInt(data[i][26]) - 1); if (cuo != 0) { cuoPres = pres / cuo; } //DESCUENTOS MENSUALES int descMensuales = caja + antic + adel + cuoPres + descRenta; //TOTAL HABERES double totalHaberes = noImp + totImp; //TOTAL DESCUENTOS int totDesc = antic + adel + cuoPres + caja; //LIQUIDO double liq = liqAl + col + trans + af - antic - adel - cuoPres; PDPageContentStream content = new PDPageContentStream(doc, page); //HEADER content.beginText(); content.setFont(PDType1Font.HELVETICA, 10); content.setLeading(14.5f); content.moveTextPositionByAmount(50, 770); content.showText("GRUAS SANTA TERESITA LTDA."); content.newLineAtOffset(200, 0); content.showText("LIQUIDACIN TRABAJADOR"); content.newLineAtOffset(200, 0); content.showText(per); content.newLineAtOffset(-400, 0); content.newLine(); content.showText("77.037.960-1"); content.newLine(); content.newLine(); content.showText("Nombre: " + data[i][1]); content.newLineAtOffset(400, 0); content.showText("Contrato: " + data[i][25]); content.newLineAtOffset(-400, 0); content.newLine(); content.showText("Rut: " + data[i][0]); content.endText(); content.drawLine(30, 700, 600, 700); //LEFT SIDE content.beginText(); content.setFont(PDType1Font.HELVETICA, 9); content.setLeading(14.5f); content.moveTextPositionByAmount(120, 650); content.showText("HABERES"); content.endText(); content.drawLine(45, 645, 245, 645); content.beginText(); content.moveTextPositionByAmount(50, 635); content.showText("Sueldo base proporcional"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(base)); content.newLineAtOffset(-150, -15); double horex = Double.parseDouble(data[i][13]); if (horex > 45) { horex = 45; } content.showText("Horas extra ( " + cantHorEx + " horas )"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(valorHorEx)); content.newLineAtOffset(-150, -15); content.showText("Gratificacin:"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(grat)); content.newLineAtOffset(-150, -15); content.showText("Bono aos trabajados"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(bonoAnt)); content.newLineAtOffset(-150, -15); content.showText("Bono horas"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(totalBon300)); content.newLineAtOffset(-150, -15); content.showText("Bono asignacin voluntaria"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(totalBonoAV)); content.newLineAtOffset(-150, -15); content.showText("Bono adicional"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(totalBonCol)); content.newLineAtOffset(-150, -15); content.showText("Otros bonos"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(bonoAd)); content.endText(); content.drawLine(45, 515, 245, 515); content.beginText(); content.moveTextPositionByAmount(50, 500); content.showText("Imponible"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(totImp)); content.newLineAtOffset(-150, -15); content.endText(); content.drawLine(45, 493, 245, 493); content.beginText(); content.moveTextPositionByAmount(50, 470); content.showText("Colacin"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(col)); content.newLineAtOffset(-150, -15); content.showText("Transporte"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(trans)); content.newLineAtOffset(-150, -15); content.showText("Asignacin familiar"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(af)); content.endText(); content.drawLine(45, 425, 245, 425); content.beginText(); content.moveTextPositionByAmount(50, 410); content.showText("No imponible"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(noImp)); content.endText(); content.drawLine(45, 403, 245, 403); content.drawLine(45, 380, 245, 380); content.beginText(); content.moveTextPositionByAmount(50, 365); content.showText("Total haberes"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(totalHaberes)); content.endText(); content.beginText(); content.setFont(PDType1Font.HELVETICA, 9); content.setLeading(14.5f); content.moveTextPositionByAmount(65, 280); content.showText("APORTES LEGALES EMPLEADOR"); content.endText(); content.drawLine(45, 275, 245, 275); content.beginText(); content.moveTextPositionByAmount(50, 265); content.showText("SIS"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(sis)); content.newLineAtOffset(-150, -15); content.showText("Seguro de cesanta empleador"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(cesEmp)); content.endText(); content.drawLine(45, 243, 245, 243); //RIGHT SIDE content.beginText(); content.moveTextPositionByAmount(410, 650); content.showText("DESCUENTOS"); content.endText(); content.drawLine(345, 645, 545, 645); content.beginText(); content.moveTextPositionByAmount(350, 635); content.showText("Descuento AFP"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(totalAFP)); content.newLineAtOffset(-150, -15); content.showText("Descuento salud"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(totalSalud)); content.newLineAtOffset(-150, -15); content.showText("Seguro de cesanta trabajador"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(ces)); content.endText(); content.drawLine(345, 585, 545, 585); content.beginText(); content.moveTextPositionByAmount(350, 570); content.showText("Descuentos legales"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(descLegales)); content.endText(); content.drawLine(345, 563, 545, 563); content.beginText(); content.moveTextPositionByAmount(350, 545); content.showText("Impuesto a la renta"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(descRenta)); content.newLineAtOffset(-150, -15); content.showText("Caja de compensacin"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(caja)); content.newLineAtOffset(-150, -15); content.showText("Anticipo"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(antic)); content.newLineAtOffset(-150, -15); content.showText("Adelanto"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(adel)); content.newLineAtOffset(-150, -15); content.showText("Prstamo"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(cuoPres)); content.newLineAtOffset(-150, -15); content.showText("Cuotas restantes"); content.newLineAtOffset(150, 0); content.showText(String.valueOf(cuores)); content.endText(); content.drawLine(345, 455, 545, 455); content.beginText(); content.moveTextPositionByAmount(350, 440); content.showText("Descuentos mensuales"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(descMensuales)); content.endText(); content.drawLine(345, 433, 545, 433); content.drawLine(345, 400, 545, 400); content.beginText(); content.moveTextPositionByAmount(350, 385); content.showText("Total descuentos"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(descLegales + descMensuales)); content.endText(); content.drawLine(345, 378, 545, 378); //CENTER content.drawLine(180, 335, 400, 335); content.beginText(); content.moveTextPositionByAmount(190, 320); content.showText("Total a pago"); content.newLineAtOffset(150, 0); content.showText(FORMAT.format(liq)); content.endText(); content.drawLine(180, 313, 400, 313); content.close(); doc.save(fileName); // saving as pdf file with name perm doc.close(); // cleaning memory } catch (IOException e) { System.out.println(e.getMessage()); } } JOptionPane.showMessageDialog(null, "Liquidaciones de sueldo generadas con xito", "Operacin exitosa", JOptionPane.INFORMATION_MESSAGE); // liquidaciones.limpiarRemuneraciones(); } catch (Exception e) { e.printStackTrace(); } } }; //runnable.run(); runnable.start(); return true; }
From source file:controladores4.controladorReportes.java
public boolean generarInformeCobranza(final JTable tabla, final int[] rows) { DateFormat perDate = new SimpleDateFormat("MMMM-yyyy"); DateFormat date = new SimpleDateFormat("dd-MM-yyyy"); final String per = date.format(new Date()); final NumberFormat FORMAT = NumberFormat.getCurrencyInstance(); final DecimalFormatSymbols dfs = new DecimalFormatSymbols(); Thread runnable = new Thread() { public void run() { try { dfs.setCurrencySymbol("$ "); dfs.setGroupingSeparator('.'); dfs.setMonetaryDecimalSeparator('.'); ((DecimalFormat) FORMAT).setDecimalFormatSymbols(dfs); String path = "Informes de cobranza/" + tabla.getValueAt(rows[0], 2); File dir = new File(path); dir.mkdirs();/*from w w w . j ava 2 s . c om*/ String fileName = path + "/" + per + ".pdf"; // name of our file PDDocument doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage(page); PDPageContentStream content = new PDPageContentStream(doc, page); int total = 0; modeloClientes model = new modeloClientes(); String[] data = model.obtenerRutContactoPorRazon(tabla.getValueAt(rows[0], 2).toString()); try { //HEADER content.beginText(); content.setFont(PDType1Font.HELVETICA, 10); content.setLeading(14.5f); content.moveTextPositionByAmount(50, 770); content.endText(); content.drawLine(30, 750, 600, 750); File imagen = new File(("src/icono/Logo_Gruas.bmp")); String imPath = imagen.getAbsolutePath(); System.out.println(imPath); PDImageXObject image = PDImageXObject.createFromFile(imPath, doc); content.drawImage(image, 50, 600); content.beginText(); content.moveTextPositionByAmount(400, 680); content.showText("INFORME COBRANZA"); content.newLine(); content.showText(per); content.newLineAtOffset(-130, -80); content.showText("CLIENTE"); content.newLine(); content.endText(); content.drawLine(30, 580, 600, 580); content.beginText(); content.moveTextPositionByAmount(50, 560); content.showText("Rut: "); content.newLineAtOffset(100, 0); content.showText(data[0]); content.newLineAtOffset(-100, -15); content.showText("Razn Social:"); content.newLineAtOffset(100, 0); content.showText(data[1]); content.newLineAtOffset(-100, -15); content.showText("Contacto:"); content.newLineAtOffset(100, 0); content.newLine(); content.endText(); content.drawLine(30, 510, 600, 510); content.beginText(); content.moveTextPositionByAmount(50, 480); content.showText( "Estimado cliente, las facturas que se exponen a continuacin se encuentran pendientes"); content.newLine(); content.showText("de pago. Favor regularizar la situacin."); content.endText(); content.drawLine(30, 440, 600, 440); content.beginText(); content.moveTextPositionByAmount(70, 430); content.showText("N Folio"); content.newLineAtOffset(70, 0); content.showText("Fecha"); content.newLineAtOffset(70, 0); content.showText("Das emisin"); content.newLineAtOffset(80, 0); content.showText("Total factura"); content.newLineAtOffset(80, 0); content.showText("Monto abono"); content.newLineAtOffset(80, 0); content.showText("Saldo deuda"); content.newLineAtOffset(80, 0); content.endText(); content.drawLine(30, 425, 600, 425); content.beginText(); content.moveTextPositionByAmount(75, 390); for (int row : rows) { String folio = tabla.getValueAt(row, 0).toString(); String fecha = tabla.getValueAt(row, 3).toString(); String dias = tabla.getValueAt(row, 4).toString(); int monto = Integer.parseInt(tabla.getValueAt(row, 7).toString()); int abono = Integer.parseInt(tabla.getValueAt(row, 11).toString()); int saldo = Integer.parseInt(tabla.getValueAt(row, 12).toString()); total += saldo; content.showText(folio); content.newLineAtOffset(60, 0); content.showText(fecha); content.newLineAtOffset(90, 0); content.showText(dias); content.newLineAtOffset(70, 0); content.showText(FORMAT.format(monto)); content.newLineAtOffset(80, 0); content.showText(FORMAT.format(abono)); content.newLineAtOffset(80, 0); content.showText(FORMAT.format(saldo)); content.newLineAtOffset(-380, -15); } content.newLineAtOffset(310, -45); content.showText("Total deuda"); content.newLineAtOffset(70, 0); content.showText(FORMAT.format(total)); content.endText(); content.close(); doc.save(fileName); // saving as pdf file with name perm doc.close(); // cleaning memory } catch (Exception e) { e.printStackTrace(); } JOptionPane.showMessageDialog(null, "Informe de cobranza generado con xito", "Operacin exitosa", JOptionPane.INFORMATION_MESSAGE); // liquidaciones.limpiarRemuneraciones(); } catch (Exception e) { e.printStackTrace(); } } }; //runnable.run(); runnable.start(); return true; }
From source file:org.dspace.disseminate.CitationDocumentServiceImpl.java
License:BSD License
@Override public void drawTable(PDPage page, PDPageContentStream contentStream, float y, float margin, String[][] content, PDFont font, int fontSize, boolean cellBorders) throws IOException { final int rows = content.length; final int cols = content[0].length; final float rowHeight = 20f; final float tableWidth = page.getMediaBox().getWidth() - (2 * margin); final float tableHeight = rowHeight * rows; final float colWidth = tableWidth / (float) cols; final float cellMargin = 5f; if (cellBorders) { //draw the rows float nexty = y; for (int i = 0; i <= rows; i++) { contentStream.drawLine(margin, nexty, margin + tableWidth, nexty); nexty -= rowHeight;//from ww w . j a va 2 s . co m } //draw the columns float nextx = margin; for (int i = 0; i <= cols; i++) { contentStream.drawLine(nextx, y, nextx, y - tableHeight); nextx += colWidth; } } //now add the text contentStream.setFont(font, fontSize); float textx = margin + cellMargin; float texty = y - 15; for (int i = 0; i < content.length; i++) { for (int j = 0; j < content[i].length; j++) { String text = content[i][j]; contentStream.beginText(); contentStream.moveTextPositionByAmount(textx, texty); contentStream.drawString(text); contentStream.endText(); textx += colWidth; } texty -= rowHeight; textx = margin + cellMargin; } }