Example usage for com.lowagie.text PageSize A4

List of usage examples for com.lowagie.text PageSize A4

Introduction

In this page you can find the example usage for com.lowagie.text PageSize A4.

Prototype

Rectangle A4

To view the source code for com.lowagie.text PageSize A4.

Click Source Link

Document

This is the a4 format

Usage

From source file:com.neu.cloud.Controller.FifthUseCaseController.java

public void generateReports(List<ArrayList<User>> user1ReportList)
        throws DocumentException, FileNotFoundException {
    Date date;//from w ww  . j  av a  2 s .  co m
    String dateForFolder = String.valueOf(new Date());
    for (ArrayList<User> users : user1ReportList) {
        date = new Date();
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        //            String path = System.getProperty("user.dir") + "\\reports\\";
        String path = System.getProperty("user.dir") + "//";
        String fileName = "ITextTest" + date.getTime() + ".pdf";
        //            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path + "ITextTest" + date.getTime() + ".pdf"));
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path + fileName));
        document.open();
        Table table = new Table(4);
        table.addCell("userID");
        table.addCell("username");
        table.addCell("password");
        table.addCell("productName");
        boolean flag = false;
        for (User u : users) {
            System.out.print("1");
            System.out.print("1");
            System.out.print("1");
            System.out.print("1");
            if (flag)
                continue;
            flag = true;
            table.addCell(String.valueOf(u.getUserID()));
            table.addCell(u.getUsername());
            table.addCell(u.getPassword());
            table.addCell(u.getProductName());
        }
        document.add(table);
        document.close();

        uploadInS3(path, fileName, dateForFolder);

        File file = new File(path + fileName);
        if (file.delete()) {
            System.out.println(file.getName() + " is deleted!");
        } else {
            System.out.println("Delete operation is failed.");
        }
    }
}

From source file:com.neu.cloud.Controller.FirstUseCaseController.java

public void generateReports(List<ArrayList<User>> user1ReportList)
        throws DocumentException, FileNotFoundException {
    Date date;/*from w  w w  .j  a v  a 2s  .  c o m*/
    String dateForFolder = String.valueOf(new Date());
    for (ArrayList<User> users : user1ReportList) {
        date = new Date();
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        //            String path = System.getProperty("user.dir") + "\\reports\\";
        String path = System.getProperty("user.dir") + "//";
        String fileName = "ITextTest" + date.getTime() + ".pdf";
        //            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path + "ITextTest" + date.getTime() + ".pdf"));
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path + fileName));
        document.open();
        Table table = new Table(4);
        table.addCell("userID");
        table.addCell("username");
        table.addCell("password");
        table.addCell("productName");
        for (User u : users) {
            table.addCell(String.valueOf(u.getUserID()));
            table.addCell(u.getUsername());
            table.addCell(u.getPassword());
            table.addCell(u.getProductName());
        }
        document.add(table);
        document.close();

        uploadInS3(path, fileName, dateForFolder);

        File file = new File(path + fileName);
        if (file.delete()) {
            System.out.println(file.getName() + " is deleted!");
        } else {
            System.out.println("Delete operation is failed.");
        }
    }
}

From source file:com.nokia.s60tools.swmtanalyser.wizards.ReportCreationJob.java

License:Open Source License

protected IStatus run(IProgressMonitor monitor) {

    monitor.beginTask("Creating report...", 10);

    try {/*from ww w .  ja  v  a  2  s .  c o m*/
        //Instantiation of document object
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(this.fileName));
        document.open();

        addGeneralDetails(document);

        if (!this.isOverviewReport) //If the report type is 1. i.e., report for selected issues only.
        {
            addSelectedIssuesReport(document);
        } else // If the report type is 2. i.e., Overview report
        {
            addOverviewReport(document);
        }

        addComments(document);

        //Close document
        document.close();
        //Close the writer
        writer.close();

    } catch (DocumentException e) {
        e.printStackTrace();
        SwmtAnalyserPlugin.getConsole().println("Unable to write document, error was: '" + e + "'",
                IConsolePrintUtility.MSG_ERROR);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        SwmtAnalyserPlugin.getConsole().println("Unable to write document, error was: '" + e + "'",
                IConsolePrintUtility.MSG_ERROR);
    } catch (Exception e) {
        e.printStackTrace();
        AbstractProductSpecificConsole absConsole = (AbstractProductSpecificConsole) SwmtAnalyserPlugin
                .getConsole();
        absConsole.printStackTrace(e);
        SwmtAnalyserPlugin.getConsole().println("Unable to write document, error was: '" + e + "'",
                IConsolePrintUtility.MSG_ERROR);
    }
    return Status.OK_STATUS;
}

From source file:com.openkm.util.DocConverter.java

License:Open Source License

/**
 * Convert SRC to PDF//w  w w .  ja  v a  2  s .  com
 */
public void src2pdf(File input, File output, String lang)
        throws ConversionException, DatabaseException, IOException {
    log.debug("** Convert from SRC to PDF **");
    FileOutputStream fos = null;
    FileInputStream fis = null;

    try {
        fos = new FileOutputStream(output);
        fis = new FileInputStream(input);

        // Make syntax highlight
        String source = IOUtils.toString(fis);
        JaSHi jashi = new JaSHi(source, lang);
        // jashi.EnableLineNumbers(1);
        String parsed = jashi.ParseCode();

        // Make conversion to PDF
        Document doc = new Document(PageSize.A4.rotate());
        PdfWriter.getInstance(doc, fos);
        doc.open();
        HTMLWorker html = new HTMLWorker(doc);
        html.parse(new StringReader(parsed));
        doc.close();
    } catch (DocumentException e) {
        throw new ConversionException("Exception in conversion: " + e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:com.openkm.util.PDFUtils.java

License:Open Source License

/**
 * Generate sample PDF/*w w  w .  j  av  a  2s  .  co m*/
 */
public static void generateSample(int paragraphs, OutputStream os) throws DocumentException {
    LoremIpsum li = new LoremIpsum();
    Document doc = new Document(PageSize.A4, 25, 25, 25, 25);
    PdfWriter.getInstance(doc, os);
    doc.open();

    for (int i = 0; i < paragraphs; i++) {
        doc.add(new Paragraph(li.getParagraphs()));
    }

    doc.close();
}

From source file:com.opst.adminBean.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();/* ww w . jav a 2  s  .  c  om*/
    pdf.setPageSize(PageSize.A4);
    String string = "CTP Leaderboard - " + adminBean.firstandlast + " Week: " + adminBean.week;
    Chunk ch = new Chunk();
    pdf.add(new Chunk(string));
    pdf.add(Chunk.NEWLINE);
    pdf.add(Chunk.NEWLINE);
    pdf.add(new Chunk(" "));

}

From source file:com.pfe.web.UtilisateurControler.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();//  w ww.j  a  va  2  s .c  om
    pdf.setPageSize(PageSize.A4);

    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();
    String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
            + File.separator + "pdfs.png";

    pdf.add(Image.getInstance(logo));
}

From source file:com.prime.location.billing.InvoicedBillingManager.java

/**
 * Print invoice/*from  w  w w . ja  v a2s  .  c  o  m*/
 */
public void printInvoice() {
    try { //catch better your exceptions, this is just an example
        FacesContext context = FacesContext.getCurrentInstance();

        Document pdf = new Document(PageSize.A4, 5f, 5f, 75f, 45f);

        String fileName = "PDFFile";

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(pdf, baos);
        TableHeader event = new TableHeader();
        event.setHeader("Header Here");
        writer.setPageEvent(event);

        if (!pdf.isOpen()) {
            pdf.open();
        }

        PdfPCell cell;

        PdfPTable header = new PdfPTable(new float[] { 1, 2, 1 });
        cell = new PdfPCell(new Paragraph("INVOICE",
                FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC, Color.BLACK)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        cell.setBorder(Rectangle.NO_BORDER);
        header.addCell(cell);
        header.setTotalWidth(527);
        header.setLockedWidth(true);

        cell = new PdfPCell(new Phrase("Agency: " + selectedAgency.getDescription()));
        cell.setColspan(2);
        cell.setBorder(Rectangle.NO_BORDER);
        header.addCell(cell);

        cell = new PdfPCell(new Phrase("Invoice#: " + selectedInvoice.getId()));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        header.addCell(cell);

        cell = new PdfPCell(
                new Phrase("Date: " + DateUtility.dateTimeFormat(selectedInvoice.getInvoiceDate())));
        cell.setColspan(3);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        header.addCell(cell);

        pdf.add(header);

        PdfPTable table = new PdfPTable(new float[] { 1, 3, 2, 1 });
        table.setSpacingBefore(15f);

        table.setTotalWidth(527);
        table.setLockedWidth(true);
        //table.setWidths(new int[]{3, 1, 1});

        table.getDefaultCell().setBackgroundColor(Color.LIGHT_GRAY);

        table.addCell("Date");
        table.addCell("Name");
        table.addCell("Service");
        table.addCell("Rate");

        table.getDefaultCell().setBackgroundColor(null);

        cell = new PdfPCell(new Phrase("Total(US$): "));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setColspan(3);
        cell.setBackgroundColor(Color.LIGHT_GRAY);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(selectedInvoice.getAmount())));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBackgroundColor(Color.LIGHT_GRAY);
        table.addCell(cell);

        // There are three special rows
        table.setHeaderRows(2);
        // One of them is a footer
        table.setFooterRows(1);
        Font f = FontFactory.getFont(FontFactory.HELVETICA, 10);
        //add remaining
        for (AgencyBilling billing : selectedInvoice.getBillings()) {
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.getDefaultCell().setIndent(2);
            table.getDefaultCell().setFixedHeight(20);

            table.addCell(new Phrase(DateUtility.dateFormat(billing.getBillingDate()), f));
            table.addCell(new Phrase(billing.getPerson().getName(), f));
            table.addCell(new Phrase(billing.getTariff().getTariffType().getDescription(), f));
            cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(billing.getRate()), f));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

            table.addCell(cell);

        }

        pdf.add(table);

        writer.getAcroForm().setNeedAppearances(true);

        //document.add(new Phrase(TEXT));
        //Keep modifying your pdf file (add pages and more)
        pdf.close();

        writePDFToResponse(context.getExternalContext(), baos, fileName);

        context.responseComplete();

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

From source file:com.pureinfo.srm.patent.action.PatentPrintPdfAction.java

License:Open Source License

/**
 * @see com.pureinfo.ark.interaction.ActionBase#executeAction()
 *//*from w w w  .j  a v  a2  s.  c om*/
public ActionForward executeAction() throws PureException {
    int nYear = request.getRequiredInt("year", "");

    Rectangle rectPageSize = new Rectangle(PageSize.A4);
    rectPageSize.setBackgroundColor(Color.WHITE);
    rectPageSize.setBorderColor(Color.BLACK);
    rectPageSize = rectPageSize.rotate();
    Document doc = new Document(rectPageSize, 10, 10, 10, 10);
    doc.addTitle(nYear + "");
    doc.addAuthor("PureInfo");
    try {
        BaseFont bfontTitle = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font fontTitle = new Font(bfontTitle, 18, Font.NORMAL);
        Paragraph paraTitle = new Paragraph(nYear + "",
                fontTitle);
        paraTitle.setAlignment(ElementTags.ALIGN_CENTER);

        BaseFont bfontContent = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font fontContent = new Font(bfontContent, 10, Font.NORMAL);

        FileFactory fileFactory = FileFactory.getInstance();
        String sPath = fileFactory.lookupPathConfigByFlag(FileFactory.FLAG_DOWNLOADTEMP, true).getLocalPath();

        FileUtil.insurePathExists(sPath);
        PdfWriter.getInstance(doc, new FileOutputStream(new File(sPath, "patent.pdf")));

        doc.open();
        doc.add(paraTitle);
        doc.add(new Paragraph("   "));

        String[] arrTitles = new String[] { "", "", "", "", "", "",
                "", "", "" };
        PdfPTable pTable = new PdfPTable(arrTitles.length);
        pTable.setWidths(new int[] { 5, 10, 9, 9, 20, 15, 12, 10, 10 });

        for (int i = 0; i < arrTitles.length; i++) {
            PdfPCell pCell = new PdfPCell();
            Paragraph para = new Paragraph(arrTitles[i], fontContent);
            para.setAlignment(ElementTags.ALIGN_CENTER);

            pCell.addElement(para);
            pTable.addCell(pCell);
        }

        /**
         * 
         */
        IPatentMgr mgr = (IPatentMgr) ArkContentHelper.getContentMgrOf(Patent.class);
        List patents = mgr.findAllAuthorizedOf(nYear);
        int i = 0;
        for (Iterator iter = patents.iterator(); iter.hasNext(); i++) {
            Patent patent = (Patent) iter.next();
            this.addPatentCell(pTable, String.valueOf(i + 1), fontContent);
            this.addPatentCell(pTable, patent.getPatentSid(), fontContent);
            this.addPatentCell(pTable, ForceConstants.DATE_FORMAT.format(patent.getApplyDate()), fontContent);
            this.addPatentCell(pTable, patent.getWarrantDate() == null ? ""
                    : ForceConstants.DATE_FORMAT.format(patent.getWarrantDate()), fontContent);
            this.addPatentCell(pTable, patent.getName(), fontContent);
            this.addPatentCell(pTable, patent.getAllAuthosName(), fontContent);
            this.addPatentCell(pTable, patent.getRightPerson(), fontContent);
            this.addPatentCell(pTable, getCollegeName(patent), fontContent);
            this.addPatentCell(pTable, patent.getPatentTypeName(), fontContent);
        }

        doc.add(pTable);
        doc.close();

    } catch (DocumentException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace(System.err);
    } catch (IOException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace(System.err);
    }

    List list = new ArrayList();
    list.add(new Pair("/download/patent.pdf", ""));
    request.setAttribute("forward", list);
    return mapping.findForward("success");
}

From source file:com.qcadoo.mes.workPlans.controller.WorkPlansController.java

License:Open Source License

private void printImageToPdf(final Entity attachment, HttpServletResponse response) {
    Document document = new Document();
    try {//from  ww  w .  jav  a  2s  .c  o  m
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();

        document.setPageSize(PageSize.A4);
        pdfHelper.addMetaData(document);
        pdfHelper.addImage(document, attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT));
        document.close();
    } catch (Exception e) {
        LOG.error("Problem with printing document - " + e.getMessage());
        document.close();
        e.printStackTrace();
    }

}