Example usage for com.itextpdf.text Document addCreator

List of usage examples for com.itextpdf.text Document addCreator

Introduction

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

Prototype


public boolean addCreator(String creator) 

Source Link

Document

Adds the creator to a Document.

Usage

From source file:Servlets.ReportsServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//w w  w . j  a  va 2  s .c om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {

        Paragraph pp;
        Paragraph palaglapgh, signParagraph, dateParagrapgh;
        Chunk chk;
        Paragraph underText;
        Chunk chuk1;
        Chunk chuk2;
        Paragraph regionText;
        String x;
        ResultSet dir;
        Paragraph regionTexts;
        String repLot;
        repLot = request.getParameter("report");

        String repNum = request.getParameter("ITLot");
        Paragraph newDate;
        response.setContentType("application/pdf");
        OutputStream out = response.getOutputStream();

        //Create document for pdf
        Document doc = new Document();

        //PDF writer to write into document
        PdfWriter docwriter = null;

        DecimalFormat df = new DecimalFormat("0.00");

        switch (repLot) {
        default:

            break;
        case "IT Report":

            //Copied code start from here
            try {
                // //file path
                //String path = "docs/" + "Name";
                docwriter = PdfWriter.getInstance(doc, out);
            } catch (DocumentException ex) {
                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
            }

            //document header attributes
            doc.addAuthor("CHED CU");
            doc.addCreationDate();
            doc.addProducer();
            doc.addCreator("Grant Monitor");
            doc.addTitle(repLot);
            doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape
            //doc.setPageSize(PageSize.A4);
            doc.setMargins(20f, 20f, 10f, 10f);

            //open document
            doc.open();

            //Creating a paragraphs and chunks
            pp = new Paragraph("Cocoa Health And Extension Division", forTitle);
            pp.setAlignment(Element.ALIGN_CENTER);

            palaglapgh = new Paragraph("(Cocobod)", bfBold12);
            palaglapgh.setAlignment(Element.ALIGN_CENTER);

            signParagraph = new Paragraph("Sign: ..............", bfBold12);
            signParagraph.setAlignment(Element.ALIGN_LEFT);

            dateParagrapgh = new Paragraph("Date: ...........", bfBold12);

            chk = new Chunk("From GIS Office, Accra", bfBold12);
            chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position
            underText = new Paragraph(chk);
            underText.setAlignment(Element.ALIGN_CENTER);

            chuk1 = new Chunk("Lot No:", forTitle2);
            chuk1.setUnderline(.1f, -2f);
            chuk2 = new Chunk(repNum.toUpperCase(), forTitle2);

            regionText = new Paragraph(repLot, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            x = "";
            dir = manager.PDFdemos(repNum);
            try {
                if (dir.next()) {
                    x = dir.getString(12);

                }
            } catch (SQLException ex) {
                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
            }

            regionTexts = new Paragraph(x, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            //add the PDF table to the paragraph
            //palaglapgh.add(table);
            //Table Generation block
            regionText.add(reports(repNum, repLot, .25f));

            //SECTION TO ADD ELEMENTS TO PDF
            // add the paragraph to the document
            doc.add(pp);
            //doc.add(Chunk.NEWLINE);       //Adds a new blank line
            doc.add(palaglapgh);
            doc.add(underText);

            doc.add(chuk1);
            doc.add(chuk2);

            //Current Date and time insertion
            newDate = new Paragraph(date, bf12);
            newDate.setAlignment(Element.ALIGN_RIGHT);
            doc.add(newDate);
            doc.add(regionTexts);
            doc.add(regionText);

            doc.add(Chunk.NEWLINE); //Adds a new blank line
            doc.add(Chunk.NEWLINE);

            doc.add(signParagraph);
            doc.add(dateParagrapgh);

            //close the document
            doc.close();

            //close the writer
            docwriter.close();

            out.close();

            break;

        case "TR Report":

            //Copied code start from here
            try {
                // //file path
                //String path = "docs/" + "Name";
                docwriter = PdfWriter.getInstance(doc, out);
            } catch (DocumentException ex) {
                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
            }

            //document header attributes
            doc.addAuthor("CHED CU");
            doc.addCreationDate();
            doc.addProducer();
            doc.addCreator("Grant Monitor");
            doc.addTitle(repLot);
            //doc.setPageSize(PageSize.A4.rotate());      //This sets page size to A4 and orientation to Landscape
            doc.setPageSize(PageSize.A4);
            doc.setMargins(30f, 30f, 20f, 20f);

            //open document
            doc.open();

            //Creating a paragraphs and chunks
            pp = new Paragraph("Cocoa Health And Extension Division", forTitle);
            pp.setAlignment(Element.ALIGN_CENTER);

            palaglapgh = new Paragraph("(Cocobod)", bfBold12);
            palaglapgh.setAlignment(Element.ALIGN_CENTER);

            signParagraph = new Paragraph("Sign: ..............", bfBold12);
            signParagraph.setAlignment(Element.ALIGN_LEFT);

            dateParagrapgh = new Paragraph("Date: ...........", bfBold12);

            chk = new Chunk("From GIS Office, Accra", bfBold12);
            chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position
            underText = new Paragraph(chk);
            underText.setAlignment(Element.ALIGN_CENTER);

            chuk1 = new Chunk("Lot No:", forTitle2);
            chuk1.setUnderline(.1f, -2f); // 0.1 thickness and -2 position
            chuk2 = new Chunk(repNum.toUpperCase(), forTitle2);

            regionText = new Paragraph(repLot, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);

            x = "";
            dir = manager.PDFdemos(repNum);
            try {
                if (dir.next()) {
                    x = dir.getString(12);

                }
            } catch (SQLException ex) {
                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
            }

            regionTexts = new Paragraph(x, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            //add the PDF table to the paragraph
            //palaglapgh.add(table);
            //Table Generation block
            regionText.add(reports(repNum, repLot, .1f));

            //SECTION TO ADD ELEMENTS TO PDF
            // add the paragraph to the document
            doc.add(pp);
            //doc.add(Chunk.NEWLINE);       //Adds a new blank line
            doc.add(palaglapgh);
            doc.add(underText);

            doc.add(chuk1);
            doc.add(chuk2);

            //Current Date and time insertion
            newDate = new Paragraph(date, bf12);
            newDate.setAlignment(Element.ALIGN_RIGHT);
            doc.add(newDate);
            doc.add(regionTexts);
            doc.add(regionText);

            doc.add(Chunk.NEWLINE); //Adds a new blank line
            doc.add(Chunk.NEWLINE);

            doc.add(signParagraph);
            doc.add(dateParagrapgh);

            //close the document
            doc.close();

            //close the writer
            docwriter.close();

            out.close();

            break;

        case "RP Report":

            //Copied code start from here
            try {
                // //file path
                //String path = "docs/" + "Name";
                docwriter = PdfWriter.getInstance(doc, out);
            } catch (DocumentException ex) {
                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
            }

            //document header attributes
            doc.addAuthor("CHED CU");
            doc.addCreationDate();
            doc.addProducer();
            doc.addCreator("Grant Monitor");
            doc.addTitle(repLot);
            doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape
            //doc.setPageSize(PageSize.A4);
            doc.setMargins(30f, 30f, 20f, 20f);

            //open document
            doc.open();

            //Creating a paragraphs and chunks
            pp = new Paragraph("Cocoa Health And Extension Division", forTitle);
            pp.setAlignment(Element.ALIGN_CENTER);

            palaglapgh = new Paragraph("(Cocobod)", bfBold12);
            palaglapgh.setAlignment(Element.ALIGN_CENTER);

            signParagraph = new Paragraph("Sign: ..............", bfBold12);
            signParagraph.setAlignment(Element.ALIGN_LEFT);

            dateParagrapgh = new Paragraph("Date: ...........", bfBold12);

            chk = new Chunk("From GIS Office, Accra", bfBold12);
            chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position
            underText = new Paragraph(chk);
            underText.setAlignment(Element.ALIGN_CENTER);

            chuk1 = new Chunk("RP Lot No:", forTitle2);
            chuk1.setUnderline(.1f, -2f);
            chuk2 = new Chunk(repNum.toUpperCase(), forTitle2);

            regionText = new Paragraph(repLot, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            x = "";
            dir = manager.PDFreplants(repNum);
            try {
                if (dir.next()) {
                    x = dir.getString(22);

                }
            } catch (SQLException ex) {
                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
            }

            regionTexts = new Paragraph(x, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            //add the PDF table to the paragraph
            //palaglapgh.add(table);
            //Table Generation block
            regionText.add(RPreport(repNum));

            //SECTION TO ADD ELEMENTS TO PDF
            // add the paragraph to the document
            doc.add(pp);
            //doc.add(Chunk.NEWLINE);       //Adds a new blank line
            doc.add(palaglapgh);
            doc.add(underText);

            doc.add(chuk1);
            doc.add(chuk2);

            //Current Date and time insertion
            newDate = new Paragraph(date, bf12);
            newDate.setAlignment(Element.ALIGN_RIGHT);
            doc.add(newDate);
            doc.add(regionTexts);
            doc.add(regionText);

            doc.add(Chunk.NEWLINE); //Adds a new blank line
            doc.add(Chunk.NEWLINE);

            doc.add(signParagraph);
            doc.add(dateParagrapgh);

            //close the document
            doc.close();

            //close the writer
            docwriter.close();

            out.close();

            break;

        case "Rehab Report":

            //Copied code start from here
            try {
                // //file path
                //String path = "docs/" + "Name";
                docwriter = PdfWriter.getInstance(doc, out);
            } catch (DocumentException ex) {
                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
            }

            //document header attributes
            doc.addAuthor("CHED CU");
            doc.addCreationDate();
            doc.addProducer();
            doc.addCreator("Grant Monitor");
            doc.addTitle(repLot);
            doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape
            //doc.setPageSize(PageSize.A4);
            doc.setMargins(5f, 5f, 3f, 3f);

            //open document
            doc.open();

            //Creating a paragraphs and chunks
            pp = new Paragraph("Cocoa Health And Extension Division", forTitle);
            pp.setAlignment(Element.ALIGN_CENTER);

            palaglapgh = new Paragraph("(Cocobod)", bfBold12);
            palaglapgh.setAlignment(Element.ALIGN_CENTER);

            signParagraph = new Paragraph("Sign: ..............", bfBold12);
            signParagraph.setAlignment(Element.ALIGN_LEFT);

            dateParagrapgh = new Paragraph("Date: ...........", bfBold12);

            chk = new Chunk("Component 1 Rehabilitation Tree Removal Cost From GIS Office, Accra", bfBold12);
            chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position
            underText = new Paragraph(chk);
            underText.setAlignment(Element.ALIGN_CENTER);

            chuk1 = new Chunk("RP Lot No:", bfBold12);
            chuk1.setUnderline(.1f, -2f);
            chuk2 = new Chunk(repNum, bfBold12);

            regionText = new Paragraph(repLot, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            x = "";
            dir = manager.PDFRehab(repNum);//SHOULD BE CHANGED!!!!
            try {
                if (dir.next()) {
                    x = dir.getString(21);

                }
            } catch (SQLException ex) {
                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
            }

            regionTexts = new Paragraph(x, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            //add the PDF table to the paragraph
            //palaglapgh.add(table);
            //Table Generation block
            regionText.add(reports(repNum));

            //SECTION TO ADD ELEMENTS TO PDF
            // add the paragraph to the document
            doc.add(pp);
            //doc.add(Chunk.NEWLINE);       //Adds a new blank line
            doc.add(palaglapgh);
            doc.add(underText);

            doc.add(chuk1);
            doc.add(chuk2);

            //Current Date and time insertion
            newDate = new Paragraph(date, bf12);
            newDate.setAlignment(Element.ALIGN_RIGHT);
            doc.add(newDate);
            doc.add(regionTexts);
            doc.add(regionText);

            doc.add(Chunk.NEWLINE); //Adds a new blank line
            doc.add(Chunk.NEWLINE);

            doc.add(signParagraph);
            doc.add(dateParagrapgh);

            //close the document
            doc.close();

            //close the writer
            docwriter.close();

            out.close();

            //Copied CODES
            break;

        }

    } catch (DocumentException ex) {
        Logger.getLogger(ReportsServlet.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:sipl.recursos.GenerarPDFGrafica.java

private void addMetaData(Document document) {
    document.addTitle(Titulo);/* w ww  .j  a va 2  s .com*/
    document.addSubject("Grfica");
    document.addKeywords("Java, Grfica, PDF, iText");
    document.addAuthor("Wilmar Gonzlez - Sandra Vera");
    document.addCreator("SIPL");
}

From source file:sipl.recursos.GenerarPDFListar.java

private void addMetaData(Document document) {
    document.addTitle(Titulo);/*from  w  ww .  ja  v  a2  s  .  c o  m*/
    document.addSubject("Lista especfica");
    document.addKeywords("Java, PDF, iText");
    document.addAuthor("Wilmar Gonzlez - Sandra Vera");
    document.addCreator("SIPL");
}

From source file:sipl.recursos.GenerarPDFtipomaterial.java

private static void addMetaData(Document document) {
    document.addTitle(Titulo);//from   w w w.  jav  a  2 s . c om
    document.addSubject("Grfica");
    document.addKeywords("Java, Grfica, PDF, iText");
    document.addAuthor("Wilmar Gonzlez - Sandra Vera");
    document.addCreator("SIPL");
}

From source file:sistemafacturacionlibros.PDFCreator.java

public void addMetaData(Document document) {
    document.addTitle("PDF Report");
    document.addSubject("Using iText");
    document.addKeywords("Java, PDF, iText");
    document.addAuthor(System.getProperty("user.name"));
    document.addCreator(System.getProperty("user.name"));
}

From source file:sqlsentinel.report.PDFGenerator.java

License:Open Source License

private static void addMetaData(Document document) {
    document.addTitle("SQLSentinel Report");
    document.addSubject("site: " + url);
    document.addKeywords("");
    document.addAuthor("SQLSentinel");
    document.addCreator("SQLSentinel");
}

From source file:SystemOperations.PdfGen.java

private static void addMetaData(Document document, String title) {
    document.addTitle("My first PDF");
    document.addAuthor("Super Rent");
    document.addCreator("Super Rent");
}

From source file:tn.com.hitechart.eds.Util.pdfRpport.FirstPdf.java

private void addMetaData(Document document) {

    document.addTitle("My first PDF");
    document.addSubject("Using iText");
    document.addKeywords("Java, PDF, iText");
    document.addAuthor("AHMED BEJ");
    document.addCreator("AHMED BEJ");
}

From source file:tn.esprit.twin1.brogrammers.eventify.Eventify.util.TicketGenerator.java

public static void GenerateTicket(Ticket ticket) {
    Document document = new Document();
    try {// w  w w. j av a  2  s . c  o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FILE));
        Rectangle pagesize = new Rectangle(700, 300);
        document.open();
        Paragraph emptyline = new Paragraph();
        emptyline.add(new Paragraph(" "));
        document.setPageSize(pagesize);
        document.newPage();
        //PIC
        PdfContentByte canvas = writer.getDirectContentUnder();
        Image image = Image.getInstance(IMAGE);
        //image.scaleAbsolute(pagesize.rotate());
        image.setAbsolutePosition(0, 0);
        canvas.addImage(image);
        //PIC
        document.addTitle("Your Access To" + ticket.getEvent().getTitle());
        document.addSubject(ticket.getEvent().getTheme());
        document.addKeywords(ticket.getEvent().getTitle() + "Ticket");
        document.addAuthor("Mohamed Firas Ouertani");
        document.addCreator("Mohamed Firas Ouertani");
        Paragraph prefacetitle = new Paragraph();
        prefacetitle.add(new Paragraph("Your Ticket For " + ticket.getEvent().getTitle(), bigFont));
        document.add(prefacetitle);
        document.add(emptyline);

        Paragraph prefacetime = new Paragraph();
        prefacetime.add(new Paragraph(ticket.getEvent().getStartTime().toString(), greyFont));
        document.add(prefacetime);
        document.add(emptyline);
        document.add(emptyline);
        Paragraph prefacetype = new Paragraph();
        prefacetype.add(new Paragraph("You Reserved For: " + ticket.getTypeTicket(), catFont));
        document.add(prefacetype);
        //QR
        BarcodeQRCode qrcode = new BarcodeQRCode(
                "REF:#" + ticket.getEvent().getId() + "" + ticket.getEvent().getTitle().trim(), 1, 1, null);
        Image qrcodeImage = qrcode.getImage();
        qrcodeImage.setAbsolutePosition(520, 70);
        qrcodeImage.scalePercent(400);
        document.add(qrcodeImage);
        //QR

        //Bar
        PdfContentByte cb = writer.getDirectContent();
        Barcode128 code128 = new Barcode128();

        BarcodeEAN codeEAN = new BarcodeEAN();
        codeEAN.setCode("REF:#" + ticket.getEvent().getId() + "" + ticket.getEvent().getTitle().trim());
        codeEAN.setCodeType(BarcodeEAN.EAN13);
        Image codeEANImage = code128.createImageWithBarcode(cb, null, null);
        codeEANImage.setAbsolutePosition(10, 10);
        codeEANImage.scalePercent(125);
        document.add(codeEANImage);
        //Bar

        document.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:tourma.views.report.HTMLtoPDF.java

public static void exportToPDF(FileOutputStream output, String source, String title, Rectangle size,
        boolean excludeCutTable) {
    try {//from  w ww  .j a  va2  s  .  c  o  m
        Document document = new Document(size);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, output);
        document.open();
        document.addAuthor(Tournament.getTournament().getParams().getTournamentOrga());
        document.addCreator("TourMa");
        document.addSubject(Tournament.getTournament().getParams().getTournamentName());
        document.addCreationDate();
        document.addTitle(title);
        XMLWorkerHelper worker = XMLWorkerHelper.getInstance();

        worker.parseXHtml(pdfWriter, document, new StringReader(source));

        document.close();
    } catch (DocumentException | IOException e) {
        e.printStackTrace();
    }
}