Example usage for com.itextpdf.text.pdf PdfWriter setBoxSize

List of usage examples for com.itextpdf.text.pdf PdfWriter setBoxSize

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfWriter setBoxSize.

Prototype

public void setBoxSize(final String boxName, final Rectangle size) 

Source Link

Document

Use this method to set the page box sizes.

Usage

From source file:Report.RelatorioProfessor.java

/**
 * Funo para gerar o stream do relatorio de orientaes por professor
 *
 * @param lOrientacao/*from  w w w.ja  v  a2 s  .c o m*/
 * @param dtinicial
 * @param dtfinal
 * @param coordenador
 * @param campus
 * @return ByteArrayOutputStream
 */
public ByteArrayOutputStream relatorioProfessorOrientacao(List<Professororientacao> lOrientacao, Date dtinicial,
        Date dtfinal, Professor coordenador, Campus campus) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    FacesContext faces = FacesContext.getCurrentInstance();
    //pega o contexto da aplicacao
    String realPath = faces.getExternalContext().getRealPath("/");

    try {
        BaseFont fHelvetica = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false);
        //----------------------------------------------------------------------
        //creation of the document with a certain size and certain margins
        //may want to use PageSize.LETTER instead
        Document document = new Document(PageSize.A4, 40, 40, 20, 50);
        document.addAuthor("SisGES"); // optional
        document.addSubject("Relatrio"); // opcional
        document.addKeywords("SisGES");
        document.addCreator("iText");
        //----------------------------------------------------------------------
        // creation of the different writers
        //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("web/resources/report/alunosMatriculados.pdf"));
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setBoxSize("header", new Rectangle(36, 54, 559, 788));
        //----------------------------------------------------------------------
        // ADICIONA HEADER E FOOTER
        //----------------------------------------------------------------------
        HeaderFooter headerFooter = new HeaderFooter();
        headerFooter.setY(760f);
        writer.setPageEvent(headerFooter);
        //----------------------------------------------------------------------
        //ABRE DOCUMENTO PARA ESCRITA
        //----------------------------------------------------------------------
        document.open();
        //----------------------------------------------------------------------
        //ADICIONAR LOGO NO DOCUMENTO
        //----------------------------------------------------------------------
        Image logoUfu = Image.getInstance(realPath + "/resources/images/logoUFUAta.png");
        logoUfu.scaleAbsolute(155, 39);//(largura,altura)
        logoUfu.isImgTemplate(); //add no template
        document.add(logoUfu);

        //----------------------------------------------------------------------
        //ADICIONAR CABEALHO
        //----------------------------------------------------------------------
        PdfContentByte univ = writer.getDirectContentUnder();
        univ.beginText();
        univ.setFontAndSize(fHelvetica, 10);
        univ.setTextMatrix(349, 816); // x e y
        univ.showText("UNIVERSIDADE FEDERAL DE UBERLNDIA");
        univ.setTextMatrix(405, 802); // x e y
        univ.showText("FACULDADE DE COMPUTAO");
        univ.setTextMatrix(403, 788); // x e y
        univ.showText("COORDENADORIA DE ESTGIO ");
        univ.endText();

        String info = "Campus Universitrio - " + campus.getNomecampus() + " - CEP " + campus.getCep() + " - "
                + campus.getCidade() + " - " + campus.getEstadosigla().toUpperCase();

        Chunk txtCampus = new Chunk(info);
        Paragraph paragraph0 = new Paragraph();
        paragraph0.setSpacingBefore(-10);
        paragraph0.setFont(new Font(fHelvetica, 7));
        paragraph0.add(txtCampus);
        paragraph0.setAlignment(Element.ALIGN_RIGHT);
        document.add(paragraph0);

        info = "Telefone: " + coordenador.getTelefone() + "   Email: " + coordenador.getEmail();
        Chunk txtCoordenador = new Chunk(info);
        Paragraph paragraph1 = new Paragraph();
        paragraph1.setSpacingBefore(-5);
        paragraph1.setSpacingAfter(10);
        paragraph1.setFont(new Font(fHelvetica, 7));
        paragraph1.add(txtCoordenador);
        paragraph1.setAlignment(Element.ALIGN_RIGHT);
        document.add(paragraph1);

        //            PdfContentByte univ = writer.getDirectContentUnder();
        //            univ.beginText();
        //            univ.setFontAndSize(fHelvetica, 12);
        //            univ.setTextMatrix(200, 815); // x e y
        //            univ.showText("UNIVERSIDADE FEDERAL DE UBERLNDIA");
        //            univ.setTextMatrix(235, 800); // x e y
        //            univ.showText("FACULDADE DE COMPUTAO");
        //            univ.endText();
        //
        //            PdfContentByte univEnd = writer.getDirectContentUnder();
        //            univEnd.beginText();
        //            univEnd.setFontAndSize(fHelvetica, 7);
        //            univEnd.setTextMatrix(210, 785); // x e y
        //            univEnd.showText("Campus Universitrio - Santa Mnica - CEP 38408-100 - Uberlndia - MG");
        //            univEnd.setTextMatrix(260, 775); // x e y
        //            univEnd.showText("Telefone: (34)3239-4144 ou 3239-4393");
        //            univEnd.endText();
        //----------------------------------------------------------------------
        //ADICIONAR TITULO
        //----------------------------------------------------------------------
        PdfContentByte t1 = writer.getDirectContentUnder();
        t1.beginText();
        t1.setFontAndSize(fHelvetica, 14);
        t1.setTextMatrix(180, 730); // x e y
        t1.showText("Participao dos professores FACOM");
        t1.endText();

        PdfContentByte t2 = writer.getDirectContentUnder();
        t2.beginText();
        t2.setFontAndSize(fHelvetica, 12);
        t2.setTextMatrix(195, 705); // x e y
        String periodo = CalendarFormat.getDataBRtoDate(dtinicial) + " at "
                + CalendarFormat.getDataBRtoDate(dtfinal);
        t2.showText("Perodo: " + periodo);
        t2.endText();

        //----------------------------------------------------------------------
        //TABELA
        PdfPTable table = new PdfPTable(4);
        //espao do inicio da pagina
        table.setSpacingBefore(100f);
        table.setTotalWidth(100f);
        table.setWidthPercentage(100);
        float[] widths = { 20, 30, 35, 15 };//largura das colunas
        table.setWidths(widths);
        table.setHeaderRows(1);

        //CABEALHO DA TABELA
        Paragraph cabecalho = new Paragraph("Siape");
        PdfPCell cell1 = new PdfPCell(cabecalho); // celula
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setBorderColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell1);

        cabecalho = new Paragraph("Professor");
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        PdfPCell cell2 = new PdfPCell(cabecalho); // celula
        cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell2.setBorderColor(BaseColor.LIGHT_GRAY);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell2);

        cabecalho = new Paragraph("Email do Professor");
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        PdfPCell cell4 = new PdfPCell(cabecalho); // celula
        cell4.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell4.setBorderColor(BaseColor.LIGHT_GRAY);
        cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell4);

        cabecalho = new Paragraph("Orientaes");
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        PdfPCell cell3 = new PdfPCell(cabecalho); // celula
        cell3.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell3.setBorderColor(BaseColor.LIGHT_GRAY);
        cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell3);

        for (int i = 0; i < lOrientacao.size(); i++) {
            Professororientacao po = lOrientacao.get(i);

            Paragraph texto = new Paragraph(String.valueOf(po.getSiape()));
            texto.getFont().setSize(8);
            cell1 = new PdfPCell(texto); // celula
            cell1.setBorderColor(BaseColor.LIGHT_GRAY);
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell1);

            texto = new Paragraph(po.getNome());
            texto.getFont().setSize(8);
            cell2 = new PdfPCell(texto); // celula
            cell2.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell2);

            texto = new Paragraph(po.getEmail());
            texto.getFont().setSize(8);
            cell4 = new PdfPCell(texto); // celula
            cell4.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell4);

            texto = new Paragraph(String.valueOf(po.getOrientacoes()));
            texto.getFont().setSize(8);
            cell3 = new PdfPCell(texto); // celula
            cell3.setBorderColor(BaseColor.LIGHT_GRAY);
            cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell3);

            switch (i % 2) {
            case 0:
                cell1.setBorderColor(BaseColor.LIGHT_GRAY);
                cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
                break;
            case 1:

                break;
            }
        }

        //add a tabela
        document.add(table);
        //-----------------------------------------------------
        // distancia do fim da pagina
        float y = 70f;
        float x = 160f;
        //-----------------------------------------------------
        //linha
        PdfContentByte linha = writer.getDirectContentUnder();
        linha.setLineWidth(1f); // mostrar linha
        linha.setGrayStroke(0.5f); // 0 = preto, 1 = branco
        linha.moveTo(x, y);
        linha.lineTo(450f, y); // ate onde a linha vai
        linha.stroke();
        //------------------------------------------------------
        //assinatura
        PdfContentByte a1 = writer.getDirectContentUnder();
        a1.beginText();
        a1.setFontAndSize(fHelvetica, 10);
        a1.setTextMatrix(x + 50, y - 15); // x e y
        a1.showText("Coordenao de Estgio Supervisionado");
        a1.endText();
        //------------------------------------------------------
        //assinatura
        PdfContentByte a2 = writer.getDirectContentUnder();
        a2.beginText();
        a2.setFontAndSize(fHelvetica, 10);
        a2.setTextMatrix(x + 50, y - 27); // x e y
        a2.showText("FACOM/UFU");
        a2.endText();
        //------------------------------------------------------

        //add nova pagina
        document.newPage();
        //close document
        document.close();
    } catch (DocumentException | IOException ex) {
        Logger.getLogger(RelatorioProfessor.class.getName()).log(Level.SEVERE, null, ex);
    }
    //return stream com dados
    return baos;
}

From source file:ro.ldir.chartpackage.GarbagePackageBuilder.java

License:Open Source License

public void writePDF(OutputStream out)
        throws DocumentException, MalformedURLException, XPathExpressionException, IOException {
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, "Cp1250", BaseFont.NOT_EMBEDDED);
    final Font hfFont = new Font(bf, 8, Font.NORMAL, BaseColor.GRAY);

    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    PdfWriter writer = PdfWriter.getInstance(document, out);
    writer.setBoxSize("art", new Rectangle(36, 54, 559, 788));

    writer.setPageEvent(new PdfPageEventHelper() {
        private int page = 0;

        @Override//from   w  w  w  . j a  va2 s  .com
        public void onEndPage(PdfWriter writer, Document arg1) {
            page++;
            Rectangle rect = writer.getBoxSize("art");
            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
                    new Phrase("Pachet mormane - \u00a9 Let's Do It, Romania!", hfFont),
                    (rect.getLeft() + rect.getRight()) / 2, rect.getTop() + 18, 0);
            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
                    new Phrase("- " + page + " -", hfFont), (rect.getLeft() + rect.getRight()) / 2,
                    rect.getBottom() - 18, 0);
        }
    });

    document.open();
    document.addAuthor("Let's Do It, Romania!");
    document.addTitle("Pachet mormane");
    document.addCreationDate();

    Font titleFont = new Font(bf, 24, Font.BOLD);
    Font noteFont = new Font(bf, 12, Font.NORMAL, BaseColor.RED);
    Font headerFont = new Font(bf, 12, Font.BOLD);
    Font normalFont = new Font(bf, 11);
    Font defFont = new Font(bf, 11, Font.BOLD);
    Paragraph par;
    int page = 0;

    for (Garbage garbage : garbages) {
        par = new Paragraph();
        par.setAlignment(Element.ALIGN_CENTER);
        par.add(new Chunk("Morman " + garbage.getGarbageId() + "\n", titleFont));
        par.add(new Chunk("Citi\u0163i cu aten\u0163ie!", noteFont));
        document.add(par);

        par = new Paragraph();
        par.setSpacingBefore(20);
        par.add(new Chunk("1. Date generale\n", headerFont));
        par.add(new Chunk("Jude\u0163ul: ", defFont));
        par.add(new Chunk(garbage.getCounty().getName() + "\n", normalFont));
        par.add(new Chunk("Comuna: ", defFont));
        par.add(new Chunk(garbage.getTown().getName() + "\n", normalFont));
        if (garbage.getChartedArea() != null) {
            par.add(new Chunk("Zona cartare: ", defFont));
            par.add(new Chunk(garbage.getChartedArea().getName() + "\n", normalFont));
        }
        par.add(new Chunk("Pozi\u0163ie: ", defFont));
        par.add(new Chunk(garbage.getY() + ", " + garbage.getX() + "\n", normalFont));
        par.add(new Chunk("Descriere:\n", defFont));
        par.add(new Phrase(garbage.getDescription() + "\n", normalFont));
        par.add(new Chunk("Componen\u0163\u0103 gunoi:\n", defFont));
        List list = new List();
        list.add(new ListItem(
                new Chunk("Procent plastic: " + garbage.getPercentagePlastic() + "%", normalFont)));
        list.add(new ListItem(
                new Chunk("Procent sticl\u0103: " + garbage.getPercentageGlass() + "%", normalFont)));
        list.add(new ListItem(new Chunk("Procent metale: " + garbage.getPercentageMetal() + "%", normalFont)));
        list.add(new ListItem(
                new Chunk("Procent nereciclabile: " + garbage.getPercentageWaste() + "%", normalFont)));
        par.add(list);
        document.add(par);

        par = new Paragraph();
        par.setSpacingBefore(20);
        par.add(new Chunk("2. Indica\u0163ii rutiere\n", headerFont));
        Image img = Image.getInstance(getImage(garbage));
        img.scaleToFit((float) (PageSize.A4.getWidth() * .75), (float) (PageSize.A4.getHeight() * .75));
        img.setAlignment(Element.ALIGN_CENTER);
        par.add(img);
        document.add(par);

        if (page < garbages.size() - 1)
            document.newPage();
        page++;
    }

    document.close();
}

From source file:se.billes.pdf.renderer.process.Renderer.java

License:Open Source License

public void onRender() throws PdfRenderException {

    long startTime = new Date().getTime();
    System.err.println(startTime + ": Renderer called");
    PdfDocument pdfDocument = pdfRequest.getDocument();
    File destinationPdf = new File(pdfRequest.getPath(), pdfDocument.getName());
    Document document = new Document();
    boolean finishedRender = false;
    PdfWriter writer = null;
    try {//from   w w w .j a v a 2 s  .  c  o m
        writer = PdfWriter.getInstance(document, new FileOutputStream(destinationPdf));
        document.addAuthor("iText");
        writer.setBoxSize("trim", new SizeFactory().getTrimBoxAsRectangle(pdfDocument));
        document.setPageSize(new SizeFactory().getSizeAsRectangle(pdfDocument));

        document.open();
        for (Page page : pdfDocument.getPages()) {
            page.onNewPage(writer, document);
        }
        System.err.println(new Date().getTime() + ": Renderer finished");
        finishedRender = true;

    } catch (FileNotFoundException e) {
        generatePdfRenderException(e);
    } catch (DocumentException e) {
        generatePdfRenderException(e);
    } catch (Exception e) {
        generatePdfRenderException(e);
    } finally {
        try {
            writer.close();
        } catch (Exception e) {
        }
        try {
            document.close();
        } catch (Exception e) {
        }

        ImageFactory.clear();

        if (finishedRender) {
            System.err.println(new Date().getTime() + ": document closed");
            long endTime = new Date().getTime();
            PdfAction action = new PdfAction();
            action.setFile(destinationPdf.getAbsolutePath());
            action.setExecutionOfPdfRendering(endTime - startTime);
            action.setTotalTimeOfExecution(endTime - pdfRequest.getStartExecutionTime());
            action.setSuccess(true);
            action.setParams(pdfRequest.getParams());
            PdfResponse response = new PdfResponse();
            response.setAction(action);
            onRendered(response);
        }
    }

}

From source file:Servlet.PDFServlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*from  ww w. j a v a  2  s  . c  o  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.
 *//*from   w w w .  j a  v  a  2 s . 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:Ventas.GeneradorFormato.java

public static void main(String[] args) {
    try {/*  w w w .  j  ava2 s.com*/

        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());
    }
}