Example usage for com.itextpdf.text Document newPage

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

Introduction

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

Prototype


public boolean newPage() 

Source Link

Document

Signals that an new page has to be started.

Usage

From source file:com.example.drivequickstart.PDFActivity.java

private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*from   w w w  .  java2 s  .co  m*/
    // Lets write a big header
    preface.add(new Paragraph("Title of the document", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes something which is very important ", smallBold));

    addEmptyLine(preface, 8);

    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.de ;-).",
            redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:com.example.pdfcreate.MainActivity.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*from   ww  w  .  j  ava  2 s .  c  om*/
    // Lets write a big header
    preface.add(new Paragraph("Details Of the Form"));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(
            new Paragraph("Report generated by: " + System.getProperty("Paresh Mutha") + ", " + new Date()));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes something which is very important "));

    addEmptyLine(preface, 8);

    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.de ;-)."));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:com.fixent.publish.server.pdf.AddressPdf.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//ww w. j  a  v  a2s  .  c o m
    // Lets write a big header
    preface.add(new Paragraph("Title of the document", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes something which is very important ", smallBold));

    addEmptyLine(preface, 8);

    //      preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
    //            redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:com.github.albfernandez.joinpdf.JoinPdf.java

License:Open Source License

private void addImage(final Image image, final Document document, final PdfWriter writer) throws Exception {
    if (image.getWidth() > image.getHeight()) {
        document.setPageSize(new Rectangle(PageSize.A4.getHeight(), PageSize.A4.getWidth()));
    } else {/*  ww w  .j  av  a2s.  c o  m*/
        document.setPageSize(new Rectangle(PageSize.A4.getWidth(), PageSize.A4.getHeight()));
    }
    image.scaleToFit(document.getPageSize().getWidth() - this.margin * 2f,
            document.getPageSize().getHeight() - this.margin * 2f);
    float px = (document.getPageSize().getWidth() - image.getScaledWidth()) / 2f;
    float py = (document.getPageSize().getHeight() - image.getScaledHeight()) / 2f;
    image.setAbsolutePosition(px, py);
    document.newPage();
    document.add(image);
    writePageNumber(writer);
}

From source file:com.github.albfernandez.joinpdf.JoinPdf.java

License:Open Source License

private void addPdf(final File file, final Document document, final PdfWriter writer) throws Exception {
    PdfReader pdfReader = null;/*from   w w  w.j  av a 2  s . c o m*/
    try (InputStream is = new FileInputStream(file)) {
        pdfReader = new PdfReader(is);
        PdfContentByte cb = writer.getDirectContent();
        for (int currentPage = 1; currentPage <= pdfReader.getNumberOfPages(); currentPage++) {
            Rectangle currentPageSize = pdfReader.getPageSize(currentPage);
            document.setPageSize(currentPageSize);
            document.newPage();
            PdfImportedPage page = writer.getImportedPage(pdfReader, currentPage);
            cb.addTemplate(page, 0, 0);
            writePageNumber(cb);

        }
        writer.flush();
    } finally {
        if (pdfReader != null) {
            writer.freeReader(pdfReader);
            ItextUtils.close(pdfReader);
        }
    }
}

From source file:com.github.ossdevs.jhocr.converter.HocrPageProcessor.java

License:Open Source License

/**
 * This method will process the {@link com.itextpdf.text.Document} fitting the image into the documents page.
 *
 * @param document  will be processed.//from ww w  .  ja v a 2s  .  c om
 * @param pdfWriter will be used to process the {@link com.itextpdf.text.Document}
 */
public boolean process(Document document, PdfWriter pdfWriter) {
    try {

        if (initialized) {
            document.setPageSize(getImageRectangle());

            if (!document.isOpen()) {
                document.open();
            } else {
                document.newPage();
            }

            PdfContentByte cb = pdfWriter.getDirectContentUnder();

            /**
             * This will fit the image into the documents page using the width and height from the image and fitting it into x0 and y0 of the page.
             */
            getImage().scaleToFit(getImageRectangle().getWidth(), getImageRectangle().getHeight());
            getImage().setAbsolutePosition(0, 0);

            pdfWriter.getDirectContent().addImage(getImage());

            for (HocrLine hocrLine : getHocrPage().getLines()) {
                processHocrLine(cb, hocrLine);
            }
        }

        return true;

    } catch (DocumentException e) {
        logger.error("Document could not be processed.", e);
        return false;
    }
}

From source file:com.github.ukase.bulk.BulkRenderTask.java

License:Open Source License

private void appendPdf(Document document, PdfWriter writer, PdfContentByte cb, byte[] pdf) throws IOException {
    PdfReader reader = new PdfReader(pdf);
    for (int i = 1; i <= reader.getNumberOfPages(); i++) {
        PdfImportedPage page = writer.getImportedPage(reader, i);
        document.newPage();
        cb.addTemplate(page, 0, 0);//from   w w w.ja v a2s .c om
    }
}

From source file:com.grant.report.BillPdf.java

private void addTitlePage(Document document, PrintDetails printDetails) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//from w w  w  .  j a  v a 2s. c o m
    // Lets write a big header
    preface.add(new Paragraph("GRANT TECH HOLDINGS", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("No, 407 A, Colombo Road, Pepiliyana", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            subFont));
    preface.add(new Paragraph("Tel/Fax :0112 199 100 | 0719 192 815 | 0719 392 815", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            subFont));
    preface.add(new Paragraph("E-mail :granttech@sltnet.lk | granttechholdings@gmail.com", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            subFont));
    preface.add(new Paragraph(
            "____________________________________________________________________________________", smallBold));

    preface.add(new Paragraph("Customer Name : " + printDetails.getCustomerName(), smallBold));

    preface.add(new Paragraph("Address : " + printDetails.getAddress(), smallBold));

    preface.add(new Paragraph(
            "Date: " + printDetails.getInvoiceNo() + "                | Order No: " + printDetails.getOrderNo(),
            smallBold));

    preface.add(new Paragraph("Pay Type: " + printDetails.getPayType() + "                | Sales Code: "
            + printDetails.getCustomerName(), smallBold));

    preface.add(new Paragraph("Cheque No: " + printDetails.getNoPay(), smallBold));

    createTable(preface);

    Paragraph preface2 = new Paragraph();
    preface2.setIndentationLeft(350);

    preface2.add(new Paragraph("Sub Total : " + printDetails.getSubTotal(), smallBold));

    preface2.add(new Paragraph("Discount  : " + printDetails.getDiscount() + " %", smallBold));

    preface2.add(new Paragraph("Total  : " + printDetails.getTotal(), smallBold));

    Paragraph preface3 = new Paragraph();

    preface3.add(new Paragraph(
            "____________________________________________________________________________________", smallBold));

    preface3.add(new Paragraph("Goods once sold will not be taken back. ", smallBold2));

    preface3.add(new Paragraph(
            "Cheques to be drawn in favour of Grant Tech Holdings (Pvt) Ltd 1146009208-Commercial Bank-Wadduwa. ",
            verySmBold));
    preface3.add(new Paragraph("goods are accepted in good condition. ", verySmBold));

    preface3.add(new Paragraph(
            "____________________________________________________________________________________", smallBold));

    preface3.add(new Paragraph(
            "Name:___________________________________________                          Signature:__________________________________________",
            smallBold3));

    preface3.add(new Paragraph(
            "I.D No (If credit):__________________________________                          Date:______________________________________________",
            smallBold3));

    preface3.add(new Paragraph(
            "Checked by:_______________________________________                        Authorized by:_______________________________________",
            smallBold3));

    preface3.add(new Paragraph(
            "____________________________________________________________________________________", smallBold));

    // now add all this to the document
    document.add(preface);
    document.add(preface2);
    document.add(preface3);
    document.newPage();
}

From source file:com.homecare.bo.EmployeeInfoBOImpl.java

@Scheduled(cron = "0 0 1 * * ?")
@Async/*from www .  jav a2  s  .  c  o  m*/
public void generatePDFAndEmailForAllActiveEmployees() {
    System.out.println("************************************Print All the Reminders");
    EmployeeInfo employeeInfoRequest = new EmployeeInfo();
    employeeInfoRequest.setStatus("A");
    List<EmployeeInfo> employeeList = employeeDAO.getAllEmployees(employeeInfoRequest);
    Map<Long, List<EmployeeInfo>> employeeListMap = getEmployeeListMap(employeeList);
    for (Long employerId : employeeListMap.keySet()) {
        List<EmployeeInfo> employees = employeeListMap.get(employerId);
        Document document = new Document();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            PdfWriter.getInstance(document, out);
            document.open();
            if (null != employees) {
                for (EmployeeInfo employeeInfo : employees) {
                    List<String> reminders = getRemindersByEmployee(employeeInfo);
                    com.itextpdf.text.List list = new com.itextpdf.text.List();
                    if (reminders != null && !reminders.isEmpty()) {
                        document.add(new Chunk(employeeInfo.getLastName() + " " + employeeInfo.getFirstName()));
                        for (String reminder : reminders) {
                            // Add the list items to list        
                            list.add(new ListItem(reminder));
                        }
                        document.add(list);
                        document.newPage();
                    }
                }
            }
            document.close();

            List<EmployerEmailInfo> employerEmailList = employerDAO.getAllEmployerEmails(employerId);
            EmailUtility emailUtility = new EmailUtility();
            emailUtility.sendEmailWithAttachment("Reminders of all the employees", employerEmailList,
                    out.toByteArray());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //clean off           
            if (null != out) {
                try {
                    out.close();
                    out = null;
                } catch (Exception ex) {
                }
            }
        }
    }
}

From source file:com.horizzon.inventerium.ExportPdf.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//from   w  w  w.ja v a  2 s.  c o m
    // Lets write a big header
    preface.add(new Paragraph("Transaction Details"));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(0)));
    addEmptyLine(preface, 3);
    //       preface.add(new Paragraph("This document describes something which is very important ",
    //           smallBold));

    addEmptyLine(preface, 8);

    //       preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
    //           redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}