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:org.apache.maven.doxia.module.itext.ITextUtil.java

License:Apache License

/**
 * Set the default page size for the document depending the user's country.
 * TODO Maybe more generic?/*from  ww  w.  java  2s .c o m*/
 *
 * @return the page size
 * @see com.lowagie.text.PageSize
 */
public static Rectangle getDefaultPageSize() {
    String defaultCountry = Locale.getDefault().getCountry();
    if (defaultCountry != null && (defaultCountry.equals(Locale.US.getCountry())
            || defaultCountry.equals(Locale.CANADA.getCountry()))) {
        return PageSize.LETTER;
    }

    return PageSize.A4;
}

From source file:org.areasy.common.doclet.document.tags.TagIMG.java

License:Open Source License

public Element[] toPdfObjects() {
    String src = getAttribute("src");
    Element[] results = new Element[0];
    Element result = null;/*from   w w w.j av a2  s.  c om*/

    if (src == null) {
        log.error("Image tag has no 'src' attribute.");
        return null;
    }

    try {
        // now we use awt Image to create iText image instead of
        // letting it read images by itself
        java.awt.Image awt = null;

        if (src.indexOf("://") > 0)
            awt = Toolkit.getDefaultToolkit().createImage(new URL(src));
        else {
            String filePath = DocletUtility.getFilePath(src);
            awt = Toolkit.getDefaultToolkit().createImage(filePath);
        }

        //img = Image.getInstance(PDFUtil.getFilePath(src));
        img = Image.getInstance(awt, null);

        // for the time being let's stick with A4
        Rectangle size = PageSize.A4;
        String width = getAttribute("width");

        if (width != null) {
            // trying to cope with the resolution differences
            float w = NumberUtility.toFloat(width, 0) / 96 * 72;
            img.scaleAbsoluteWidth(w);
        }

        float maxW = size.width() - 100;

        if (img.plainWidth() > maxW)
            img.scaleAbsoluteWidth(maxW);

        String height = getAttribute("height");

        if (height != null) {
            // trying to cope with the resolution differences
            float h = NumberUtility.toFloat(height, 0) / 96 * 72;
            img.scaleAbsoluteHeight(h);
        }

        float maxH = size.height() - 100;

        if (img.plainHeight() > maxH)
            img.scaleAbsoluteHeight(maxH);

        result = img;

        img.setAlignment(HtmlTagUtility.getAlignment(getAttribute("align"), Element.ALIGN_CENTER));

        String border = getAttribute("border");

        if (border != null) {
            // trying to cope with the resolution differences
            float b = NumberUtility.toFloat(border, 0);

            img.setBorder((int) b);
            img.setBorderWidthTop(b);
            img.setBorderWidthLeft(b);
            img.setBorderWidthRight(b);
            img.setBorderWidthBottom(b);
            img.setBorderColor(Color.black);
        }

    } catch (FileNotFoundException e) {
        DocletUtility.error("** Image not found: " + src, e);
    } catch (Exception e) {
        DocletUtility.error("** Failed to read image: " + src, e);
    }

    if (result != null) {
        results = new Element[1];
        results[0] = result;
    }

    return results;
}

From source file:org.bambrikii.photobank.web.documents.paymentcertificates.impl.PaymentCertificateBuilderRU.java

public void build(OutputStream outputStream) throws DocumentGenerationException {
    Document doc = new Document(PageSize.A4);
    PdfWriter writer;/*from w w w . ja  va 2s  .co  m*/
    BaseFont baseFont = null;
    try {
        writer = PdfWriter.getInstance(doc, outputStream);

        writer.setEncryption(null, "qweasdzxc".getBytes(), PdfWriter.ALLOW_PRINTING,
                PdfWriter.ENCRYPTION_AES_128);

        doc.open();

        String baseFontPath = getResourcesPath() + "org/bambrikii/photobank/web/documents/ARIAL.TTF";
        final String stampImagePath = getResourcesPath()
                + "org/bambrikii/photobank/web/documents/paymentcertificates/PersonaStarsStamp.png";
        baseFont = BaseFont.createFont(baseFontPath, "Cp1251", true);

        Font baseTextStyle = new com.lowagie.text.Font(baseFont, 10, com.lowagie.text.Font.NORMAL,
                new Color(0, 0, 0));
        Font baseBoldTextStyle = new com.lowagie.text.Font(baseFont, 10, com.lowagie.text.Font.BOLD,
                new Color(0, 0, 0));

        Calendar cal = Calendar.getInstance(getLocale());
        cal.setTime(getData().getDate());

        // Act number
        String actNumber = MessageFormat.format(
                "\u0410\u043a\u0442 \u2116 {0} \u043e\u0442 \u00ab{1}\u00bb {2} {3} \u0433\u043e\u0434\u0430",
                String.valueOf(getData().getNumber()), cal.get(Calendar.DAY_OF_MONTH),
                monthsGenitiveCase.get(cal.get(Calendar.MONTH)).toLowerCase(),
                String.valueOf(cal.get(Calendar.YEAR)));
        Paragraph actNumberParagraph = new Paragraph(actNumber,
                new com.lowagie.text.Font(baseFont, 12, com.lowagie.text.Font.BOLD, new Color(0, 0, 0)));
        actNumberParagraph.setSpacingAfter(19);

        Paragraph cityParagraph = new Paragraph("\u0433. \u041c\u043e\u0441\u043a\u0432\u0430", baseTextStyle);
        cityParagraph.setSpacingAfter(15);

        // Licensor
        Paragraph licensorParagraph = new Paragraph();
        licensorParagraph
                .add(new Chunk("\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0440: ", baseBoldTextStyle));
        licensorParagraph.add(new Chunk(MessageFormat.format("{0}",
                "\u0418\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c \u041b\u0438\u043f\u0430\u0442\u043d\u0438\u043a\u043e\u0432 \u0415\u0432\u0433\u0435\u043d\u0438\u0439 \u0410\u0440\u043a\u0430\u0434\u044c\u0435\u0432\u0438\u0447, \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0421\u0432\u0438\u0434\u0435\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u041e\u0413\u0420\u041d \u2116 305501025600011 \u043e\u0442 13.09.2005\u0433."),
                baseTextStyle));
        licensorParagraph.setSpacingAfter(15);

        // Licensee
        Paragraph licenseeParagraph = new Paragraph();
        licenseeParagraph
                .add(new Chunk("\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0442: ", baseBoldTextStyle));
        licenseeParagraph.add(new Chunk(getData().getLicensee(), baseTextStyle));
        licenseeParagraph.setSpacingAfter(15);

        // Pre text
        Paragraph pretextParagraph = new Paragraph();
        pretextParagraph.add(new Chunk(
                "\u0412 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0414\u043e\u0433\u043e\u0432\u043e\u0440\u043e\u043c \u041e\u0444\u0435\u0440\u0442\u044b \u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0440 \u043f\u0435\u0440\u0435\u0434\u0430\u043b \u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0442\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (\u0446\u0438\u0444\u0440\u043e\u0432\u044b\u0435 \u043a\u043e\u043f\u0438\u0438) \u0438 \u043d\u0435\u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 (\u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f): ",
                baseTextStyle));
        pretextParagraph.setSpacingAfter(15);

        int defaultLeading = 9;
        // Files table
        Table filesTbl = new Table(5);
        filesTbl.setWidths(new int[] { 5, 35, 35, 10, 15 });
        filesTbl.setBorder(Table.RECTANGLE);
        filesTbl.setBorderWidth(1);
        filesTbl.setSpacing(0);
        filesTbl.setPadding(2);
        filesTbl.setCellsFitPage(false);
        filesTbl.setUseVariableBorders(true);
        filesTbl.setAlignment(Element.ALIGN_LEFT);
        filesTbl.setWidth(100);

        Cell cellheader1 = new Cell(new Phrase(new Chunk("\u2116", baseBoldTextStyle)));
        cellheader1.setHeader(true);
        cellheader1.setLeading(defaultLeading);
        cellheader1.setHorizontalAlignment(Cell.ALIGN_CENTER);
        filesTbl.addCell(cellheader1);

        Cell cellheader2 = new Cell(new Phrase(
                new Chunk("\u041d\u043e\u043c\u0435\u0440 \u0444\u043e\u0442\u043e", baseBoldTextStyle)));
        cellheader2.setHeader(true);
        cellheader2.setLeading(defaultLeading);
        cellheader2.setHorizontalAlignment(Cell.ALIGN_CENTER);
        filesTbl.addCell(cellheader2);

        Cell cellheader3 = new Cell(
                new Phrase(new Chunk("\u041f\u0435\u0440\u0441\u043e\u043d\u0430", baseBoldTextStyle)));
        cellheader3.setHeader(true);
        cellheader3.setLeading(defaultLeading);
        cellheader3.setHorizontalAlignment(Cell.ALIGN_CENTER);
        filesTbl.addCell(cellheader3);

        Cell cellheader4 = new Cell(
                new Phrase(new Chunk("\u0420\u0430\u0437\u043c\u0435\u0440", baseBoldTextStyle)));
        cellheader4.setHeader(true);
        cellheader4.setLeading(defaultLeading);
        cellheader4.setHorizontalAlignment(Cell.ALIGN_CENTER);
        filesTbl.addCell(cellheader4);

        Cell cellheader5 = new Cell(
                new Phrase(new Chunk("\u0426\u0435\u043d\u0430 \u0440\u0443\u0431.", baseBoldTextStyle)));
        cellheader5.setHeader(true);
        cellheader5.setLeading(defaultLeading);
        cellheader5.setHorizontalAlignment(Cell.ALIGN_CENTER);
        filesTbl.addCell(cellheader5);
        filesTbl.endHeaders();

        Integer i = 0;
        for (PaymentCertificateDataItem item : getData().getItems()) {
            i++;
            Cell cell1 = new Cell(new Phrase(new Chunk(Integer.toString(i), baseTextStyle)));
            cell1.setLeading(defaultLeading);
            cell1.setHorizontalAlignment(Cell.ALIGN_CENTER);
            cell1.setBorder(Cell.NO_BORDER);
            filesTbl.addCell(cell1);

            Cell cell2 = new Cell(new Phrase(new Chunk(item.getFilename(), baseTextStyle)));
            cell2.setLeading(defaultLeading);
            cell2.setHorizontalAlignment(Cell.ALIGN_LEFT);
            cell2.setBorder(Cell.NO_BORDER);
            filesTbl.addCell(cell2);

            Cell cell3 = new Cell(new Phrase(new Chunk(item.getName(), baseTextStyle)));
            cell3.setLeading(defaultLeading);
            cell3.setHorizontalAlignment(Cell.ALIGN_LEFT);
            cell3.setBorder(Cell.NO_BORDER);
            filesTbl.addCell(cell3);

            Cell cell4 = new Cell(new Phrase(new Chunk(item.getSizeName(), baseTextStyle)));
            cell4.setLeading(defaultLeading);
            cell4.setHorizontalAlignment(Cell.ALIGN_CENTER);
            cell4.setBorder(Cell.NO_BORDER);
            filesTbl.addCell(cell4);

            Cell cell5 = new Cell(new Phrase(new Chunk(Double.toString(item.getPrice()), baseTextStyle)));
            cell5.setLeading(defaultLeading);
            cell5.setHorizontalAlignment(Cell.ALIGN_CENTER);
            cell5.setBorder(Cell.NO_BORDER);
            filesTbl.addCell(cell5);
        }
        filesTbl.complete();

        // filesTbl.normalize();

        String totalPrice = MessageFormat.format("{0} {1}", String.valueOf(getData().getTotal()),
                getData().getCurrency());

        Paragraph totalParagraph = new Paragraph();
        totalParagraph.setAlignment(Paragraph.ALIGN_RIGHT);

        totalParagraph.add(new Chunk("\u0418\u0442\u043e\u0433\u043e: ", baseTextStyle));
        totalParagraph.add(new Chunk(totalPrice, baseBoldTextStyle));
        totalParagraph.setSpacingAfter(25);

        Paragraph posttext1Paragraph = new Paragraph();
        posttext1Paragraph.add(new Chunk(
                "\u0412\u043e\u0437\u043d\u0430\u0433\u0440\u0430\u0436\u0434\u0435\u043d\u0438\u0435 \u0437\u0430 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442: ",
                baseTextStyle));
        posttext1Paragraph.add(new Chunk(totalPrice, baseBoldTextStyle));
        // posttext1Paragraph.setSpacingAfter(15);

        Paragraph posttext2Paragraph = new Paragraph(
                "\u041d\u0414\u0421 \u043d\u0435 \u043e\u0431\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043f\u0443\u043d\u043a\u0442\u0430\u043c\u0438 2, 3 \u0438 5 \u0441\u0442\u0430\u0442\u044c\u0438 346.11 \u041d\u0430\u043b\u043e\u0433\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0435\u043a\u0441\u0430 \u0420\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u043e\u0439 \u0424\u0435\u0434\u0435\u0440\u0430\u0446\u0438\u0438.",
                baseTextStyle);
        posttext2Paragraph.setSpacingAfter(15);

        Paragraph posttext3Paragraph = new Paragraph(
                "\u041f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u0440\u043e\u043a\u043e\u043c \u043d\u0430 1 (\u043e\u0434\u0438\u043d) \u0433\u043e\u0434 \u0441 \u0434\u0430\u0442\u044b \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432 \u0410\u043a\u0442\u0435.",
                baseTextStyle);
        posttext3Paragraph.setSpacingAfter(15);

        Paragraph posttext4Paragraph = new Paragraph();
        posttext4Paragraph.add(new Chunk(
                "\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0442 \u043d\u0435 \u0432\u043f\u0440\u0430\u0432\u0435 ",
                baseTextStyle));
        posttext4Paragraph.add(new Chunk("(\u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u0442\u0441\u044f)",
                baseBoldTextStyle));
        posttext4Paragraph.add(new Chunk(
                ": \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0442\u044c \u0438 \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u043a\u043e\u043f\u0438\u0438 \u0444\u0430\u0439\u043b\u043e\u0432 \u0441 \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438; \u043f\u0440\u043e\u0434\u0430\u0432\u0430\u0442\u044c, \u0441\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043f\u0440\u043e\u043a\u0430\u0442, \u0430\u0440\u0435\u043d\u0434\u0443, \u043b\u0438\u0437\u0438\u043d\u0433, \u043a\u0430\u043a \u0441\u0430\u043c\u0438 \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0438 \u0444\u0430\u0439\u043b\u044b \u0441 \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u0434\u0438\u0437\u0430\u0439\u043d\u0435 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u0435\u0439, \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0445 \u043a\u0430\u0440\u0442\u043e\u0447\u0435\u043a \u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043a, \u043f\u043e\u0441\u0442\u0435\u0440\u043e\u0432 \u0438 \u043e\u0431\u0440\u0430\u043c\u043b\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0439 \u0432 \u0446\u0435\u043b\u044f\u0445 \u043f\u0440\u043e\u0434\u0430\u0436\u0438; \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u0441\u0435\u0442\u044c \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u043c \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0442\u0440\u0435\u0442\u044c\u0438\u043c\u0438 \u043b\u0438\u0446\u0430\u043c\u0438, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c, \u0434\u0435\u043b\u0430\u044f \u0438\u0445 \u043e\u0431\u0449\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438.",
                baseTextStyle));
        posttext4Paragraph.setSpacingAfter(15);

        Paragraph posttext5Paragraph = new Paragraph(
                "\u0421\u0442\u043e\u0440\u043e\u043d\u044b \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e \u0443\u0441\u043b\u0443\u0433\u0438 \u043f\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u043f\u0440\u0430\u0432 \u043d\u0430 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438 \u0432 \u043f\u043e\u043b\u043d\u043e\u043c \u043e\u0431\u044a\u0435\u043c\u0435. \u0421\u0442\u043e\u0440\u043e\u043d\u044b \u043f\u0440\u0435\u0442\u0435\u043d\u0437\u0438\u0439 \u0434\u0440\u0443\u0433 \u043a \u0434\u0440\u0443\u0433\u0443 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442.",
                baseTextStyle);
        posttext5Paragraph.setSpacingAfter(15);

        // Signatures
        Table signaturesTable = new Table(4);
        signaturesTable.setWidths(new int[] { 10, 40, 10, 40 });
        signaturesTable.setWidth(100);
        signaturesTable.setSpacing(0);
        signaturesTable.setPadding(5);
        signaturesTable.setBorder(Table.NO_BORDER);

        Cell licensorSignature1Cell = new Cell(new Phrase(
                new Chunk("\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0440:", baseBoldTextStyle)));
        licensorSignature1Cell.setHorizontalAlignment(Cell.ALIGN_LEFT);
        licensorSignature1Cell.setBorder(Cell.NO_BORDER);

        Cell licensorSignature2Cell = new Cell(new Phrase(new Chunk(
                "______________/ \u041b\u0438\u043f\u0430\u0442\u043d\u0438\u043a\u043e\u0432 \u0415.\u0410. /",
                baseTextStyle)));
        licensorSignature2Cell.setHorizontalAlignment(Cell.ALIGN_LEFT);
        licensorSignature2Cell.setBorder(Cell.NO_BORDER);
        licensorSignature2Cell.addElement(new Paragraph("\n\n\n\n"));
        licensorSignature2Cell.add(
                // Stamp
                Image.getInstance(stampImagePath));

        Cell licenseeSignature1Cell = new Cell(new Phrase(
                new Chunk("\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0442:", baseBoldTextStyle)));
        licenseeSignature1Cell.setHorizontalAlignment(Cell.ALIGN_LEFT);
        licenseeSignature1Cell.setBorder(Cell.NO_BORDER);

        Cell licenseeSignature2Cell = new Cell(new Phrase(new Chunk(
                MessageFormat.format("______________/ {0} /", getData().getLicensee()), baseTextStyle)));
        licenseeSignature2Cell.setHorizontalAlignment(Cell.ALIGN_LEFT);
        licenseeSignature2Cell.setBorder(Cell.NO_BORDER);

        signaturesTable.addCell(new Cell() {
            {
                setBorder(Cell.NO_BORDER);
            }
        });
        signaturesTable.addCell(licensorSignature1Cell);
        signaturesTable.addCell(new Cell(true) {
            {
                setBorder(Cell.NO_BORDER);
            }
        });
        signaturesTable.addCell(licenseeSignature1Cell);
        signaturesTable.addCell(new Cell(true) {
            {
                setBorder(Cell.NO_BORDER);
            }
        });
        signaturesTable.addCell(licensorSignature2Cell);
        signaturesTable.addCell(new Cell(true) {
            {
                setBorder(Cell.NO_BORDER);
            }
        });
        signaturesTable.addCell(licenseeSignature2Cell);

        signaturesTable.addCell(new Cell(true) {
            {
                setBorder(Cell.NO_BORDER);
            }
        });
        signaturesTable.addCell(new Cell(true) {
            {
                setBorder(Cell.NO_BORDER);
            }
        });

        signaturesTable.complete();
        // PdfPTable signaturePdPfTable = signaturesTable.createPdfPTable();

        // Document items
        doc.add(actNumberParagraph);
        doc.add(cityParagraph);
        doc.add(licensorParagraph);
        doc.add(licenseeParagraph);
        doc.add(pretextParagraph);
        doc.add(filesTbl);
        doc.add(totalParagraph);
        doc.add(posttext1Paragraph);
        doc.add(posttext2Paragraph);
        doc.add(posttext3Paragraph);
        doc.add(posttext4Paragraph);
        doc.add(posttext5Paragraph);
        doc.add(signaturesTable);

        doc.close();
    } catch (DocumentException ex) {
        throw new DocumentGenerationException("Exception creating document.", ex);
    } catch (IOException ex) {
        throw new DocumentGenerationException(
                "Exception creating document, required font file may not be found.", ex);
    }
}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.CaseStudieSummaryPDF.java

License:Open Source License

/**
 * This method is used for generating the PDF File.
 * //from w  w  w.  j  av a 2s.c  o m
 * @param project project prepared before with the information
 * @param currentPlanningYear current year of planning
 * @param midOutcomeYear year 2019
 */
public void generatePdf(Project project, int currentPlanningYear, int currentReportingYear,
        int midOutcomeYear) {

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    this.document = new Document(PageSize.A4, 57, 57, 60, 57);
    this.project = project;
    this.midOutcomeYear = midOutcomeYear;

    this.setSummaryTitle(project.getStandardIdentifier(Project.PDF_IDENTIFIER_REPORT));
    PdfWriter writer = this.initializePdf(document, outputStream, PORTRAIT);

    // Open document
    document.open();

    // Summary content

    this.addProjectOutcomes("4");

    // Close document
    document.close();

    // Setting result file attributes
    contentLength = outputStream.size();

    inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    /*
     * InputStream inputStream_loca = new ByteArrayInputStream(outputStream.toByteArray());
     * try {
     * FileUtils.copyInputStreamToFile(inputStream_loca, new File("C:test.pdf"));
     * } catch (IOException e) {
     * // TODO Auto-generated catch block
     * e.printStackTrace();
     * }
     */
}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java

License:Open Source License

/**
 * This method is used for generating the PDF File.
 * /* w w w . ja  va  2s .  c  o m*/
 * @param project project prepared before with the information
 * @param currentPlanningYear current year of planning
 * @param midOutcomeYear year 2019
 */
public void generatePdf(Project project, int currentPlanningYear, int currentReportingYear,
        int midOutcomeYear) {

    this.prepareFormatter();
    this.allMOGs = elementManager.getIPElementList();
    statuses = new HashMap<>();
    List<ProjectStatusEnum> list = Arrays.asList(ProjectStatusEnum.values());
    for (ProjectStatusEnum projectStatusEnum : list) {
        statuses.put(projectStatusEnum.getStatusId(), projectStatusEnum.getStatus());
    }

    this.mapPartnerPersons = projectPartnerManager.getAllProjectPartnersPersonsWithTheirInstitution();

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    this.document = new Document(PageSize.A4, 57, 57, 60, 57);
    this.project = project;
    this.midOutcomeYear = midOutcomeYear;
    this.currentPlanningYear = currentPlanningYear;
    this.currentReportingYear = currentReportingYear;
    this.setSummaryTitle(project.getStandardIdentifier(Project.PDF_IDENTIFIER_REPORT));

    PdfWriter writer = this.initializePdf(document, outputStream, PORTRAIT);

    // Adding the event to include header and footer on each page

    HeaderFooterPDF event;

    if (project.isReporting()) {
        event = new HeaderFooterPDF(summaryTitle, PORTRAIT,
                project.isSubmitted(currentReportingYear, APConstants.REPORTING_SECTION),
                APConstants.REPORTING_SECTION, String.valueOf(currentReportingYear));
    } else {
        event = new HeaderFooterPDF(summaryTitle, PORTRAIT,
                project.isSubmitted(currentPlanningYear, APConstants.PLANNING_SECTION),
                APConstants.PLANNING_SECTION, String.valueOf(this.currentPlanningYear));
    }

    writer.setPageEvent(event);

    // Open document
    document.open();

    // Summary content
    this.addProjectTitle();
    this.addMainInformationTable();
    this.addProjectContributions();
    this.addSummary();
    this.addProjectPartners();
    this.addProjectLocations();
    this.addProjectOutcomes("4");
    this.addProjectOutputs("5");
    this.addActivities();
    if (project.isReporting()) {
        this.addBudgetReporting("7");
    } else {
        this.addProjectBudgets();
    }

    // Close document
    document.close();

    // Setting result file attributes
    contentLength = outputStream.size();
    inputStream = new ByteArrayInputStream(outputStream.toByteArray());
}

From source file:org.deegree.igeo.views.swing.print.VectorPrintDialog.java

License:Open Source License

private void initGUI() {
    try {/*from w ww.j a  v  a2s . c  om*/
        {
            GridBagLayout thisLayout = new GridBagLayout();
            thisLayout.rowWeights = new double[] { 0.0, 0.0 };
            thisLayout.rowHeights = new int[] { 531, 16 };
            thisLayout.columnWeights = new double[] { 0.1, 0.1 };
            thisLayout.columnWidths = new int[] { 7, 20 };
            getContentPane().setLayout(thisLayout);
            {
                pnButtons = new JPanel();
                FlowLayout pnButtonsLayout = new FlowLayout();
                pnButtonsLayout.setAlignment(FlowLayout.LEFT);
                pnButtons.setLayout(pnButtonsLayout);
                getContentPane().add(pnButtons, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                {
                    btPrint = new JButton(Messages.getMessage(getLocale(), "$MD11785"),
                            IconRegistry.getIcon("accept.png"));
                    pnButtons.add(btPrint);
                    btPrint.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent event) {
                            if (tfOutputFile.getText().trim().length() < 3) {
                                DialogFactory.openWarningDialog(appContainer.getViewPlatform(),
                                        VectorPrintDialog.this, Messages.get("$MD11817"),
                                        Messages.get("$MD11818"));
                            } else {
                                doPrint();
                            }
                        }
                    });
                }
                {
                    btCancel = new JButton(Messages.getMessage(getLocale(), "$MD11786"),
                            IconRegistry.getIcon("cancel.png"));
                    btCancel.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            VectorPrintDialog.this.dispose();
                        }
                    });
                    pnButtons.add(btCancel);

                }
            }
            {
                pnHelp = new JPanel();
                FlowLayout pnHelpLayout = new FlowLayout();
                pnHelpLayout.setAlignment(FlowLayout.RIGHT);
                pnHelp.setLayout(pnHelpLayout);
                getContentPane().add(pnHelp, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                {
                    btHelp = new JButton(Messages.getMessage(getLocale(), "$MD11787"),
                            IconRegistry.getIcon("help.png"));
                    pnHelp.add(btHelp);
                    btHelp.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            HelpFrame hf = HelpFrame.getInstance(new HelpManager(appContainer));
                            hf.setVisible(true);
                            hf.gotoModule("Print");
                        }
                    });
                }
            }
            {
                pnPrint = new JPanel();
                GridBagLayout pnPrintLayout = new GridBagLayout();
                getContentPane().add(pnPrint, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                pnPrint.setBorder(
                        BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11788")));
                pnPrintLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.1 };
                pnPrintLayout.rowHeights = new int[] { 78, 111, 126, 65, 60, 7 };
                pnPrintLayout.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.1 };
                pnPrintLayout.columnWidths = new int[] { 117, 158, 151, 7 };
                pnPrint.setLayout(pnPrintLayout);
                {
                    pnPreview = new PreviewPanel();
                    pnPreview.setLayout(new BorderLayout());
                    pnPrint.add(pnPreview, new GridBagConstraints(0, 0, 2, 3, 0.0, 0.0,
                            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnPreview.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11789")));
                    {
                        lbPageSize = new JLabel();
                        pnPreview.add(lbPageSize, BorderLayout.SOUTH);
                        lbPageSize.setText(Messages.getMessage(getLocale(), "$MD11790"));
                    }
                }
                {
                    pnFile = new JPanel();
                    FlowLayout pnFileLayout = new FlowLayout();
                    pnFileLayout.setAlignment(FlowLayout.LEFT);
                    pnFile.setLayout(pnFileLayout);
                    pnPrint.add(pnFile, new GridBagConstraints(0, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnFile.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11791")));
                    {
                        btLoad = new JButton(Messages.getMessage(getLocale(), "$MD11792"),
                                IconRegistry.getIcon("open.gif"));
                        pnFile.add(btLoad);
                        btLoad.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent event) {
                                doLoadSettings();
                            }
                        });
                    }
                    {
                        btSave = new JButton(Messages.getMessage(getLocale(), "$MD11793"),
                                IconRegistry.getIcon("save.gif"));
                        pnFile.add(btSave);
                        btSave.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent event) {
                                doSaveSettings();
                            }
                        });
                    }
                }
                {
                    pnLayoutPosition = new JPanel();
                    GridBagLayout pnLayoutPositionLayout = new GridBagLayout();
                    pnLayoutPositionLayout.rowWeights = new double[] { 0.0, 0.1, 0.1, 0.1 };
                    pnLayoutPositionLayout.rowHeights = new int[] { 39, 7, 7, 7 };
                    pnLayoutPositionLayout.columnWeights = new double[] { 0.0, 0.0, 0.1 };
                    pnLayoutPositionLayout.columnWidths = new int[] { 69, 95, 7 };
                    pnLayoutPosition.setLayout(pnLayoutPositionLayout);
                    pnPrint.add(pnLayoutPosition, new GridBagConstraints(2, 0, 2, 2, 0.0, 0.0,
                            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnLayoutPosition.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11848")));
                    {
                        lb1 = new JLabel(Messages.getMessage(getLocale(), "$MD11794"));
                        pnLayoutPosition.add(lb1,
                                new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lb2 = new JLabel(Messages.getMessage(getLocale(), "$MD11794"));
                        pnLayoutPosition.add(lb2,
                                new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lb3 = new JLabel(Messages.getMessage(getLocale(), "$MD11794"));
                        pnLayoutPosition.add(lb3,
                                new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lb4 = new JLabel(Messages.getMessage(getLocale(), "$MD11794"));
                        pnLayoutPosition.add(lb4,
                                new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        spLeft = new JSpinner(new SpinnerNumberModel(20, 0, 100000, 1));
                        pnLayoutPosition.add(spLeft,
                                new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
                        spLeft.addChangeListener(printSizeListener);
                    }
                    {
                        spTop = new JSpinner(new SpinnerNumberModel(20, 0, 100000, 1));
                        pnLayoutPosition.add(spTop,
                                new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
                        spTop.addChangeListener(printSizeListener);
                    }
                    {
                        spWidth = new JSpinner(new SpinnerNumberModel(150, 10, 100000, 1));
                        pnLayoutPosition.add(spWidth,
                                new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
                        spWidth.addChangeListener(printSizeListener);
                    }
                    {
                        spHeight = new JSpinner(new SpinnerNumberModel(200, 10, 100000, 1));
                        pnLayoutPosition.add(spHeight,
                                new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
                        spHeight.addChangeListener(printSizeListener);
                    }
                    {
                        lbLeft = new JLabel(Messages.getMessage(getLocale(), "$MD11795"));
                        pnLayoutPosition.add(lbLeft,
                                new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lbTop = new JLabel(Messages.getMessage(getLocale(), "$MD11796"));
                        pnLayoutPosition.add(lbTop,
                                new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lbWidth = new JLabel(Messages.getMessage(getLocale(), "$MD11797"));
                        pnLayoutPosition.add(lbWidth,
                                new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lbHeight = new JLabel(Messages.getMessage(getLocale(), "$MD11798"));
                        pnLayoutPosition.add(lbHeight,
                                new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                }
                {
                    pnMapCoord = new JPanel();
                    GridBagLayout pnMapCoordLayout = new GridBagLayout();
                    pnPrint.add(pnMapCoord, new GridBagConstraints(2, 2, 2, 1, 0.0, 0.0,
                            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnMapCoord.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11799")));
                    pnMapCoordLayout.rowWeights = new double[] { 0.1, 0.1 };
                    pnMapCoordLayout.rowHeights = new int[] { 7, 7 };
                    pnMapCoordLayout.columnWeights = new double[] { 0.0, 0.1, 0.1 };
                    pnMapCoordLayout.columnWidths = new int[] { 68, 7, 7 };
                    pnMapCoord.setLayout(pnMapCoordLayout);
                    {
                        lbMapLeft = new JLabel(Messages.getMessage(getLocale(), "$MD11800"));
                        pnMapCoord.add(lbMapLeft,
                                new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lbMapBottom = new JLabel(Messages.getMessage(getLocale(), "$MD11801"));
                        pnMapCoord.add(lbMapBottom,
                                new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        spMapLeft = new JSpinner(new SpinnerNumberModel(0, -9E9, 9E9, 0.5));
                        spMapLeft.setValue(mapModel.getEnvelope().getMin().getX());
                        pnMapCoord.add(spMapLeft,
                                new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 9), 0, 0));
                        spMapLeft.addChangeListener(printSizeListener);
                    }
                    {
                        spMapBottom = new JSpinner(new SpinnerNumberModel(0, -9E9, 9E9, 0.5));
                        spMapBottom.setValue(mapModel.getEnvelope().getMin().getY());
                        pnMapCoord.add(spMapBottom,
                                new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 9), 0, 0));
                        spMapBottom.addChangeListener(printSizeListener);
                    }
                }
                {
                    pnScale = new JPanel();
                    GridBagLayout pnScaleLayout = new GridBagLayout();
                    pnPrint.add(pnScale, new GridBagConstraints(2, 3, 2, 2, 0.0, 0.0, GridBagConstraints.CENTER,
                            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnScale.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11802")));
                    pnScaleLayout.rowWeights = new double[] { 0.1, 0.1 };
                    pnScaleLayout.rowHeights = new int[] { 7, 7 };
                    pnScaleLayout.columnWeights = new double[] { 0.1, 0.1 };
                    pnScaleLayout.columnWidths = new int[] { 7, 7 };
                    pnScale.setLayout(pnScaleLayout);
                    {
                        rbConst = new JRadioButton(Messages.getMessage(getLocale(), "$MD11803"));
                        pnScale.add(rbConst,
                                new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                        rbConst.setSelected(true);
                        bg.add(rbConst);
                    }
                    {
                        rbVariable = new JRadioButton(Messages.getMessage(getLocale(), "$MD11804"));
                        pnScale.add(rbVariable,
                                new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                        bg.add(rbVariable);
                    }
                    {
                        int[] sc = StringTools.toArrayInt(Messages.getMessage(getLocale(), "$MD11805"), ",; ");
                        ListEntry[] le = new ListEntry[sc.length];
                        for (int i = 0; i < sc.length; i++) {
                            le[i] = new ListEntry("1:" + sc[i], sc[i]);
                        }
                        cbScale = new JComboBox(new DefaultComboBoxModel(le));
                        cbScale.setSelectedIndex(6);
                        pnScale.add(cbScale,
                                new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 9), 0, 0));
                        cbScale.setEditable(true);
                        cbScale.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                Object o = cbScale.getSelectedItem();
                                if (o instanceof String) {
                                    try {
                                        // handle use defined scales
                                        ListEntry le = null;
                                        if (((String) o).indexOf(":") > 0) {
                                            String[] t = StringTools.toArray((String) o, ":", false);
                                            le = new ListEntry((String) o, Integer.parseInt(t[1].trim()));
                                        } else {
                                            le = new ListEntry("1:" + o, Integer.parseInt((String) o));
                                        }
                                        ((DefaultComboBoxModel) cbScale.getModel()).addElement(le);
                                        cbScale.setSelectedItem(le);
                                    } catch (Exception ex) {
                                        DialogFactory.openWarningDialog(appContainer.getViewPlatform(),
                                                VectorPrintDialog.this, Messages.get("$MD11821"),
                                                Messages.get("$MD11822"));
                                        return;
                                    }
                                }
                                updatePreview();
                            }
                        });
                    }
                }
                {
                    pnFormat = new JPanel();
                    GridBagLayout pnFormatLayout = new GridBagLayout();
                    pnPrint.add(pnFormat, new GridBagConstraints(0, 3, 2, 1, 0.0, 0.0,
                            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnFormat.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11806")));
                    pnFormatLayout.rowWeights = new double[] { 0.1 };
                    pnFormatLayout.rowHeights = new int[] { 7 };
                    pnFormatLayout.columnWeights = new double[] { 0.1 };
                    pnFormatLayout.columnWidths = new int[] { 7 };
                    pnFormat.setLayout(pnFormatLayout);
                    {
                        String[] tmp = StringTools.toArray(Messages.getMessage(getLocale(), "$MD11807"), ",;",
                                true);
                        ListEntry[] le = new ListEntry[tmp.length / 2 + 1];
                        le[0] = new ListEntry(Messages.getMessage(getLocale(), "$MD11829"), null);
                        for (int i = 0; i < tmp.length; i += 2) {
                            le[i / 2 + 1] = new ListEntry(tmp[i], tmp[i + 1]);
                        }
                        cbPageFormat = new JComboBox(new DefaultComboBoxModel(le));
                        cbPageFormat.setSelectedIndex(2);

                        pnFormat.add(cbPageFormat,
                                new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 9), 0, 0));

                        // width
                        lbPageWidth = new JLabel(Messages.getMessage(getLocale(), "$MD11831"));
                        pnFormat.add(lbPageWidth,
                                new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 15, 0, 0), 0, 0));
                        tfPageWidth = new JSpinner(
                                new SpinnerNumberModel(inMM(PageSize.A4.getWidth()), 0, 6080, 1));
                        pnFormat.add(tfPageWidth,
                                new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));

                        tfPageWidth.setEnabled(false);
                        lbPageUnitW = new JLabel(Messages.getMessage(getLocale(), "$MD11832"));
                        pnFormat.add(lbPageUnitW,
                                new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 15), 0, 0));

                        // height
                        lbPageHeight = new JLabel(Messages.getMessage(getLocale(), "$MD11830"));
                        pnFormat.add(lbPageHeight,
                                new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 15, 0, 0), 0, 0));
                        tfPageHeight = new JSpinner(
                                new SpinnerNumberModel(inMM(PageSize.A4.getHeight()), 0, 6080, 1));
                        pnFormat.add(tfPageHeight,
                                new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
                        tfPageHeight.setEnabled(false);
                        lbPageUnitH = new JLabel(Messages.getMessage(getLocale(), "$MD11832"));
                        pnFormat.add(lbPageUnitH,
                                new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 15), 0, 0));

                        cbPageFormat.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {

                                int width;
                                int height;
                                ListEntry le = (ListEntry) ((JComboBox) e.getSource()).getSelectedItem();
                                if (le.value != null) {
                                    String value = (String) le.value;
                                    Rectangle rect = PageSize.getRectangle(value);
                                    width = (int) Math.round(rect.getWidth() / 72 * 25.4);
                                    height = (int) Math.round(rect.getHeight() / 72 * 25.4);
                                    tfPageWidth.setEnabled(false);
                                    tfPageHeight.setEnabled(false);
                                } else {
                                    tfPageWidth.setEnabled(true);
                                    tfPageHeight.setEnabled(true);
                                    width = ((Number) tfPageWidth.getValue()).intValue();
                                    height = ((Number) tfPageHeight.getValue()).intValue();
                                }
                                // if page format has been changed max size of printed map must be changed
                                // for new map size (millimeter) left and top border must be considered to
                                // ensure that printed map does not overlap paper at the right and at the bottom

                                width -= (((Number) spLeft.getValue()).intValue() * 2);
                                height -= (((Number) spTop.getValue()).intValue() * 2);
                                spWidth.setValue(width);
                                spHeight.setValue(height);
                                // preview of printed area must be updated
                                updatePreview();
                            }
                        });
                    }
                }
                {
                    pnDPI = new JPanel();
                    GridBagLayout pnDPILayout = new GridBagLayout();
                    pnPrint.add(pnDPI, new GridBagConstraints(0, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnDPI.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11808")));
                    pnDPILayout.rowWeights = new double[] { 0.1 };
                    pnDPILayout.rowHeights = new int[] { 7 };
                    pnDPILayout.columnWeights = new double[] { 0.1 };
                    pnDPILayout.columnWidths = new int[] { 7 };
                    pnDPI.setLayout(pnDPILayout);
                    {
                        final DefaultComboBoxModel cbDPIModel = new DefaultComboBoxModel(
                                new Integer[] { 72, 96, 150, 300, 600, 1200, 2400 });
                        cbDPI = new JComboBox();
                        pnDPI.add(cbDPI, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 9), 0, 0));
                        cbDPI.setModel(cbDPIModel);
                        cbDPI.setEditable(true);
                        cbDPI.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                Object o = cbDPI.getSelectedItem();
                                if (o instanceof String) {
                                    try {
                                        Integer i = Integer.parseInt(o.toString());
                                        cbDPIModel.addElement(i);
                                        cbDPI.setSelectedItem(i);
                                    } catch (Exception ex) {
                                        DialogFactory.openWarningDialog(appContainer.getViewPlatform(),
                                                VectorPrintDialog.this, Messages.get("$MD11819"),
                                                Messages.get("$MD11820"));
                                    }
                                }
                            }
                        });
                    }
                }
                {
                    pnOutput = new JPanel();
                    GridBagLayout pnOutputLayout = new GridBagLayout();
                    pnOutputLayout.rowWeights = new double[] { 0.1 };
                    pnOutputLayout.rowHeights = new int[] { 7 };
                    pnOutputLayout.columnWeights = new double[] { 0.1, 0.0, 0.1 };
                    pnOutputLayout.columnWidths = new int[] { 7, 94, 7 };
                    pnOutput.setLayout(pnOutputLayout);
                    pnPrint.add(pnOutput, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0,
                            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnOutput.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11809")));
                    {
                        btOutputFile = new JButton(Messages.get("$MD11823"));
                        btOutputFile.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                Preferences prefs = Preferences.userNodeForPackage(VectorPrintDialog.class);
                                File file = GenericFileChooser.showSaveDialog(FILECHOOSERTYPE.externalResource,
                                        appContainer, VectorPrintDialog.this, prefs, "print definition",
                                        IGeoFileFilter.PDF);
                                tfOutputFile.setText(file.getAbsolutePath());
                            }
                        });
                        pnOutput.add(btOutputFile,
                                new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 9), 0, 0));
                    }
                    {
                        tfOutputFile = new JTextField();
                        pnOutput.add(tfOutputFile,
                                new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                }
            }
        }
        pnPreview.setAreaLeft(((Number) spLeft.getValue()).intValue());
        pnPreview.setAreaTop(((Number) spTop.getValue()).intValue());
        pnPreview.setAreaWidth(((Number) spWidth.getValue()).intValue());
        pnPreview.setAreaHeight(((Number) spHeight.getValue()).intValue());
        Rectangle rect;
        ListEntry le = (ListEntry) cbPageFormat.getSelectedItem();
        if (le.value != null) {
            rect = PageSize.getRectangle((String) le.value);
        } else {
            rect = new Rectangle(inPt(((Number) tfPageWidth.getValue()).intValue()),
                    inPt(((Number) tfPageHeight.getValue()).intValue()));
        }
        pnPreview.setPageSize(rect);
        this.setBounds(300, 200, 530, 609);
    } catch (Exception e) {
        e.printStackTrace();
    }

    DefaultMapModule<Container> mapModule = getAssignedMapModule();
    final Container jco = mapModule.getMapContainer();
    jco.addMouseListener(ml);
    jco.addMouseMotionListener(mml);
    isActive = true;
    final MapTool<Container> mapTool = mapModule.getMapTool();
    mapTool.addChangeListener(this);

    addWindowFocusListener(new WindowFocusListener() {

        @Override
        public void windowLostFocus(WindowEvent e) {
        }

        @Override
        public void windowGainedFocus(WindowEvent e) {
            mapTool.resetState();
            // it is required to add the listeners again, cause it seems some other module removes all...
            jco.addMouseListener(ml);
            jco.addMouseMotionListener(mml);
            isActive = true;
        }
    });
}

From source file:org.displaytag.export.DefaultItextExportView.java

License:Artistic License

/**
 * @see org.displaytag.export.BinaryExportView#doExport(OutputStream)
 *//*w ww. ja v a  2  s.  co m*/
public void doExport(OutputStream out) throws JspException {
    try {
        Document document = new Document(PageSize.A4.rotate(), 60, 60, 40, 40);
        this.initItextWriter(document, out);
        document.open();
        Table table = new Table(this.model.getNumberOfColumns());
        ItextTableWriter writer = new ItextTableWriter(table, document);
        writer.writeTable(this.model, "-1");
        document.add(table);
        document.close();
    } catch (Exception e) {
        throw new ItextGenerationException(e);
    }
}

From source file:org.displaytag.export.PdfView.java

License:Artistic License

/**
 * @see org.displaytag.export.BinaryExportView#doExport(OutputStream)
 */// w  w w .j  av  a2 s.c  o m
public void doExport(OutputStream out) throws JspException {
    try {
        // Initialize the table with the appropriate number of columns
        initTable();

        // Initialize the Document and register it with PdfWriter listener and the OutputStream
        Document document = new Document(PageSize.A4.rotate(), 60, 60, 40, 40);
        document.addCreationDate();
        HeaderFooter footer = new HeaderFooter(new Phrase(TagConstants.EMPTY_STRING, smallFont), true);
        footer.setBorder(Rectangle.NO_BORDER);
        footer.setAlignment(Element.ALIGN_CENTER);

        PdfWriter.getInstance(document, out);

        // Fill the virtual PDF table with the necessary data
        generatePDFTable();
        document.open();
        document.setFooter(footer);
        document.add(this.tablePDF);
        document.close();

    } catch (Exception e) {
        throw new PdfGenerationException(e);
    }
}

From source file:org.egomez.irpgeditor.swing.PanelSpoolFiles.java

License:Open Source License

@Override
public void run() {
    synchronized (this) {
        try {/*from   w w w  .  ja  v  a2  s .  c  o  m*/
            localPrintStream = new PrintStream(target);

            switch (exportType) {
            case SPOOL_EXPORT_TEXT:
                break;
            case SPOOL_EXPORT_PDF:
                document = new Document(PageSize.A4);
                PdfWriter.getInstance(document, localPrintStream);
                document.open();
                break;
            }

            PrintParameterList localPrintParameterList = new PrintParameterList();
            localPrintParameterList.setParameter(PrintObject.ATTR_WORKSTATION_CUST_OBJECT,
                    "/QSYS.LIB/QWPDEFAULT.WSCST");
            localPrintParameterList.setParameter(PrintObject.ATTR_MFGTYPE, "*WSCST");
            localPrintParameterList.setParameter(PrintObject.ATTR_CODEPAGE, 284);
            PrintObjectTransformedInputStream localPrintObjectTransformedInputStream = file
                    .getTransformedInputStream(localPrintParameterList);
            byte[] buf = new byte[32767];
            StringBuffer buffer = new StringBuffer();
            int bytesRead = 0;
            do {
                bytesRead = localPrintObjectTransformedInputStream.read(buf);
                // System.out.println(bytesRead);
                if (bytesRead > 0) {
                    buffer.append(new String(buf, 0, bytesRead, "cp437"));
                }
            } while (bytesRead != -1);

            String cadena = buffer.toString();
            cadena = cadena.replace('\r', ' ');
            switch (exportType) {
            case SPOOL_EXPORT_TEXT:
                if (buffer.length() > 0)
                    localPrintStream.println(cadena.toCharArray());
                localPrintStream.flush();
                localPrintStream.close();
                break;
            case SPOOL_EXPORT_PDF:
                Paragraph p = new Paragraph(cadena,
                        FontFactory.getFont(FontFactory.COURIER, 6, com.lowagie.text.Font.NORMAL));
                // p.setFont(courierFont);
                if (buffer.length() > 0) {
                    document.add(p);
                }

                document.close();
                document = null;
                break;
            }

            JOptionPane.showMessageDialog(null, "File " + target.getAbsolutePath() + " was saved.");

        } catch (FileNotFoundException e) {
            // e.printStackTrace();
            logger.error(e.getMessage());
        } catch (IOException e) {
            logger.error(e.getMessage());
        } catch (AS400Exception e) {
            logger.error(e.getMessage());
        } catch (AS400SecurityException e) {
            logger.error(e.getMessage());
        } catch (ErrorCompletingRequestException e) {
            // e.printStackTrace();
            logger.error(e.getMessage());
        } catch (InterruptedException e) {
            // e.printStackTrace();
            logger.error(e.getMessage());
        } catch (RequestNotSupportedException e) {
            // e.printStackTrace();
            logger.error(e.getMessage());
        } catch (DocumentException e) {
            // e.printStackTrace();
            logger.error(e.getMessage());
        }
    }
}

From source file:org.egov.infra.web.displaytag.export.EGovPdfView.java

License:Open Source License

@Override
public void doExport(final OutputStream out) throws JspException {

    try {/* w w  w.  ja  v a2s.co m*/
        // Initialize the table with the appropriate number of columns
        initTable();

        // Initialize the Document and register it with PdfWriter listener and the OutputStream
        final Document document = new Document(PageSize.A4.rotate(), 60, 60, 40, 40);
        document.addCreationDate();
        final HeaderFooter footer = new HeaderFooter(new Phrase(TagConstants.TAGNAME_CAPTION, this.smallFont),
                true);
        footer.setBorder(Rectangle.NO_BORDER);
        footer.setAlignment(Element.ALIGN_CENTER);

        // PdfWriter.getInstance(document, out);
        PdfWriter.getInstance(document, out).setPageEvent(new PageNumber());
        // Fill the virtual PDF table with the necessary data
        generatePDFTable();
        document.open();

        // Table table = new Table(this.model.getNumberOfColumns());
        // ItextTableWriter writer = new ItextTableWriter(tablePDF, document);
        // writer.writeTable(this.model, "-1");
        // document.setFooter(footer);
        // document.setHeader(footer);
        document.add(this.tableCaption);
        document.add(this.tablePDF);
        document.close();

    } catch (final Exception e) {

        throw new PdfGenerationException(e);
    }

}