Example usage for com.itextpdf.text PageSize A4

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

Introduction

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

Prototype

Rectangle A4

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

Click Source Link

Document

This is the a4 format

Usage

From source file:org.bonitasoft.studio.migration.utils.PDFMigrationReportWriter.java

License:Open Source License

public void execute(String filePath) {
    try {//from   w  w w .  ja va 2s . co  m
        Document document = new Document(PageSize.A4.rotate(), 5, 5, 10, 10);
        PdfWriter.getInstance(document, new FileOutputStream(filePath));
        document.open();
        addMetaData(document);
        addTitlePage(document);
        addContent(document);
        document.close();
    } catch (Exception e) {
        BonitaStudioLog.error(e);
    }
}

From source file:org.cejug.yougi.event.web.controller.AttendeeMBean.java

License:Open Source License

public void getCertificate() {
    if (this.attendee.getAttended() != null && !this.attendee.getAttended()) {
        return;//from w w w. j  a v  a 2 s.c o  m
    }

    response.setContentType("application/pdf");
    response.setHeader("Content-disposition", "inline=filename=file.pdf");

    try {
        Document document = new Document(PageSize.A4.rotate());
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, output);
        document.open();

        ApplicationProperty fileRepositoryPath = applicationPropertyBean
                .findApplicationProperty(Properties.FILE_REPOSITORY_PATH);

        EventAttendeeCertificate eventAttendeeCertificate = new EventAttendeeCertificate(document);
        if (this.attendee.getEvent().getCertificateTemplate() != null
                && !this.attendee.getEvent().getCertificateTemplate().isEmpty()) {
            StringBuilder certificateTemplatePath = new StringBuilder();
            certificateTemplatePath.append(fileRepositoryPath.getPropertyValue());
            certificateTemplatePath.append("/");
            certificateTemplatePath.append(this.attendee.getEvent().getCertificateTemplate());
            eventAttendeeCertificate.setCertificateTemplate(writer, certificateTemplatePath.toString());
        }

        List<Venue> venues = eventVenueBean.findEventVenues(this.attendee.getEvent());

        this.attendee.getEvent().setVenues(venues);
        this.attendee.generateCertificateData();
        this.attendeeBean.save(this.attendee);
        eventAttendeeCertificate.generateCertificate(this.attendee);

        document.close();

        response.getOutputStream().write(output.toByteArray());
        response.getOutputStream().flush();
        response.getOutputStream().close();
        context.responseComplete();
    } catch (IOException | DocumentException ioe) {
        LOGGER.log(Level.SEVERE, ioe.getMessage(), ioe);
    }
}

From source file:org.cejug.yougi.event.web.controller.EventMBean.java

License:Open Source License

public void getCertificate() {
    if (!this.attendee.getAttended()) {
        return;/*from  w w w .j a  va 2 s .co m*/
    }

    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
    response.setContentType("application/pdf");
    response.setHeader("Content-disposition", "inline=filename=file.pdf");

    try {
        Document document = new Document(PageSize.A4.rotate());
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, output);
        document.open();

        ApplicationProperty fileRepositoryPath = applicationPropertyBean
                .findApplicationProperty(Properties.FILE_REPOSITORY_PATH);

        EventAttendeeCertificate eventAttendeeCertificate = new EventAttendeeCertificate(document);
        StringBuilder certificateTemplatePath = new StringBuilder();
        certificateTemplatePath.append(fileRepositoryPath.getPropertyValue());
        certificateTemplatePath.append("/");
        certificateTemplatePath.append(event.getCertificateTemplate());
        eventAttendeeCertificate.setCertificateTemplate(writer, certificateTemplatePath.toString());

        this.attendee.generateCertificateData();
        this.attendeeBean.save(this.attendee);
        eventAttendeeCertificate.generateCertificate(this.attendee);

        document.close();

        response.getOutputStream().write(output.toByteArray());
        response.getOutputStream().flush();
        response.getOutputStream().close();
        context.responseComplete();
    } catch (IOException | DocumentException ioe) {
        LOGGER.log(Level.SEVERE, ioe.getMessage(), ioe);
    }
}

From source file:org.com.controller.ProductController.java

@RequestMapping(value = "/repProduct", method = RequestMethod.GET)
public void productReport(Model m, HttpServletResponse response, HttpServletRequest request,
        OutputStream outputStream) throws Exception {
    String name = "ProductReport-";
    Date d = new Date();
    name = name + d.toString() + ".pdf";
    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", "attachment; filename=" + name);
    Rectangle pagesize = new Rectangle(216f, 720f);
    Document document = new Document(PageSize.A4);
    PdfWriter.getInstance(document, outputStream);
    document.open();/*from www . j a  v  a2 s  .  c om*/
    document.addTitle("PRODUCT DETAILSA REPORT");
    document.add(new Paragraph("PRODUCT DETAILSA REPORT ",
            FontFactory.getFont(FontFactory.HELVETICA, 28, BaseColor.CYAN)));
    document.add(new Paragraph("DATE: " + new Date()));
    document.add(new Paragraph("-------------------------------------------------------- "));
    document.add(new Paragraph(" "));
    ProductDaoImpl pdi = new ProductDaoImpl();
    PdfPTable table = new PdfPTable(4);
    table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell("ID");
    table.addCell("TITLE");
    table.addCell("PUBLISHER");
    table.addCell("PRICE");
    ArrayList<ProductTable> list = pdi.getAllProduct();
    for (ProductTable u : list) {
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(u.getPid().toString());
        table.getDefaultCell().setBackgroundColor(BaseColor.GRAY);
        table.addCell(u.getPname());
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(u.getPublisher());
        table.getDefaultCell().setBackgroundColor(BaseColor.GRAY);
        table.addCell(u.getSprice().toString());
    }
    document.add(table);
    document.close();

}

From source file:org.durel.mydooble.PDF.java

License:Open Source License

public PDF(int nbItems) throws IOException, DocumentException {
    buffer = new ByteArrayOutputStream();
    doc = new Document(PageSize.A4);
    writer = PdfWriter.getInstance(doc, buffer);
    writer.setCompressionLevel(0);/*  w  w  w .j a  v  a 2s. c o  m*/
    this.nbItems = nbItems;
    doc.open();

    PdfContentByte cb = writer.getDirectContent();
    cb.setFontAndSize(font, FONT_SIZE);
}

From source file:org.fatec.lpbd.projetocurriculo.controller.CurriculoHelper.java

public CurriculoHelper(Employee emp, String path) {

    Document doc = null;/*from  w w w.  j a  v a2  s .c o  m*/
    OutputStream os = null;

    try {
        //cria o documento tamanho A4, margens de 2,54cm
        doc = new Document(PageSize.A4, 52, 52, 52, 52);

        //cria a stream de sada
        os = new FileOutputStream(path);

        try {
            //associa a stream de sada ao
            PdfWriter.getInstance(doc, os);
        } catch (DocumentException ex) {
            Logger.getLogger(CurriculoHelper.class.getName()).log(Level.SEVERE, null, ex);
        }

        //abre o documento
        doc.open();

        //adiciona o texto ao PDF
        String fullName = String.format("%1s %2s", emp.getName(), emp.getLastName());

        doc.add(titleString(fullName));
        doc.add(separatorText("INFORMAES PESSOAIS"));
        doc.add(lineSeparator());
        doc.add(simpleText("    - Idade: " + emp.getAge()));
        doc.add(simpleText(streetStringFormat(emp)));
        doc.add(simpleText(cityStringFormat(emp)));
        doc.add(simpleText(phonesStringFormat(emp)));
        doc.add(simpleText(emailStringFormat(emp)));

        doc.add(separatorText("OBJETIVO"));
        doc.add(lineSeparator());
        doc.add(simpleText(objectivesStringFormat(emp)));

        doc.add(separatorText("IDIOMA"));
        doc.add(lineSeparator());
        doc.add(simpleText(languagesStringFormat(emp)));

        doc.add(separatorText("FORMAO"));
        doc.add(lineSeparator());
        doc.add(simpleText(academicsStringFormat(emp)));

        doc.add(separatorText("EXPERINCIA PROFISSIONAL"));
        doc.add(lineSeparator());
        doc.add(simpleText(experiencesStringFormat(emp)));

    } catch (FileNotFoundException | DocumentException ex) {
        Logger.getLogger(CurriculoHelper.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (doc != null) {
            //fechamento do documento
            doc.close();
        }
        if (os != null) {
            try {
                //fechamento da stream de sada
                os.close();
            } catch (IOException ex) {
                Logger.getLogger(CurriculoHelper.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

}

From source file:org.fhaes.neofhchart.PDFExportOptionsDialog.java

License:Open Source License

/**
 * Handles when actions are performed on the dialog.
 *///from w ww .java2  s.com
@Override
public void actionPerformed(ActionEvent evt) {

    if (evt.getActionCommand().equals("OK")) {
        // Perform the export operation
        boolean completedSuccessfully = doExportToPDF();

        if (completedSuccessfully) {
            MainWindow.getInstance().getFeedbackMessagePanel().updateFeedbackMessage(FeedbackMessageType.INFO,
                    FeedbackDisplayProtocol.AUTO_HIDE,
                    FeedbackDictionary.NEOFHCHART_PDF_EXPORT_MESSAGE.toString());
        } else {
            MainWindow.getInstance().getFeedbackMessagePanel().updateFeedbackMessage(FeedbackMessageType.ERROR,
                    FeedbackDisplayProtocol.MANUAL_HIDE,
                    "An error occured while attempting to export chart as PDF.");
        }

        this.dispose();
    } else if (evt.getActionCommand().equals("Cancel")) {
        // Close the dialog
        this.dispose();
    } else if (evt.getActionCommand().equals("PaperSize")) {
        // Update the paper size label
        if (this.cboPaperSize.getSelectedItem() instanceof Rectangle) {
            Object value = this.cboPaperSize.getSelectedItem();
            if (value.equals(PageSize.A5)) {
                this.lblSize.setText("148 x 210mm  /  5.83 x 8.27\"");
            } else if (value.equals(PageSize.A4)) {
                this.lblSize.setText("210 x 297mm  /  8.27 x 11.7\"");
            } else if (value.equals(PageSize.A3)) {
                this.lblSize.setText("297 x 420mm  /  11.7 x 16.5\"");
            } else if (value.equals(PageSize.A2)) {
                this.lblSize.setText("420 x 594mm  /  16.5 x 23.4\"");
            } else if (value.equals(PageSize.A1)) {
                this.lblSize.setText("594 x 841mm  /  23.4 x 33.1\"");
            } else if (value.equals(PageSize.A0)) {
                this.lblSize.setText("841 x 1189mm  /  33.1 x 46.8\"");
            } else if (value.equals(PageSize.LETTER)) {
                this.lblSize.setText("215.9 x 279.4mm  /  8.5 x 11\"");
            } else if (value.equals(PageSize.LEGAL)) {
                this.lblSize.setText("215.9 x 355.6mm  /  8.5 x 14\"");
            } else if (value.equals(PageSize.EXECUTIVE)) {
                this.lblSize.setText("184 x 267mm  /  7.25 x 10.5\"");
            } else {
                this.lblSize.setText("");
            }

            radLandscape.setEnabled(true);
            radPortrait.setEnabled(true);
        } else {
            this.lblSize.setText("");
            radLandscape.setEnabled(false);
            radPortrait.setEnabled(false);
        }
    }
}

From source file:org.fossa.rolp.util.PdfStreamSource.java

License:Open Source License

public PdfStreamSource(FossaApplication app, LebData lebData, LebCreator lebCreator)
        throws DocumentException, IOException, PdfFormatierungsException {
    this.lebData = lebData;
    this.lebCreator = lebCreator;
    BaseFont fontNormal = BaseFont.createFont(
            app.getContext().getBaseDirectory() + Config.getRelativeNormalFontPath(), BaseFont.CP1252,
            BaseFont.EMBEDDED);//from w  w w.  j a v  a 2s. c  o  m
    BaseFont fontBold = BaseFont.createFont(
            app.getContext().getBaseDirectory() + Config.getRelativeBoldFontPath(), BaseFont.CP1252,
            BaseFont.EMBEDDED);
    BaseFont fontThin = BaseFont.createFont(
            app.getContext().getBaseDirectory() + Config.getRelativeThinFontPath(), BaseFont.CP1252,
            BaseFont.EMBEDDED);

    lernentwicklungsberichtUeberschriftFont = new Font(fontThin, 22, Font.NORMAL);
    standardTextFont = new Font(fontNormal, KlassenstufenUtils.getLebFontSize(lebData.getKlassenname()),
            Font.NORMAL);
    standardTextBoldFont = new Font(fontBold, KlassenstufenUtils.getLebFontSize(lebData.getKlassenname()),
            Font.NORMAL);
    headerFont = new Font(fontNormal, 12, Font.NORMAL);
    footerFont = new Font(fontNormal, 10, Font.NORMAL);
    fusszeilenFont = new Font(fontNormal, 8, Font.NORMAL);
    zeilenabstandsfaktor = KlassenstufenUtils.getLebZeilenabstandAsFactor(lebData.getKlassenname());
    document = null;
    try {
        document = new Document(PageSize.A4, 100, 90, topMargin, bottomMargin);
        PdfWriter writer = PdfWriter.getInstance(document, outputStream);
        LebPageHelper event = new LebPageHelper(lebData,
                Image.getInstance(app.getContext().getBaseDirectory() + Config.getRelativeLogoPath()),
                fusszeilenFont);
        writer.setPageEvent(event);
        document.open();
        addContent(writer);
        addFooter(lebData, writer);
    } finally {
        if (document != null) {
            document.close();
        }
    }
}

From source file:org.gephi.ui.exporter.preview.UIExporterPDFPanel.java

License:Open Source License

public UIExporterPDFPanel() {
    initComponents();/*  w w  w .  j av  a2s.  c om*/

    sizeFormatter = NumberFormat.getNumberInstance();
    sizeFormatter.setMaximumFractionDigits(3);
    marginFormatter = NumberFormat.getNumberInstance();
    marginFormatter.setMaximumFractionDigits(1);

    //Page size model - http://en.wikipedia.org/wiki/Paper_size
    DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
    comboBoxModel.addElement(new PageSizeItem(PageSize.A0, "A0", 841, 1189, 33.1, 46.8));
    comboBoxModel.addElement(new PageSizeItem(PageSize.A1, "A1", 594, 841, 23.4, 33.1));
    comboBoxModel.addElement(new PageSizeItem(PageSize.A2, "A2", 420, 594, 16.5, 23.4));
    comboBoxModel.addElement(new PageSizeItem(PageSize.A3, "A3", 297, 420, 11.7, 16.5));
    comboBoxModel.addElement(new PageSizeItem(PageSize.A4, "A4", 210, 297, 8.3, 11.7));
    comboBoxModel.addElement(new PageSizeItem(PageSize.A5, "A5", 148, 210, 5.8, 8.3));
    comboBoxModel.addElement(new PageSizeItem(PageSize.ARCH_A, "ARCH A", 229, 305, 9, 12));
    comboBoxModel.addElement(new PageSizeItem(PageSize.ARCH_B, "ARCH B", 305, 457, 12, 18));
    comboBoxModel.addElement(new PageSizeItem(PageSize.ARCH_C, "ARCH C", 457, 610, 18, 24));
    comboBoxModel.addElement(new PageSizeItem(PageSize.ARCH_D, "ARCH D", 610, 914, 24, 36));
    comboBoxModel.addElement(new PageSizeItem(PageSize.ARCH_E, "ARCH E", 914, 1219, 36, 48));
    comboBoxModel.addElement(new PageSizeItem(PageSize.B0, "B0", 1000, 1414, 39.4, 55.7));
    comboBoxModel.addElement(new PageSizeItem(PageSize.B1, "B1", 707, 1000, 27.8, 39.4));
    comboBoxModel.addElement(new PageSizeItem(PageSize.B2, "B2", 500, 707, 19.7, 27.8));
    comboBoxModel.addElement(new PageSizeItem(PageSize.B3, "B3", 353, 500, 13.9, 19.7));
    comboBoxModel.addElement(new PageSizeItem(PageSize.B4, "B4", 250, 353, 9.8, 13.9));
    comboBoxModel.addElement(new PageSizeItem(PageSize.B5, "B5", 176, 250, 6.9, 9.8));
    comboBoxModel.addElement(new PageSizeItem(PageSize.LEDGER, "Ledger", 432, 279, 17, 11));
    comboBoxModel.addElement(new PageSizeItem(PageSize.LEGAL, "Legal", 216, 356, 8.5, 14));
    comboBoxModel.addElement(new PageSizeItem(PageSize.LETTER, "Letter", 216, 279, 8.5, 11));
    comboBoxModel.addElement(new PageSizeItem(PageSize.TABLOID, "Tabloid", 279, 432, 11, 17));

    customSizeString = NbBundle.getMessage(UIExporterPDFPanel.class, "UIExporterPDFPanel.pageSize.custom");
    comboBoxModel.addElement(customSizeString);
    pageSizeCombo.setModel(comboBoxModel);

    loadPreferences();

    initEvents();
    refreshUnit(false);
}

From source file:org.imos.abos.plot.JfreeChartDemo.java

License:Open Source License

protected void createPDF(String filename) {
    try {/* www.  jav  a 2 s  .c o  m*/
        Rectangle page = PageSize.A4.rotate();

        // step 1
        Document document = new Document(page);
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        float width = page.getWidth();
        float height = page.getHeight();
        // add chart
        PdfTemplate pie = cb.createTemplate(width, height);
        Graphics2D g2d1 = new PdfGraphics2D(pie, width, height);
        Rectangle2D r2d1 = new Rectangle2D.Double(0, 0, width, height);
        chart.draw(g2d1, r2d1);
        g2d1.dispose();
        cb.addTemplate(pie, 0, 0);
        // step 5
        document.close();
    } catch (DocumentException ex) {
        Logger.getLogger(JfreeChartDemo.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(JfreeChartDemo.class.getName()).log(Level.SEVERE, null, ex);
    }

    System.out.println("PDF finsihed");
}