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:net.bull.javamelody.swing.print.MPdfWriter.java

License:Apache License

/**
 * Ecrit le pdf./*from   w  ww. j  a v a  2 s .c  o m*/
 *
 * @param table
 *           MBasicTable
 * @param out
 *           OutputStream
 * @throws IOException
 *            e
 */
protected void writePdf(final MBasicTable table, final OutputStream out) throws IOException {
    try {
        // step 1: creation of a document-object
        final Rectangle pageSize = landscape ? PageSize.A4.rotate() : PageSize.A4;
        final Document document = new Document(pageSize, 50, 50, 50, 50);
        // step 2: we create a writer that listens to the document and directs a PDF-stream to out
        createWriter(table, document, out);

        // we add some meta information to the document, and we open it
        document.addAuthor(System.getProperty("user.name"));
        document.addCreator("JavaMelody");
        final String title = buildTitle(table);
        if (title != null) {
            document.addTitle(title);
        }
        document.open();

        // ouvre la bote de dialogue Imprimer de Adobe Reader
        // if (writer instanceof PdfWriter) {
        // ((PdfWriter) writer).addJavaScript("this.print(true);", false);
        // }

        // table
        final Table datatable = new Table(table.getColumnCount());
        datatable.setCellsFitPage(true);
        datatable.setPadding(4);
        datatable.setSpacing(0);

        // headers
        renderHeaders(table, datatable);

        // data rows
        renderList(table, datatable);

        document.add(datatable);

        // we close the document
        document.close();
    } catch (final DocumentException e) {
        // on ne peut dclarer d'exception autre que IOException en throws
        throw new IOException(e);
    }
}

From source file:net.mitnet.tools.pdf.book.pdf.util.PdfPageSizeHelper.java

License:Open Source License

/**
 * Returns the default page size for the current locale.
 * //from w  w w .j  a va 2s  .com
 * eg. 
 * "en_AU" = PageSize.A4
  * "en_US" = PageSize.LETTER
 */
public static final Rectangle getDefaultPageSizeByLocale() {

    Rectangle pageSize = PageSize.A4;

    Locale locale = Locale.getDefault();
    if (locale != null) {
        pageSize = getDefaultPageSizeByLocale(locale);
    }

    return pageSize;
}

From source file:net.mitnet.tools.pdf.book.publisher.BookPublisher.java

License:Open Source License

public BookPublisher() {
    getConfig().setServerContext(new OpenOfficeServerContext());
    getConfig().setPageSize(PageSize.A4);
}

From source file:net.refractions.udig.printing.ui.internal.template.A4LandscapeTemplate.java

License:Open Source License

protected Rectangle getPaperSize() {
    Rectangle a4 = PageSize.A4;
    Rectangle a4Landscape = new Rectangle(0f, 0f, a4.getHeight(), a4.getWidth());
    return a4Landscape;
}

From source file:net.refractions.udig.printing.ui.internal.template.A4PortraitTemplate.java

License:Open Source License

protected Rectangle getPaperSize() {
    Rectangle a4 = PageSize.A4;
    return a4;
}

From source file:net.refractions.udig.printing.ui.internal.template.AbstractPrinterPageTemplate.java

License:Open Source License

/**
 * Populates the templates two boxes with a title and map
 * /*from www. j  a  v a  2s.co m*/
 * @param page the parent(owner) page
 * @param map the Map to be drawn
 */
public void init(Page page, Map map) {
    this.page = page;
    com.lowagie.text.Rectangle paperRectangle = getPaperSize();
    Dimension paperSize = new Dimension((int) paperRectangle.getWidth(), (int) paperRectangle.getHeight());
    // set the requested papersize
    page.setPaperSize(paperSize);
    // then apply the ratio of the papersize also to the page size.
    setPageSizeFromPaperSize(page, paperSize);

    float scaleFactor = (float) page.getSize().width / (float) page.getPaperSize().height;

    int height = page.getSize().height;
    int width = page.getSize().width;

    int xPos = getPercentagePieceOf(width, LEFT_MARGIN_PERCENT);
    int yPos = getPercentagePieceOf(height, UPPER_MARGIN_PERCENT);
    int w = getPercentagePieceOf(width, TITLE_WIDTH_PERCENT);
    int h = getPercentagePieceOf(height, TITLE_HEIGHT_PERCENT);
    // the base font size is good for the A4 size, scale every other proportional
    float scaledSize = (float) BASEFONT_SIZE * (float) paperSize.height / PageSize.A4.getHeight();
    // float scaledFontSize = scaleValue(page, paperSize, scaledSize);
    addLabelBox(formatName(map.getName()), xPos, yPos, w, h, (int) scaledSize, scaleFactor);

    xPos = getPercentagePieceOf(width, LEFT_MARGIN_PERCENT);
    yPos = getPercentagePieceOf(height, UPPER_MARGIN_PERCENT + TITLE_HEIGHT_PERCENT);
    w = getPercentagePieceOf(width, MAP_WIDTH_PERCENT);
    h = getPercentagePieceOf(height, MAP_HEIGHT_PERCENT);
    addMapBox(map, xPos, yPos, w, h, paperSize);

    // xPos = getPercentagePieceOf(width, 100f - RIGHT_MARGIN_PERCENT - SPACING_PERCENT * 3f
    // - LEGEND_WIDTH_PERCENT);
    // yPos = getPercentagePieceOf(height, 100f - BOTTOM_MARGIN_PERCENT - SPACING_PERCENT * 3f
    // - LEGEND_HEIGHT_PERCENT);
    // w = getPercentagePieceOf(width, LEGEND_WIDTH_PERCENT);
    // h = getPercentagePieceOf(height, LEGEND_HEIGHT_PERCENT);
    // addLegendBox(xPos, yPos, w, h);

    xPos = getPercentagePieceOf(width, LEFT_MARGIN_PERCENT + SPACING_PERCENT * 2f);
    yPos = getPercentagePieceOf(height,
            100f - BOTTOM_MARGIN_PERCENT - SPACING_PERCENT * 3f - SCALE_HEIGHT_PERCENT);
    w = getPercentagePieceOf(width, SCALE_WIDTH_PERCENT);
    h = getPercentagePieceOf(height, SCALE_HEIGHT_PERCENT);
    addScale(xPos, yPos, w, h);
}

From source file:net.sf.firemox.deckbuilder.BuildBook.java

License:Open Source License

/**
 * // www .  j  a  v a  2s  .  co  m
 */
@SuppressWarnings("unchecked")
public void build() {
    BufferedReader in = null;
    try {
        in = new BufferedReader(new InputStreamReader(new FileInputStream(MToolKit.getFile(checklist)),
                Charset.forName("ISO-8859-1")));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return;
    }
    // String charset = Charset.forName("ISO-8859-1").name();
    String line = null;
    int cur = 0;
    int row = 0;
    PdfPCell[] cells = new PdfPCell[3];
    PdfPTable table = new PdfPTable(3);
    Document document = new Document(PageSize.A4);
    try {
        PdfWriter.getInstance(document, new FileOutputStream(this.pdfBook));
        document.open();
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }

    try {
        in.readLine(); // Removing header line
        String[] tokens = new String[] { "\t", "\\s{2,}" };
        while ((line = in.readLine()) != null) {
            // line = new String(line.getBytes(),charset);
            // Card# Card Name Artist Color Rarity
            String[] fields = null;
            for (String token : tokens) {
                fields = line.split(token);
                if (fields.length == 5) {
                    break;
                }
            }

            if (fields == null || fields.length < 5) {
                System.err.println("Unable to parse " + line);
                continue;
            } else if (fields.length > 5) {
                System.out.println("Too many value found on " + line);
            }
            fields[1] = fields[1].trim();
            fields[1] = fields[1].replaceAll("[ -]", "_");
            fields[1] = fields[1].replaceAll("[/',\\u0092]", "");
            fields[1] = fields[1].replaceAll("", "AE");
            System.out.println("Inserting " + fields[1]);
            if (basicLands.containsKey(fields[1])) {
                int x = basicLands.get(fields[1]);
                cells[cur] = new PdfPCell(getImage(fields[1] + x), true);
                x++;
                basicLands.put(fields[1], x);
            } else {
                cells[cur] = new PdfPCell(getImage(fields[1]), true);
            }
            cur++;
            if (cur == 3) {
                for (int j = 0; j < cells.length; j++) {
                    cells[j].setPadding(2.0f);
                }
                table.getRows().add(new PdfPRow(cells));
                row++;
                cur = 0;
                cells = new PdfPCell[3];
            }
            if (row == 3) {
                table.setWidthPercentage(100);
                document.add(table);
                table = new PdfPTable(3);
                row = 0;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.close();
}

From source file:open.dolphin.client.AuditController.java

License:Open Source License

private void makePDF() {

    //- ?/*from  w  w w .  ja va 2  s. c  o m*/
    Document doc = new Document(PageSize.A4, 20.0F, 20.0F, 40.0F, 40.0F);

    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String fileName = "_" + sdf.format(new java.util.Date()) + ".pdf";

        //()??
        FileOutputStream fos = new FileOutputStream(outputDir.getText() + fileName);
        PdfWriter pdfwriter = PdfWriter.getInstance(doc, fos);
        Font font_header = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 15.0F, 1);
        Font font_g11 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 11.0F);
        Font font_g10 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 10.0F);
        //- ?
        Font font_m8 = new Font(BaseFont.createFont("HeiseiMin-W3", "UniJIS-UCS2-HW-H", false), 8.0F);
        Font font_underline_11 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 11.0F,
                4);
        Font font_red_11 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 11.0F);
        font_red_11.setColor(new Color(255, 0, 0));
        Font font_empty = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 9.0F);
        font_empty.setColor(new Color(255, 255, 255));

        Paragraph para_NF = new Paragraph(5, "\r\n",
                new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 13, Font.NORMAL));
        para_NF.setAlignment(Element.ALIGN_CENTER);

        // ??
        String author = Project.getProjectStub().getUserModel().getCommonName();
        doc.addAuthor(author);
        doc.addSubject("");

        HeaderFooter header = new HeaderFooter(new Phrase("", font_header),
                false);
        header.setAlignment(1);
        doc.setHeader(header);

        HeaderFooter footer = new HeaderFooter(new Phrase("--"), new Phrase("--"));
        footer.setAlignment(1);
        footer.setBorder(0);
        doc.setFooter(footer);

        doc.open();

        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy''MM''dd'' HH''mm''");
        String today = sdf1.format(new java.util.Date());
        Paragraph para_0 = new Paragraph("?" + today, font_g11);
        para_0.setAlignment(2);
        doc.add(para_0);
        Paragraph para_1 = new Paragraph("?" + author, font_g11);
        para_1.setAlignment(2);
        doc.add(para_1);
        doc.add(new Paragraph(""));
        // 
        doc.add(para_NF);
        doc.add(para_NF);

        for (int cnt = 0; cnt < outputList.size(); cnt++) {

            InnerBean bean = outputList.get(cnt);
            Person person = bean.getPerson();

            Paragraph para_2 = new Paragraph("ID" + person.idProperty().get(), font_underline_11);
            para_2.setAlignment(0);
            doc.add(para_2);
            Paragraph para_3 = new Paragraph("???" + person.nameProperty().get(),
                    font_underline_11);
            para_3.setAlignment(0);
            doc.add(para_3);
            Paragraph para_4 = new Paragraph("" + person.nameKanaProperty().get(),
                    font_underline_11);
            para_4.setAlignment(0);
            doc.add(para_4);
            Paragraph para_5 = new Paragraph("" + person.sexProperty().get(), font_underline_11);
            para_5.setAlignment(0);
            doc.add(para_5);
            Paragraph para_6 = new Paragraph("" + person.birthdayProperty().get(),
                    font_underline_11);
            para_6.setAlignment(0);
            doc.add(para_6);

            Table karteHistoryTable = new Table(5);
            karteHistoryTable.setWidth(100.0F);
            int[] uriage_table_width = { 25, 20, 30, 20, 25 };
            karteHistoryTable.setWidths(uriage_table_width);
            //karteHistoryTable.setDefaultHorizontalAlignment(1);
            //karteHistoryTable.setDefaultVerticalAlignment(5);
            karteHistoryTable.setPadding(3.0F);
            karteHistoryTable.setSpacing(0.0F);
            karteHistoryTable.setBorderColor(new Color(0, 0, 0));

            Cell cell_01 = new Cell(new Phrase("?", font_g10));
            cell_01.setGrayFill(0.8F);
            cell_01.setHorizontalAlignment(Element.ALIGN_CENTER);
            Cell cell_11 = new Cell(new Phrase("?", font_g10));
            cell_11.setGrayFill(0.8F);
            cell_11.setHorizontalAlignment(Element.ALIGN_CENTER);
            Cell cell_21 = new Cell(new Phrase("", font_g10));
            cell_21.setGrayFill(0.8F);
            cell_21.setHorizontalAlignment(Element.ALIGN_CENTER);
            Cell cell_31 = new Cell(new Phrase("", font_g10));
            cell_31.setGrayFill(0.8F);
            cell_31.setHorizontalAlignment(Element.ALIGN_CENTER);
            Cell cell_41 = new Cell(new Phrase("", font_g10));
            cell_41.setGrayFill(0.8F);
            cell_41.setHorizontalAlignment(Element.ALIGN_CENTER);

            karteHistoryTable.addCell(cell_01);
            karteHistoryTable.addCell(cell_11);
            karteHistoryTable.addCell(cell_21);
            karteHistoryTable.addCell(cell_31);
            karteHistoryTable.addCell(cell_41);

            List<KarteBean> list = bean.getResult();
            KarteBean karteInfo = list.get(0);
            List<DocInfoModel> docInfoList = karteInfo.getDocInfoList();

            //- ???
            int stepCount = 22;
            int tempCount = 0;
            int pageCount = 0;

            String firstKarteMaker = null;
            String karteMakeDate = null;
            if (docInfoList != null) {
                for (int i = 0; i < docInfoList.size(); ++i) {
                    DocInfoModel docInfo = docInfoList.get(i);
                    Cell cell = new Cell(new Phrase(docInfo.getFirstConfirmDateTime(), font_m8));
                    if (karteMakeDate == null || !karteMakeDate.equals(docInfo.getFirstConfirmDateTime())) {
                        karteMakeDate = docInfo.getFirstConfirmDateTime();
                        firstKarteMaker = docInfo.getPurpose();
                    }
                    cell.setHorizontalAlignment(0);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    karteHistoryTable.addCell(cell);
                    cell = new Cell(new Phrase(firstKarteMaker, font_m8));
                    cell.setHorizontalAlignment(0);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    karteHistoryTable.addCell(cell);
                    //- 
                    String addTitle = docInfo.getTitle();
                    addTitle = addTitle.replace("\r\n", "");
                    addTitle = addTitle.replace("\n", "");
                    cell = new Cell(new Phrase(addTitle, font_m8));
                    cell.setHorizontalAlignment(0);
                    karteHistoryTable.addCell(cell);
                    cell = new Cell(new Phrase(docInfo.getPurpose(), font_m8));
                    cell.setHorizontalAlignment(0);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    karteHistoryTable.addCell(cell);
                    cell = new Cell(new Phrase(docInfo.getConfirmDateTime(), font_m8));
                    cell.setHorizontalAlignment(0);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    karteHistoryTable.addCell(cell);

                    if (stepCount == tempCount) {
                        if (pageCount == 0) {
                            stepCount += 5;
                            pageCount++;
                        }
                        tempCount = 0;
                        doc.add(karteHistoryTable);
                        doc.newPage();
                        karteHistoryTable.deleteAllRows();
                        karteHistoryTable.addCell(cell_01);
                        karteHistoryTable.addCell(cell_11);
                        karteHistoryTable.addCell(cell_21);
                        karteHistoryTable.addCell(cell_31);
                        karteHistoryTable.addCell(cell_41);
                    } else {
                        tempCount++;
                    }
                }

                //                    Cell Empty_Cell = new Cell(new Phrase("empty", font_empty));
                //                    for (int i = docInfoList.size(); i < docInfoList.size() + 4; ++i) {
                //                        for (int j = 0; j < 4; ++j) {
                //                            karteHistoryTable.addCell(Empty_Cell);
                //                        }
                //                    }
                //
                //            Cell cell_goukei = new Cell(new Phrase("?", font_g10));
                //            cell_goukei.setGrayFill(0.8F);
                //            cell_goukei.setColspan(3);
                //            karteHistoryTable.addCell(cell_goukei);
                //            Cell cell_sum = new Cell(new Phrase("136,900", font_m10));
                //            cell_sum.setHorizontalAlignment(2);
                //            karteHistoryTable.addCell(cell_sum);
                doc.add(karteHistoryTable);
                doc.newPage();

            } else {
                // 
                doc.add(para_NF);

                Paragraph noData = new Paragraph("??", font_m8);
                noData.setAlignment(0);
                doc.add(noData);
                doc.newPage();
            }
        }
    } catch (DocumentException | IOException e) {
        Logger.getLogger(AuditController.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        doc.close();
    }
}

From source file:opisiame.controller.gestion_resultat.Choix_exportController.java

@FXML
public void pdf_export() {
    File pdf_file = choix_chemin_enregistrement("PDF files (*.pdf)", "*.pdf");

    if (onglet_actif.equals("questions")) {

        if (pdf_file != null) {
            Document document = new Document(PageSize.A4);
            try {
                PdfWriter.getInstance(document, new FileOutputStream(pdf_file));
                document.open();/*from  w w w .j ava2s .  c  om*/
                document.add(new Paragraph("Rsultat Quiz"));

                Table tableau = new Table(6, reponse_questions.size());
                tableau.setAutoFillEmptyCells(true);
                tableau.setPadding(2);

                Cell cell = new Cell("Question");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage reponse A");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage reponse B");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage reponse C");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage reponse D");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage bonne rponse");
                cell.setHeader(true);
                tableau.addCell(cell);

                tableau.endHeaders();
                tableau.setWidth(100);
                fill_data_pdf(tableau);
                document.add(tableau);
            } catch (DocumentException | IOException de) {
                de.printStackTrace();
            }
            document.close();
        }

    } else if (onglet_actif.equals("eleves")) {

        if (pdf_file != null) {
            Document document = new Document(PageSize.A4);
            try {
                PdfWriter.getInstance(document, new FileOutputStream(pdf_file));
                document.open();
                document.add(new Paragraph("Rsultats des tudiants"));

                Table tableau = new Table(5, resultats_eleves.size());
                tableau.setAutoFillEmptyCells(true);
                tableau.setPadding(2);

                Cell cell = new Cell("Nom");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Prnom");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("N tudiant");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Note");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage");
                cell.setHeader(true);
                tableau.addCell(cell);

                tableau.endHeaders();
                tableau.setWidth(100);
                fill_data_pdf(tableau);
                document.add(tableau);
            } catch (DocumentException | IOException de) {
                de.printStackTrace();
            }
            document.close();
        }
    } else if (onglet_actif.equals("eleves_pas_num")) {

        if (pdf_file != null) {
            Document document = new Document(PageSize.A4);
            try {
                PdfWriter.getInstance(document, new FileOutputStream(pdf_file));
                document.open();
                document.add(new Paragraph("Rsultats des tudiants"));

                Table tableau = new Table(4, resultats_eleves.size());
                tableau.setAutoFillEmptyCells(true);
                tableau.setPadding(2);

                Cell cell = new Cell("Nom");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Prnom");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Note");
                cell.setHeader(true);
                tableau.addCell(cell);

                cell = new Cell("Pourcentage");
                cell.setHeader(true);
                tableau.addCell(cell);

                tableau.endHeaders();
                tableau.setWidth(100);
                fill_data_pdf(tableau);
                document.add(tableau);
            } catch (DocumentException | IOException de) {
                de.printStackTrace();
            }
            document.close();
        }
    }

    close_window();
}

From source file:org.apache.cocoon.serialization.iTextSerializer.java

License:Apache License

private Rectangle getPageSize(final String s) throws ConfigurationException {
    // TC: we could use reflection here instead
    if ("letter".equalsIgnoreCase(s)) {
        return PageSize.LETTER;
    } else if ("a4".equalsIgnoreCase(s)) {
        return PageSize.A4;
    } else if ("a5".equalsIgnoreCase(s)) {
        return PageSize.A5;
    } else {//from   www  . j a v  a 2  s . c o m
        throw new ConfigurationException("page size [" + String.valueOf(s) + "] is not yet recognized");
    }
}