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.ostrichemulators.semtool.util.ExportUtility.java

License:Open Source License

public static void exportAsPdf(BufferedImage img, File pdf) throws IOException, DocumentException {
    final double MAX_DIM = 14400;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(img, "PNG", baos);
    Image image1 = Image.getInstance(baos.toByteArray(), true);
    Rectangle r;//  www.  j  ava2 s  . c  o  m
    if (image1.getHeight() > MAX_DIM) {
        r = new Rectangle((int) image1.getWidth(), (int) MAX_DIM);
    } else if (image1.getWidth() > MAX_DIM) {
        r = new Rectangle((int) MAX_DIM, (int) image1.getHeight());
    } else {
        r = new Rectangle((int) image1.getWidth() + 20, (int) image1.getHeight() + 20);
    }
    Document document = new Document(r, 15, 25, 15, 25);
    PdfWriter.getInstance(document, new FileOutputStream(pdf));
    document.open();

    int pages = (int) Math.ceil((double) img.getHeight() / MAX_DIM);
    if (pages == 0) {
        pages = 1;
    }
    for (int i = 0; i < pages; i++) {
        BufferedImage temp;
        if (i < pages - 1) {
            temp = img.getSubimage(0, i * (int) MAX_DIM, img.getWidth(), (int) MAX_DIM);
        } else {
            temp = img.getSubimage(0, i * (int) MAX_DIM, img.getWidth(), img.getHeight() % (int) MAX_DIM);
        }
        File tempFile = new File(i + Constants.PNG);
        ImageIO.write(temp, Constants.PNG, tempFile);
        Image croppedImage = Image.getInstance(i + Constants.PNG);
        document.add(croppedImage);
        tempFile.delete();
        if (i < pages - 1) {
            document.newPage();
        }
    }

    document.close();
}

From source file:com.pablog178.pdfcreator.android.PdfcreatorModule.java

License:Open Source License

private void generateiTextPDFfunction(HashMap args) {
    if (args.containsKey("fileName")) {
        Object fileName = args.get("fileName");
        if (fileName instanceof String) {
            this.fileName = (String) fileName;
            Log.i(PROXY_NAME, "fileName: " + this.fileName);
        }/* ww w  .  j a v  a 2s .  co m*/
    } else
        return;

    if (args.containsKey("view")) {
        Object viewObject = args.get("view");
        if (viewObject instanceof TiViewProxy) {
            TiViewProxy viewProxy = (TiViewProxy) viewObject;
            this.view = viewProxy.getOrCreateView();
            if (this.view == null) {
                Log.e(PROXY_NAME, "NO VIEW was created!!");
                return;
            }
            Log.i(PROXY_NAME, "view: " + this.view.toString());
        }
    } else
        return;

    if (args.containsKey("quality")) {
        this.quality = TiConvert.toInt(args.get("quality"));
    }

    if (args.containsKey("pageSize")) {
        Object pageSize = args.get("pageSize");
        if (pageSize instanceof String) {
            if (pageSize.equals("letter")) {
                this.pageSize = PageSize.LETTER;
            } else if (pageSize.equals("A4")) {
                this.pageSize = PageSize.A4;
            } else {
                this.pageSize = PageSize.LETTER;
            }
        }
    }

    TiBaseFile file = TiFileFactory.createTitaniumFile(this.fileName, true);
    Log.i(PROXY_NAME, "file full path: " + file.nativePath());
    try {

        Resources appResources = app.getResources();
        OutputStream outputStream = file.getOutputStream();
        final int MARGIN = 0;
        final float PDF_WIDTH = this.pageSize.getWidth() - MARGIN * 2; // A4: 595 //Letter: 612
        final float PDF_HEIGHT = this.pageSize.getHeight() - MARGIN * 2; // A4: 842 //Letter: 792
        final int DEFAULT_VIEW_WIDTH = 980;
        final int DEFAULT_VIEW_HEIGHT = 1384;
        int viewWidth = DEFAULT_VIEW_WIDTH;
        int viewHeight = DEFAULT_VIEW_HEIGHT;

        Document pdfDocument = new Document(this.pageSize, MARGIN, MARGIN, MARGIN, MARGIN);
        PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, outputStream);

        Log.i(PROXY_NAME, "PDF_WIDTH: " + PDF_WIDTH);
        Log.i(PROXY_NAME, "PDF_HEIGHT: " + PDF_HEIGHT);

        WebView view = (WebView) this.view.getNativeView();

        if (TiApplication.isUIThread()) {

            viewWidth = view.capturePicture().getWidth();
            viewHeight = view.capturePicture().getHeight();

            if (viewWidth <= 0) {
                viewWidth = DEFAULT_VIEW_WIDTH;
            }

            if (viewHeight <= 0) {
                viewHeight = DEFAULT_VIEW_HEIGHT;
            }

        } else {
            Log.e(PROXY_NAME, "NO UI THREAD");
            viewWidth = DEFAULT_VIEW_WIDTH;
            viewHeight = DEFAULT_VIEW_HEIGHT;
        }

        view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        Log.i(PROXY_NAME, "viewWidth: " + viewWidth);
        Log.i(PROXY_NAME, "viewHeight: " + viewHeight);

        float scaleFactorWidth = 1 / ((float) viewWidth / PDF_WIDTH);
        float scaleFactorHeight = 1 / ((float) viewHeight / PDF_HEIGHT);

        Log.i(PROXY_NAME, "scaleFactorWidth: " + scaleFactorWidth);
        Log.i(PROXY_NAME, "scaleFactorHeight: " + scaleFactorHeight);

        Bitmap viewBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
        Canvas viewCanvas = new Canvas(viewBitmap);

        // Paint paintAntialias = new Paint();
        // paintAntialias.setAntiAlias(true);
        // paintAntialias.setFilterBitmap(true);

        Drawable bgDrawable = view.getBackground();
        if (bgDrawable != null) {
            bgDrawable.draw(viewCanvas);
        } else {
            viewCanvas.drawColor(Color.WHITE);
        }
        view.draw(viewCanvas);

        TiBaseFile pdfImg = createTempFile();

        // ByteArrayOutputStream stream = new ByteArrayOutputStream(32);
        // viewBitmap.compress(Bitmap.CompressFormat.JPEG, this.quality, stream);
        viewBitmap.compress(Bitmap.CompressFormat.JPEG, this.quality, pdfImg.getOutputStream());

        FileInputStream pdfImgInputStream = new FileInputStream(pdfImg.getNativeFile());
        byte[] pdfImgBytes = IOUtils.toByteArray(pdfImgInputStream);
        pdfImgInputStream.close();

        // ByteBuffer      buffer         = ByteBuffer.allocate(viewBitmap.getByteCount());
        // viewBitmap.copyPixelsToBuffer(buffer);

        pdfDocument.open();
        float yFactor = viewHeight * scaleFactorWidth;
        int pageNumber = 1;

        do {
            if (pageNumber > 1) {
                pdfDocument.newPage();
            }
            pageNumber++;
            yFactor -= PDF_HEIGHT;

            Image pageImage = Image.getInstance(pdfImgBytes, true);
            // Image pageImage = Image.getInstance(buffer.array());
            pageImage.scalePercent(scaleFactorWidth * 100);
            pageImage.setAbsolutePosition(0f, -yFactor);
            pdfDocument.add(pageImage);

            Log.i(PROXY_NAME, "yFactor: " + yFactor);
        } while (yFactor > 0);

        pdfDocument.close();

        sendCompleteEvent();

    } catch (Exception exception) {
        Log.e(PROXY_NAME, "Error: " + exception.toString());
        sendErrorEvent(exception.toString());
    }
}

From source file:com.pdg.ticket.utils.FirstPdf.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);// w  w  w  .j av a2  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.photon.phresco.framework.docs.impl.DocumentUtil.java

License:Apache License

/**
 * @param titleSection//from   w w  w .  jav  a2 s.c o  m
 * @param writer
 * @param docu
 * @throws PhrescoException 
 */
public static void addPages(InputStream titleSection, PdfWriter writer, com.itextpdf.text.Document docu)
        throws PhrescoException {
    if (isDebugEnabled) {
        S_LOGGER.debug(
                "Entering Method DocumentUtil.addPages(InputStream titleSection, PdfWriter writer, com.itextpdf.text.Document docu)");
    }
    try {
        PdfReader reader = new PdfReader(titleSection);
        reader.consolidateNamedDestinations();
        PdfContentByte cb = writer.getDirectContent();

        int pages = reader.getNumberOfPages();
        for (int i = 1; i <= pages; i++) {
            PdfImportedPage importedPage = writer.getImportedPage(reader, i);
            cb.addTemplate(importedPage, 0, 0);
            docu.newPage();
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new PhrescoException(e);
    }
}

From source file:com.photon.phresco.service.docs.impl.DocumentUtil.java

License:Apache License

/**
 * @param titleSection/*from  w  w  w .  j  a v a  2s  . c om*/
 * @param writer
 * @param docu
 * @throws IOException
 * @throws DocumentException
 */
public static void addPages(InputStream titleSection, PdfWriter writer, com.itextpdf.text.Document docu)
        throws IOException, DocumentException {
    if (isDebugEnabled) {
        S_LOGGER.debug(
                "Entering Method DocumentUtil.addPages(InputStream titleSection, PdfWriter writer, com.itextpdf.text.Document docu)");
    }
    PdfReader reader = new PdfReader(titleSection);
    reader.consolidateNamedDestinations();
    PdfContentByte cb = writer.getDirectContent();

    int pages = reader.getNumberOfPages();
    for (int i = 1; i <= pages; i++) {
        PdfImportedPage importedPage = writer.getImportedPage(reader, i);
        cb.addTemplate(importedPage, 0, 0);
        docu.newPage();
    }
}

From source file:com.photoshop.misc.Factuurgenerator.java

public Factuurgenerator(Order order, Environment env, MessageSource messageSource, Locale locale) {
    this.locale = locale;
    this.messageSource = messageSource;
    this.env = env;
    this.order = order;
    this.filename = "Factuur " + order.getId();
    String FILE = env.getProperty("logo") + this.filename + ".pdf"; //order generate moet nog gemaakt worden
    catFont = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD);
    subtitel = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD);
    subFont = new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL);
    smallBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD);

    try {/*  w w w. j  a  v a2 s . c o m*/
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FILE));
        document.open();
        document.newPage();
        addMetaData(document);
        addTitlePage(document);
        //addContent(document);
        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.photoshop.misc.Indexkaartgenerator.java

private void addTitlePage(Document document) throws DocumentException {
    document.newPage();
    Paragraph preface = new Paragraph();
    addEmptyLine(preface, 1);/*from  w  w w  .j  a va 2  s.  co m*/

    Image Logo = null;
    try {
        Logo = Image.getInstance(env.getProperty("logo") + "Photoshop_black.png");
        Logo.scaleAbsolute(200, 100);
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(OrderController.class.getName()).log(Level.SEVERE, null, ex);
    }
    SimpleDateFormat simpledatafo = new SimpleDateFormat("dd/MM/yyyy");
    preface.add(Logo);
    Paragraph datum = new Paragraph(Getspringmessage("Date") + " " + simpledatafo.format(new Date()),
            smallBold);
    datum.setAlignment(Element.ALIGN_RIGHT);
    preface.add(datum);
    Paragraph Factuurnummer = new Paragraph(this.Getspringmessage("invoicenumber") + " " + order.getId(),
            smallBold);
    Factuurnummer.setAlignment(Element.ALIGN_RIGHT);
    preface.add(Factuurnummer);
    addEmptyLine(preface, 1);

    //Aanmaken van de bedrijfs gegevens
    preface.add(new Paragraph(this.Getspringmessage("company"), subtitel));
    preface.add(new Paragraph("Rachelsmolen 1", subFont));
    preface.add(new Paragraph("5612MA Eindhoven", subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(this.Getspringmessage("accountNumber") + ": 165947888", subFont));
    preface.add(new Paragraph("Bank: Paypal", subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de bestellende persoons gegevens
    preface.add(new Paragraph(this.Getspringmessage("reciver") + ": ", subtitel));
    preface.add(new Paragraph(order.getInvoiceaddress().getKlantnaam(), subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(order.getInvoiceaddress().getAdres(), subFont));
    preface.add(new Paragraph(
            order.getInvoiceaddress().getPostcode() + " " + order.getInvoiceaddress().getWoonplaats(),
            subFont));
    preface.add(new Paragraph(order.getInvoiceaddress().getTelefoonnummer(), subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de start zin 
    preface.add(new Paragraph(this.Getspringmessage("dear") + " " + order.getInvoiceaddress().getKlantnaam(),
            subtitel));
    addEmptyLine(preface, 1);
    preface.add(new Paragraph(
            this.Getspringmessage("allordersby") + " " + order.getInvoiceaddress().getKlantnaam(), subFont));
    addEmptyLine(preface, 1);
    //Aanmaken van de betaal tabel
    createTable(preface);

    //Toevoegen footerzin
    Paragraph footer = new Paragraph(this.Getspringmessage("thanksforordering"), subFont);
    footer.setAlignment(Element.ALIGN_CENTER);
    preface.add(footer);

    document.add(preface);

}

From source file:com.propelics.pdfcreator.PdfcreatorModule.java

License:Open Source License

private void generateiTextPDFfunction(HashMap args) {
    Log.d(PROXY_NAME, "generateiTextPDFfunction()");

    String filename = "";
    TiUIView webview = null;/*w ww  . ja v a  2s . co  m*/
    int quality = 100;

    try {
        if (args.containsKey("filename")) {
            filename = (String) args.get("filename");
            Log.d(PROXY_NAME, "filename: " + filename);
        } else
            return;

        if (args.containsKey("webview")) {
            TiViewProxy viewProxy = (TiViewProxy) args.get("webview");
            webview = viewProxy.getOrCreateView();
            Log.d(PROXY_NAME, "webview: " + webview.toString());
        } else
            return;

        if (args.containsKey("quality")) {
            quality = TiConvert.toInt(args.get("quality"));
        }

        TiBaseFile file = TiFileFactory.createTitaniumFile(filename, true);
        Log.d(PROXY_NAME, "file full path: " + file.nativePath());

        OutputStream outputStream = file.getOutputStream();
        final int MARGIN = 0;
        final float PDF_WIDTH = PageSize.LETTER.getWidth() - MARGIN * 2; // A4: 595 //Letter: 612
        final float PDF_HEIGHT = PageSize.LETTER.getHeight() - MARGIN * 2; // A4: 842 //Letter: 792
        final int DEFAULT_VIEW_WIDTH = 980;
        final int DEFAULT_VIEW_HEIGHT = 1384;
        int viewWidth = DEFAULT_VIEW_WIDTH;
        int viewHeight = DEFAULT_VIEW_HEIGHT;

        Document pdfDocument = new Document(PageSize.LETTER, MARGIN, MARGIN, MARGIN, MARGIN);
        PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, outputStream);

        Log.d(PROXY_NAME, "PDF_WIDTH: " + PDF_WIDTH);
        Log.d(PROXY_NAME, "PDF_HEIGHT: " + PDF_HEIGHT);

        WebView view = (WebView) webview.getNativeView();

        if (TiApplication.isUIThread()) {

            viewWidth = view.capturePicture().getWidth();
            viewHeight = view.capturePicture().getHeight();

            if (viewWidth <= 0) {
                viewWidth = DEFAULT_VIEW_WIDTH;
            }

            if (viewHeight <= 0) {
                viewHeight = DEFAULT_VIEW_HEIGHT;
            }

        } else {
            Log.e(PROXY_NAME, "NO UI THREAD");
            viewWidth = DEFAULT_VIEW_WIDTH;
            viewHeight = DEFAULT_VIEW_HEIGHT;
        }

        view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        Log.d(PROXY_NAME, "viewWidth: " + viewWidth);
        Log.d(PROXY_NAME, "viewHeight: " + viewHeight);

        float scaleFactorWidth = 1 / (viewWidth / PDF_WIDTH);
        float scaleFactorHeight = 1 / (viewHeight / PDF_HEIGHT);

        Log.d(PROXY_NAME, "scaleFactorWidth: " + scaleFactorWidth);
        Log.d(PROXY_NAME, "scaleFactorHeight: " + scaleFactorHeight);

        Bitmap viewBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
        Canvas viewCanvas = new Canvas(viewBitmap);

        // Paint paintAntialias = new Paint();
        // paintAntialias.setAntiAlias(true);
        // paintAntialias.setFilterBitmap(true);

        Drawable bgDrawable = view.getBackground();
        if (bgDrawable != null) {
            bgDrawable.draw(viewCanvas);
        } else {
            viewCanvas.drawColor(Color.WHITE);
        }
        view.draw(viewCanvas);

        TiBaseFile pdfImg = createTempFile(filename);

        viewBitmap.compress(Bitmap.CompressFormat.PNG, quality, pdfImg.getOutputStream());

        FileInputStream pdfImgInputStream = new FileInputStream(pdfImg.getNativeFile());
        byte[] pdfImgBytes = IOUtils.toByteArray(pdfImgInputStream);
        pdfImgInputStream.close();

        pdfDocument.open();
        float yFactor = viewHeight * scaleFactorWidth;
        int pageNumber = 1;

        do {
            if (pageNumber > 1) {
                pdfDocument.newPage();
            }
            pageNumber++;
            yFactor -= PDF_HEIGHT;

            Image pageImage = Image.getInstance(pdfImgBytes, true);
            // Image pageImage = Image.getInstance(buffer.array());
            pageImage.scalePercent(scaleFactorWidth * 100);
            pageImage.setAbsolutePosition(0f, -yFactor);
            pdfDocument.add(pageImage);

            Log.d(PROXY_NAME, "yFactor: " + yFactor);
        } while (yFactor > 0);

        pdfDocument.close();

        sendCompleteEvent(filename);

    } catch (Exception exception) {
        sendErrorEvent(exception);
    }
}

From source file:com.quix.aia.cn.imo.mapper.ApplicationFormPDFMaintenance.java

License:Open Source License

private static Document ESingnature(Document document, PdfWriter writer, AddressBook addressbook) {
    // TODO Auto-generated method stub
    log.log(Level.INFO, "ApplicationFormPDFMaintenance --> ESingnature ");
    try {//from  ww w.  java  2 s .  c om

        document.newPage();

        PdfPTable table = new PdfPTable(2);
        table.setSpacingBefore(10);
        table.setWidthPercentage(100f);

        PdfPCell c1 = new PdfPCell(new Phrase("E-singnature "));
        c1.setHorizontalAlignment(Element.ALIGN_LEFT);
        c1.setColspan(4);
        c1.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP);
        c1.setFixedHeight(30f);
        c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        c1.setBorder(Rectangle.BOX);
        c1.setFixedHeight(25f);
        table.addCell(c1);
        table.setHeaderRows(1);

        for (int i = 0; i < 2; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }

        Iterator itr = null;
        CandidateESignature esignature = new CandidateESignature();
        if (addressbook.getCandidateESignatures().size() > 0) {
            itr = addressbook.getCandidateESignatures().iterator();
            esignature = (CandidateESignature) itr.next();
        }

        c1 = new PdfPCell(new Phrase("Branch : " + esignature.getBranch(), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        c1.setBorder(Rectangle.BOTTOM);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Servicing Department : " + esignature.getServiceDepartment(), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        c1.setBorder(Rectangle.BOTTOM);
        table.addCell(c1);

        for (int i = 0; i < 2; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }

        c1 = new PdfPCell(new Phrase("City : " + esignature.getCity(), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        c1.setBorder(Rectangle.BOTTOM);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Agent Code : " + esignature.getAgentId(), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        c1.setBorder(Rectangle.BOTTOM);
        table.addCell(c1);

        for (int i = 0; i < 4; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }

        document.add(table);

        table = new PdfPTable(2);
        table.setSpacingBefore(10);
        table.setWidthPercentage(100f);
        table.setWidths(new int[] { 80, 20 });

        c1 = new PdfPCell(new Phrase("Presently attached with another insurance Company ?  ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Yes \t\t\t\t\t\t\t\t  No", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        for (int i = 0; i < 2; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);

        }

        c1 = new PdfPCell(
                new Phrase("Presently in contact with any other AIA'S servicing Department ?   ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Yes \t\t\t\t\t\t\t\t  No", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        for (int i = 0; i < 2; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);

        }

        c1 = new PdfPCell(
                new Phrase("Taken LOMBRA occupational test or PSP test in the past ?  If Yes, ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Yes \t\t\t\t\t\t\t\t  No", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        for (int i = 0; i < 2; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);

        }

        c1 = new PdfPCell(new Phrase("Please provide the result.  ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        for (int i = 0; i < 5; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }
        document.add(table);

        Paragraph para1 = new Paragraph();
        para1.add(new Chunk("Applicant's Declaration ", font));
        para1.setAlignment(Element.ALIGN_LEFT);
        para1.setSpacingAfter(5f);
        document.add(para1);

        table = new PdfPTable(2);
        table.setSpacingBefore(10);
        table.setWidthPercentage(100f);

        for (int i = 0; i < 4; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);

            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }

        c1 = new PdfPCell(new Phrase("Application Date", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Applicant/Candidate Name  :", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        if (esignature.getApplicationDate() != null) {
            c1 = new PdfPCell(new Phrase(format.format(esignature.getApplicationDate()), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        } else {
            c1 = new PdfPCell(new Phrase("", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }

        c1 = new PdfPCell(new Phrase(esignature.getCandidateName(), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        for (int i = 0; i < 4; i++) {
            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);

            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            table.addCell(c1);
        }
        document.add(table);

        para1 = new Paragraph();
        para1.add(new Chunk("E-Signature  : ", font));
        para1.setAlignment(Element.ALIGN_LEFT);
        para1.setSpacingAfter(5f);
        document.add(para1);

        c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        if (esignature.geteSignaturePhoto() != null) {
            Image image = Image.getInstance(esignature.geteSignaturePhoto());
            para1 = new Paragraph();
            para1.add(image);
            para1.setAlignment(Element.ALIGN_LEFT);
            para1.setSpacingAfter(5f);
            document.add(para1);
        } else {
            para1 = new Paragraph();
            para1.add("");
            para1.setAlignment(Element.ALIGN_LEFT);
            para1.setSpacingAfter(5f);
            document.add(para1);
        }

    } catch (Exception e) {
        // TODO Auto-generated catch block
        log.log(Level.INFO, "ApplicationFormPDFMaintenance --> ESingnature " + e.getMessage());
        e.printStackTrace();
        e.printStackTrace();
        LogsMaintenance logsMain = new LogsMaintenance();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        logsMain.insertLogs("ApplicationFormPDFMaintenance", Level.SEVERE + "", errors.toString());
    }

    return document;
}

From source file:com.quix.aia.cn.imo.mapper.ApplicationFormPDFMaintenance.java

License:Open Source License

private static Document personalCertification(Document document, PdfWriter writer, AddressBook addressbook) {
    // TODO Auto-generated method stub
    log.log(Level.INFO, "ApplicationFormPDFMaintenance --> personalCertification ");
    try {//from w w w.  j  a v a  2  s  . c o  m

        /*  New Page   */
        document.newPage();

        PdfPTable table = new PdfPTable(2);
        table.setSpacingBefore(10);
        table.setWidthPercentage(100f);
        int i = 0;

        for (Iterator itr = addressbook.getCandidateProfessionalCertifications().iterator(); itr.hasNext();) {
            CandidateProfessionalCertification procertification = (CandidateProfessionalCertification) itr
                    .next();
            if (i != 0) {
                PdfPCell c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);

                c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);
            }
            i++;
            PdfPCell c1 = new PdfPCell(new Phrase("PERSONAL CERTIFICATION"));
            c1.setHorizontalAlignment(Element.ALIGN_LEFT);
            c1.setColspan(4);
            c1.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP);
            c1.setFixedHeight(30f);
            c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
            c1.setBorder(Rectangle.BOX);
            c1.setFixedHeight(25f);
            table.addCell(c1);
            table.setHeaderRows(1);

            for (int j = 0; j < 2; j++) {
                c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);

            }

            c1 = new PdfPCell(new Phrase("Certificate Name: " + procertification.getCertificateName(), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

            c1 = new PdfPCell(new Phrase("Chrater Agency: " + procertification.getCharterAgency(), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

            for (int j = 0; j < 2; j++) {
                c1 = new PdfPCell(new Phrase(" ", font));
                c1.setBorder(Rectangle.NO_BORDER);
                c1.setLeading(4f, 0f);
                c1.setFixedHeight(15f);
                table.addCell(c1);

            }

            c1 = new PdfPCell(
                    new Phrase("Charter Date : " + format.format(procertification.getCharterDate()), font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

            c1 = new PdfPCell(new Phrase(" ", font));
            c1.setBorder(Rectangle.NO_BORDER);
            c1.setLeading(4f, 0f);
            c1.setFixedHeight(15f);
            //c1.setBorder(Rectangle.BOTTOM);
            table.addCell(c1);

        }

        document.add(table);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        log.log(Level.INFO, "ApplicationFormPDFMaintenance --> personalCertification " + e.getMessage());
        e.printStackTrace();
        e.printStackTrace();
        LogsMaintenance logsMain = new LogsMaintenance();
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        logsMain.insertLogs("ApplicationFormPDFMaintenance", Level.SEVERE + "", errors.toString());
    }

    return document;
}