Example usage for com.itextpdf.text Rectangle Rectangle

List of usage examples for com.itextpdf.text Rectangle Rectangle

Introduction

In this page you can find the example usage for com.itextpdf.text Rectangle Rectangle.

Prototype

public Rectangle(final float llx, final float lly, final float urx, final float ury) 

Source Link

Document

Constructs a Rectangle -object.

Usage

From source file:se.billes.pdf.renderer.request.factory.SizeFactory.java

License:Open Source License

public Rectangle getTrimBoxAsRectangle(PdfDocument request) {
    float[] trimBox = getTrimBoxInPS(request);
    return new Rectangle(trimBox[0], trimBox[1], trimBox[2], trimBox[3]);
}

From source file:Servlet.PDFServlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//  w w w  . j a va 2 s .co m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setCharacterEncoding("UTF-8");
    String strData = request.getParameter("hidden_pdfData");
    //System.out.println("strData_new --> " + strData);
    String[] strSplitData = strData.split("###");
    String strBerichtname;
    String strTable;

    strBerichtname = strSplitData[0];
    strTable = strSplitData[1];

    String strAusgabe = "Es ist ein unerwartetes Problem aufgetreten";
    boolean boolLeerbericht = true;
    HttpSession userSession = request.getSession();
    switch (strBerichtname) {
    case "Einsatzbericht leer":
        strAusgabe = generiereAusgabeEinsatzberichtLeer(strTable, strSplitData[2]);
        break;
    case "bungsbericht leer":
        strAusgabe = generiereAusgabeUebungsberichtLeer(strTable, strSplitData[2]);
        break;
    case "Ttigkeitsbericht leer":
        strAusgabe = generiereAusgabeTaetigkeitsberichtLeer(strTable, strSplitData[2]);
        break;
    case "Dynamisch":
        strAusgabe = "<h1>" + strBerichtname + "</h1>" + strTable;
        boolLeerbericht = false;
        break;
    case "Kursstatistik":
        if (strTable.split("<td>").length > 1 && strSplitData[2].split("<td>").length > 1) {
            strAusgabe = "<h1>" + strBerichtname + "</h1>" + strSplitData[2].replace("</br>", "")
                    + "<p>&nbsp;</p>" + strTable;
        } else if (strTable.split("<td>").length < 2) {
            strAusgabe = "<h1>" + strBerichtname + "</h1>" + strSplitData[2].replace("</br>", "");
        } else if (strSplitData[2].split("<td>").length < 2) {
            strAusgabe = "<h1>" + strBerichtname + "</h1>" + strTable;
        }
        boolLeerbericht = false;
        break;
    case "Digitales Fahrtenbuch":
        if (strSplitData.length > 2) {
            strAusgabe = "<h1>" + strBerichtname + "</h1>" + strSplitData[2] + "<p>&nbsp;</p>" + strTable;
        } else {
            strAusgabe = "<h1>" + strBerichtname + "</h1>" + strTable;
        }
        boolLeerbericht = false;
        break;
    case "Stundenauswertung je Mitglied je Instanz":
        strAusgabe = "<h1>" + strBerichtname + "</h1>"
                + generiereStundenauswertungJeMitgliedJeInstanz(strTable);
        boolLeerbericht = false;
        break;
    case "Geburtstagsliste":
        strAusgabe = "<h1>" + strBerichtname + " " + userSession.getAttribute("attJahr") + "</h1>" + strTable;
        boolLeerbericht = false;
        break;
    case "Dienstzeitliste":
        strAusgabe = "<h1>" + strBerichtname + " " + userSession.getAttribute("attJahrDienst") + "</h1>"
                + strTable;
        boolLeerbericht = false;
        break;
    default:
        strAusgabe = "<h1>" + strBerichtname + "</h1>" + strTable;
        boolLeerbericht = false;
    }
    String strContextPath = this.getServletContext().getRealPath("/");
    String strCSSPath1 = strContextPath + File.separator + "css" + File.separator + "pdfSimpel.css";
    String strFontPath = strContextPath + File.separator + "res" + File.separator + "Cambria.ttf";

    //FAIL - just ignore
    //strAusgabe = strAusgabe.substring(0, pos+5) + ("<thead>" + strAusgabe.split("<thead>")[1].split("</thead>")[0] + "</thead>") + strAusgabe.substring(pos+5);
    //String strHead = "<thead>" + strAusgabe.split("<thead>")[1].split("</thead>")[0] + "</thead>";
    //String strUeberschrift = "<h1>" + strAusgabe.split("<h1>")[1].split("</h1")[0] + "</h1>";
    if (!strBerichtname.contains("leer")) {
        strAusgabe = strAusgabe.replace("<table", "<table style='repeat-header: yes;' ");
    }

    Rectangle rect;
    try {
        Document document;
        if (liBerHochformat.contains(strBerichtname)) {
            document = new Document(PageSize.A4, 36, 36, 100, 54);
            rect = new Rectangle(36, 54, 559, 788);
        } else {
            document = new Document(PageSize.A4.rotate(), 36, 36, 70, 54);
            rect = new Rectangle(36, 54, 805, 559);
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        PDF_KopfFuzeile event = new PDF_KopfFuzeile(strFontPath, writer);
        writer.setBoxSize("pageRect", rect);
        writer.setPageEvent(event);

        document.open();
        HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
        htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
        CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(false);
        //hier werden die CSS files eingebunden
        cssResolver.addCssFile(strCSSPath1, true);

        if (liBerHochformat.contains(strBerichtname)) {
            cssResolver.addCssFile(strCSSPath1.replace("Simpel", "Hoch"), true);
        } else {
            cssResolver.addCssFile(strCSSPath1.replace("Simpel", "Quer"), true);
        }
        if (!boolLeerbericht) {
            cssResolver.addCssFile(strCSSPath1.replace("Simpel", "StandartBericht"), true);
        } else {
            cssResolver.addCssFile(strCSSPath1.replace("Simpel", "Leerbericht"), true);
        }
        Pipeline<?> pipeline = new CssResolverPipeline(cssResolver,
                new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));

        XMLWorker worker = new XMLWorker(pipeline, true);
        XMLParser p = new XMLParser(worker);
        XMLParser p2 = new XMLParser(worker);
        p.toString();
        //ByteArrayInputStream bis = new ByteArrayInputStream(strAusgabe.toString().getBytes());
        //ByteArrayInputStream cis = new ByteArrayInputStream(strCSSPath1.replace("Simple", "Hoch").toString().getBytes());
        //XMLWorkerHelper.getInstance().parseXHtml(writer, document, bis, cis);
        //p.selectState().selfClosing();

        p.parse(new StringReader(strAusgabe));

        document.close();
        writer.close();
        strBerichtname = strBerichtname.replaceAll(" ", "_");
        response.setContentType("application/pdf");
        response.setHeader("Content-Disposition", "filename=" + strBerichtname + ".pdf");
        response.setContentLength(baos.size());

        ServletOutputStream os = response.getOutputStream();
        baos.writeTo(os);
        os.flush();
        os.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    } catch (CssResolverException ex) {
        Logger.getLogger(PDFServlet.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:timeclock.reports.TableReport.java

/**
 * Creates the PDF with the employee list.
 *//*ww w .  ja  v a 2s . co m*/
public void createPdf() {
    // Step 1 - create the Document
    Document document = new Document(PageSize.A4, 36, 36, 54, 54);
    try {
        // Step 2 - create the PdfWriter and arguements
        // TODO: FILE_CHOOSER - Change how I get the file name and location, put dialog here
        // FileChooser fc = new FileChooser();
        // this.fileName = fc.showDialog("Employees");
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(this.fileName));
        HeaderFooter event = new HeaderFooter(this.title, MyFonts.font.get("title"));
        writer.setBoxSize("art", new Rectangle(36, 54, 559, 788));
        writer.setPageEvent(event);
        // Step 3 - Open the document
        document.open();
        // Step 4 - create and add content
        PdfPTable table = createTable(this.list);
        document.add(table);
        // Step 5 - close the document
        document.close(); // no need to close PDFwriter?
    } catch (DocumentException | FileNotFoundException e) {
        Debugger.log(e);
    }
}

From source file:valstreamtools.ValStrSplitPage.java

private void splitDocument(String[] args) throws IOException, DocumentException {
    /**/*from w ww  . ja v  a 2 s . c o m*/
     * int splitNo = 4; String inputFileName =
     * "C:\\tmp\\valuestream_export_input_2015-03-03-22-18-37.pdf"; String
     * outputFileName = "C:\\tmp\\valuestream_export_op_2015-03-03-22-18-37.pdf";*
     */
    int splitNo = Integer.parseInt(args[0]);
    String inputFileName = args[1];
    if (splitNo > 1) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
        String splitOutFileName = "/var/tmp/PDF_SPLIT_" + sdf.format(new Date()) + ".pdf";
        PdfReader reader = new PdfReader(inputFileName);
        Rectangle pagesize = reader.getPageSize(1);
        float pageHeight = pagesize.getHeight();
        float newpagewidth = (pagesize.getWidth() / splitNo);
        Rectangle newPapeSize = new Rectangle(0, 0, newpagewidth, pageHeight);
        Document document = new Document(newPapeSize);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(splitOutFileName));
        document.open();
        int pageNos = reader.getNumberOfPages();
        PdfContentByte content = writer.getDirectContent();
        for (int i = 1; i <= pageNos; i++) {
            PdfImportedPage page = writer.getImportedPage(reader, i);
            if (i > 1) {// In case of a new inpit page, need to create this.
                document.newPage();
            }
            for (int j = 0; j < splitNo; j++) {
                if (j == 0) {//This condition is used to skip the adding of new page.
                    content.addTemplate(page, 0, 0);
                } else {
                    document.newPage();
                    content.addTemplate(page, (-1 * j * newpagewidth), 0);
                }
            }
        }
        document.close();
        reader.close();
        createPageNo(splitOutFileName, args[2], pageHeight);
        File f = new File(splitOutFileName);
        if (f.exists()) {
            f.delete();
        }
    } else {
        PdfReader reader = new PdfReader(inputFileName);
        float pageHeight = reader.getPageSize(1).getHeight();
        reader.close();
        createPageNo(inputFileName, args[2], pageHeight);
    }
}

From source file:Ventas.GeneradorFormato.java

public static void main(String[] args) {
    try {/*from ww w  .j  av a2 s  .  c  om*/

        Document document = new Document(PageSize.LETTER, 50, 50, 85, 50);
        document.addAuthor("Ventas");
        document.addTitle("Ventas");

        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        writer.setInitialLeading(16);
        Rectangle rct = new Rectangle(80, 104, 500, 688);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

        document.open();
        //            Paragraph parrafo2 = new Paragraph("De aqui en ", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED));
        //            parrafo2.setAlignment(0);
        document.add(Chunk.NEWLINE);
        document.add(new Paragraph("Fecha:"));
        Paragraph id_Venta = new Paragraph("ID_Venta:");
        id_Venta.setAlignment(0);
        document.add(id_Venta);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        //            document.add(parrafo2);
        document.add(new Paragraph("Nombre del cliente:"));
        //            document.add(Chunk.NEWLINE);
        //            document.add(Chunk.NEWLINE);
        document.add(new Paragraph("Apellido Paterno:"));
        //            document.add(Chunk.NEWLINE);
        document.add(new Paragraph("Apellido Materno:"));
        document.add(new Paragraph("Domicilio:"));
        document.add(new Paragraph("Calle:"));
        document.add(new Paragraph("Numero:"));
        document.add(new Paragraph(""));

        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.close();
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
}

From source file:view.WorkspacePanel.java

License:Open Source License

private void btnApplySignatureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnApplySignatureActionPerformed
    if (tempCCAlias != null) {
        signatureSettings.setPageNumber(imagePanel.getPageNumber());
        signatureSettings.setCcAlias(tempCCAlias);
        signatureSettings.setReason(tfReason.getText());
        signatureSettings.setLocation(tfLocation.getText());
        if (jRadioButton1.isSelected()) {
            signatureSettings.setCertificationLevel(PdfSignatureAppearance.NOT_CERTIFIED);
        } else if (jRadioButton2.isSelected()) {
            signatureSettings.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);
        } else if (jRadioButton3.isSelected()) {
            signatureSettings.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_FORM_FILLING);
        } else if (jRadioButton4.isSelected()) {
            signatureSettings/*from   w  w  w  .j  ava  2 s  . c  o m*/
                    .setCertificationLevel(PdfSignatureAppearance.CERTIFIED_FORM_FILLING_AND_ANNOTATIONS);
        }
        signatureSettings.setOcspClient(true);
        if (cbTimestamp.isSelected()) {
            signatureSettings.setTimestamp(true);
            if (tfTimestamp.getText().isEmpty()) {
                JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.timestampEmpty"),
                        "", JOptionPane.ERROR_MESSAGE);
                return;
            } else {
                signatureSettings.setTimestampServer(tfTimestamp.getText());
            }
        } else {
            signatureSettings.setTimestamp(false);
            cbTimestamp.setSelected(false);
            tfTimestamp.setVisible(false);
        }
        signatureSettings.setVisibleSignature(cbVisibleSignature.isSelected());

        if (cbVisibleSignature.isSelected()) {
            Point p = tempSignature.getScaledPositionOnDocument();
            Dimension d = tempSignature.getScaledSizeOnDocument();
            float p1 = (float) p.getX();
            float p3 = (float) d.getWidth() + p1;
            float p2 = (float) ((document.getPageDimension(imagePanel.getPageNumber(), 0).getHeight())
                    - (p.getY() + d.getHeight()));
            float p4 = (float) d.getHeight() + p2;

            signatureSettings.setVisibleSignature(true);
            if (tempSignature.getImageLocation() != null) {
                signatureSettings.getAppearance().setImageLocation(tempSignature.getImageLocation());
            }
            Rectangle rect = new Rectangle(p1, p2, p3, p4);
            signatureSettings.setSignaturePositionOnDocument(rect);
            signatureSettings.setText(tfText.getText());
        } else {
            signatureSettings.setVisibleSignature(false);
        }
        if (mainWindow.getOpenedFiles().size() > 1) {
            Object[] options = { Bundle.getBundle().getString("menuItem.allDocuments"),
                    Bundle.getBundle().getString("menuItem.onlyThis"),
                    Bundle.getBundle().getString("btn.cancel") };
            int i = JOptionPane.showOptionDialog(null,
                    Bundle.getBundle().getString("msg.multipleDocumentsOpened"),
                    Bundle.getBundle().getString("msg.multipleDocumentsOpenedTitle"),
                    JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
            if (i == 0) {
                signBatch(signatureSettings);
            } else if (i == 1) {
                signDocument(document, true, true);
            }
        } else {
            signDocument(document, true, true);
        }
    } else {
        JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("noSmartcardFound"),
                WordUtils.capitalize(Bundle.getBundle().getString("error")), JOptionPane.ERROR_MESSAGE);
        changeCard(CardEnum.SIGN_PANEL, false);
    }
}