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:Tables.PrinterClass.java

public void footer(Document doc) throws DocumentException {
    Paragraph paragraph = new Paragraph("@" + this.companyName);
    doc.add(paragraph);/*w  ww.  j a  v a  2 s  .co m*/
    dNow = new Date();

    String prodDate;
    prodDate = "Created on the " + dateOnly.format(dNow) + " at " + timeOnly.format(dNow);

    //////////////////

    PdfPTable timeOfProduction = new PdfPTable(1);

    PdfPCell cell = new PdfPCell(new Phrase(prodDate.trim(), smallFooter));
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setColspan(3);
    cell.setBorder(0);
    if (prodDate.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }

    timeOfProduction.addCell(cell);
    doc.add(timeOfProduction);

    try {
        Image img = Image.getInstance(this.companyLogo);
        img.scaleAbsolute(20f, 20f);

        img.setAbsolutePosition((PageSize.A4.getWidth() - img.getScaledWidth()),
                (PageSize.A4.getHeight() - img.getScaledHeight())); //place the image at the bottom right position

        img.setAlt("Unity Systems");
    } catch (Exception ex) {

    }

}

From source file:Tables.PrinterClass.java

/**
 * heading ends/*from ww  w.  j  ava2 s  .  co m*/
 * @param tabId
 * @param col1
 * @param col2
 * @param tHeading
 * @param fileName
 * @param tTitle
 */
public void print(TableView tabId, TableColumn col1, TableColumn col2, String fileName, String tTitle,
        String[] tHeading) {
    dNow = new Date();
    System.out.println("printing with 2 cols");
    try {
        String completeFileName = this.saveDir + fileName + this.datForFile.format(dNow) + ".pdf";
        completeFileName = System.getProperties().getProperty("user.home") + completeFileName;
        fs = new FileOutputStream(completeFileName); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea

        Document doc = new Document(PageSize.A4, 20, 20, 20, 20);
        PdfWriter writer = PdfWriter.getInstance(doc, fs);

        //specify column widths    
        float[] columnWidths = { 5f, 5f };
        PdfPTable table = new PdfPTable(columnWidths);

        table.setWidthPercentage(90f);

        PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR "));
        cell.setColspan(6);
        cell.setHorizontalAlignment(2);
        doc.open();
        //doc.add(im);

        makeCompanyHeading(doc);

        doc.add(cell);
        System.out.println(doc.leftMargin());

        for (String tHeading1 : tHeading) {
            insertTableHeading(table, tHeading1, Element.ALIGN_CENTER, 1, this.tHeadingFont);
        }
        table.setHeaderRows(1);

        /*Now i have to fill the table  */
        for (int i = 0; i < tabId.getItems().size(); i++) {
            insertCell(table, col1.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont);
            insertCell(table, col2.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont);
        }

        doc.add(table);

        footer(doc); // this is rgw footer of the page

        doc.addCreationDate();
        doc.close();
        System.out.println("finished the printing job");

        Dialogs.create().title("Printing complete").masthead("The printing process was completed succesfully")
                .message("See : " + completeFileName).showInformation();
    } catch (Exception sd) {
        sd.printStackTrace();
        Dialogs.create().title("Printer Error").masthead("Errro In Printing File")
                .message("There was an error while trying to print. ").showError();
    } finally {
    }
}

From source file:Tables.PrinterClass.java

/**
 * heading ends/*from w w w  .  j  a  va  2s. co m*/
 * @param tabId
 * @param col1
 * @param col2
 * @param tHeading
 * @param fileName
 * @param tTitle
 */
public void print(TableView tabId, TableColumn col1, TableColumn col2, TableColumn col3, String fileName,
        String tTitle, String[] tHeading) {
    dNow = new Date();
    System.out.println("printing with 2 cols");
    try {
        String completeFileName = this.saveDir + fileName + this.datForFile.format(dNow) + ".pdf";
        completeFileName = System.getProperties().getProperty("user.home") + completeFileName;
        fs = new FileOutputStream(completeFileName); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea

        Document doc = new Document(PageSize.A4, 20, 20, 20, 20);
        PdfWriter writer = PdfWriter.getInstance(doc, fs);

        //specify column widths    
        float[] columnWidths = { 4f, 4f, 4f };
        PdfPTable table = new PdfPTable(columnWidths);

        table.setWidthPercentage(90f);

        PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR "));
        cell.setColspan(6);
        cell.setHorizontalAlignment(2);
        doc.open();
        //doc.add(im);

        makeCompanyHeading(doc);

        doc.add(cell);
        System.out.println(doc.leftMargin());

        for (String tHeading1 : tHeading) {
            insertTableHeading(table, tHeading1, Element.ALIGN_CENTER, 1, this.tHeadingFont);
        }
        table.setHeaderRows(1);

        /*Now i have to fill the table  */
        for (int i = 0; i < tabId.getItems().size(); i++) {
            insertCell(table, col1.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont);
            insertCell(table, col2.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont);
            insertCell(table, col3.getCellData(i).toString(), Element.ALIGN_LEFT, 1, this.tBodyFont);
        }

        doc.add(table);

        footer(doc); // this is rgw footer of the page

        doc.addCreationDate();
        doc.close();
        System.out.println("finished the printing job");

        Dialogs.create().title("Printing complete").masthead("The printing process was completed succesfully")
                .message("See : " + completeFileName).showInformation();
    } catch (Exception sd) {
        sd.printStackTrace();
        Dialogs.create().title("Printer Error").masthead("Errro In Printing File")
                .message("There was an error while trying to print. ").showError();
    } finally {
    }
}

From source file:timeclock.reports.TableReport.java

/**
 * Creates the PDF with the employee list.
 *///from  w w w.j  av  a2 s .co  m
public void createPdf() {
    // Step 1 - create the Document
    Document document = new Document(PageSize.A4, 36, 36, 54, 54);
    try {
        // Step 2 - create the PdfWriter and arguements
        // TODO: FILE_CHOOSER - Change how I get the file name and location, put dialog here
        // FileChooser fc = new FileChooser();
        // this.fileName = fc.showDialog("Employees");
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(this.fileName));
        HeaderFooter event = new HeaderFooter(this.title, MyFonts.font.get("title"));
        writer.setBoxSize("art", new Rectangle(36, 54, 559, 788));
        writer.setPageEvent(event);
        // Step 3 - Open the document
        document.open();
        // Step 4 - create and add content
        PdfPTable table = createTable(this.list);
        document.add(table);
        // Step 5 - close the document
        document.close(); // no need to close PDFwriter?
    } catch (DocumentException | FileNotFoundException e) {
        Debugger.log(e);
    }
}

From source file:tn.com.hitechart.eds.Util.pdfRpport.FirstPdf.java

public void createPdf(Context context, String NamePDF, String[] tabData, List<Task> taskList,
        List<Achat> achatList, List<Composant> compList, List<Message> msgList, List<Task> autreActList,
        List<Dossier> dossList) {
    try {// w  ww . ja v a 2 s .c om
        Document document = new Document(PageSize.A4.rotate());
        PdfWriter.getInstance(document, new FileOutputStream(PATHFILE + NamePDF));
        document.open();
        //addMetaData(document);
        // addTitlePage(document);

        tabDatapointage = tabData;
        tasks = taskList;
        achats = achatList;
        comps = compList;
        msgs = msgList;
        dossiers = dossList;
        td = new TasksDAO(context);
        autreActList = autreActList;

        addContent(document);
        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:tn.com.hitechart.eds.Util.pdfRpport.FirstPdf.java

private void createTable(Section subCatPart) throws BadElementException {

    //-------------------------- TAB POINTAGE -------------------//
    PdfPTable table = new PdfPTable(8);
    table.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    table.setLockedWidth(true);// w w  w  .  jav  a2  s .  c  o m
    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    //----------- C1 --------------//
    PdfPCell c1 = new PdfPCell(new Phrase("Date Rapport"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C2 --------------//
    c1 = new PdfPCell(new Phrase("Technicien"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C3 --------------//
    c1 = new PdfPCell(new Phrase("Poinatge"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    //----------- C4 --------------//
    c1 = new PdfPCell(new Phrase("Matin"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    //----------- C5 --------------//
    c1 = new PdfPCell(new Phrase("Aprs-Midi"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    //----------- C6 --------------//
    c1 = new PdfPCell(new Phrase("Rapport Journalier", catFont));
    c1.setBorder(Rectangle.NO_BORDER);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setColspan(3);
    table.addCell(c1);
    //----------- C7 --------------//

    //----------- C8 --------------//

    table.setHeaderRows(1);

    //----------- R2 --------------//
    //----------- C1 --------------//
    c1 = new PdfPCell(new Phrase(tabDatapointage[0], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setRowspan(2);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(user.getLogin(), dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setRowspan(2);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Arrive"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(tabDatapointage[1], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(tabDatapointage[2], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C7 --------------//

    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C8 --------------//

    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);

    //----------- R3 --------------//

    c1 = new PdfPCell(new Phrase("Sortie"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(tabDatapointage[3], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(tabDatapointage[4], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C7 --------------//
    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C8 --------------//
    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    table.setSpacingAfter(10);
    subCatPart.add(table);

    //-------------------------- END TAB POINTAGE -------------------//
    // TODO: 20/01/2017
    //--------------------------------- TASK ---------------------//
    PdfPTable tableTask = new PdfPTable(5);

    tableTask.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableTask.setLockedWidth(true);

    PdfPCell c2 = new PdfPCell(new Phrase("Dossiers Traits", catFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    c2.setColspan(5);
    c2.setBorder(Rectangle.NO_BORDER);
    tableTask.addCell(c2);

    tableTask.setHeaderRows(1);

    c2 = new PdfPCell(new Phrase("NDoss.", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);

    c2 = new PdfPCell(new Phrase("Client", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);

    c2 = new PdfPCell(new Phrase("Dure", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);

    c2 = new PdfPCell(new Phrase("Mission", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);

    c2 = new PdfPCell(new Phrase("Resultat", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);
    if (tasks.isEmpty()) {
        c2 = new PdfPCell(new Phrase("Aucune  Tache a t trait", catFontempty));
        c2.setHorizontalAlignment(Element.ALIGN_CENTER);
        c2.setColspan(5);
        tableTask.addCell(c2);
    } else {

        if (!dossiers.isEmpty()) {
            for (Dossier d : dossiers) {

                tableTask.addCell(d.getNumDoss());
                tableTask.addCell(d.getClient());
                tableTask.addCell(convertLongtoDurationfr(d.getTimeDuration()));
                tableTask.addCell(td.getTaskById(d.get_idTask()).getType());
                tableTask.addCell(td.getTaskById(d.get_idTask()).getRes());
            }
        }

    }

    tableTask.setSpacingAfter(10);

    subCatPart.add(tableTask);

    //-------------------------- END TAB TASK -------------------//
    // TODO: 20/01/2017  tab achat
    //-------------------------- TAB ACHAT -------------------//

    PdfPTable tableAchat = new PdfPTable(3);

    tableAchat.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableAchat.setLockedWidth(true);

    PdfPCell c3 = new PdfPCell(new Phrase("Frais Engags", catFont));
    c3.setHorizontalAlignment(Element.ALIGN_CENTER);
    c3.setColspan(3);
    c3.setBorder(Rectangle.NO_BORDER);
    tableAchat.addCell(c3);

    tableAchat.setHeaderRows(1);
    c3 = new PdfPCell(new Phrase("N.Doss.", dataFont));
    c3.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAchat.addCell(c3);

    c3 = new PdfPCell(new Phrase("Dsignation", dataFont));
    c3.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAchat.addCell(c3);

    c3 = new PdfPCell(new Phrase("Montant TCC", dataFont));
    c3.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAchat.addCell(c3);
    if (achats.isEmpty()) {
        c3 = new PdfPCell(new Phrase("la liste des achats est vide", catFontempty));
        c3.setHorizontalAlignment(Element.ALIGN_CENTER);
        c3.setColspan(3);
        tableAchat.addCell(c3);
    } else {

        for (Achat achat : achats) {

            tableAchat.addCell(String.valueOf(achat.getNumDoss()));
            tableAchat.addCell(achat.getDesignation());
            tableAchat.addCell(String.valueOf(achat.getPrix()));
        }
    }
    tableAchat.setSpacingAfter(10);
    subCatPart.add(tableAchat);
    //-------------------------- END TAB ACHAT -------------------//

    // TODO: 20/01/2017  tab composant
    //-------------------------- TAB COMPOSANT -------------------//

    PdfPTable tableComp = new PdfPTable(3);

    tableComp.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableComp.setLockedWidth(true);

    PdfPCell c4 = new PdfPCell(new Phrase("Composants", catFont));
    c4.setHorizontalAlignment(Element.ALIGN_CENTER);
    c4.setColspan(3);
    c4.setBorder(Rectangle.NO_BORDER);
    tableComp.addCell(c4);
    tableComp.setHeaderRows(1);

    c4 = new PdfPCell(new Phrase("N.Doss.", dataFont));
    c4.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableComp.addCell(c4);

    c4 = new PdfPCell(new Phrase("Dsignation", dataFont));
    c4.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableComp.addCell(c4);

    c4 = new PdfPCell(new Phrase("Quantit", dataFont));
    c4.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableComp.addCell(c4);

    if (comps.isEmpty()) {
        c4 = new PdfPCell(new Phrase("la liste des composants est vide", catFontempty));
        c4.setHorizontalAlignment(Element.ALIGN_CENTER);
        c4.setColspan(3);
        tableComp.addCell(c4);
    } else {
        for (Composant comp : comps) {

            tableComp.addCell(String.valueOf(comp.getNumDoss()));
            tableComp.addCell(comp.getName());
            tableComp.addCell(String.valueOf(comp.getQte()));
        }
    }
    tableComp.setSpacingAfter(10);
    subCatPart.add(tableComp);
    //-------------------------- END TAB COMPOSANT -------------------//

    // TODO: 20/01/2017  tab message
    //-------------------------- TAB MESSAGE -------------------//

    PdfPTable tableMsg = new PdfPTable(2);

    tableMsg.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableMsg.setLockedWidth(true);

    PdfPCell c5 = new PdfPCell(new Phrase("Message  Transmettre", catFont));
    c5.setHorizontalAlignment(Element.ALIGN_CENTER);
    c5.setColspan(3);
    c5.setBorder(Rectangle.NO_BORDER);
    tableMsg.addCell(c5);

    c5 = new PdfPCell(new Phrase("N.Doss.", dataFont));
    c5.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableMsg.addCell(c5);

    tableMsg.setHeaderRows(1);
    c5 = new PdfPCell(new Phrase("Message", dataFont));
    c5.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableMsg.addCell(c5);

    tableMsg.setHeaderRows(1);
    if (msgs.isEmpty()) {
        c5 = new PdfPCell(new Phrase("Aucun message", catFontempty));
        c5.setHorizontalAlignment(Element.ALIGN_CENTER);
        c5.setColspan(3);
        tableMsg.addCell(c5);
    } else {
        for (Message msg : msgs) {

            tableMsg.addCell(String.valueOf(msg.getNumDoss()));
            tableMsg.addCell(msg.getMsg());
        }
    }
    tableMsg.setSpacingAfter(10);
    subCatPart.add(tableMsg);
    //-------------------------- END TAB MESSAGE -------------------//

    // TODO: 20/01/2017  tab Activitee
    //-------------------------- TAB ACTIVITEE -------------------//

    PdfPTable tableAct = new PdfPTable(2);

    tableAct.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableAct.setLockedWidth(true);

    PdfPCell c6 = new PdfPCell(new Phrase("Autre Activites", catFont));
    c6.setHorizontalAlignment(Element.ALIGN_CENTER);
    c6.setColspan(2);
    c6.setBorder(Rectangle.NO_BORDER);
    tableAct.addCell(c6);

    tableAct.setHeaderRows(1);

    c6 = new PdfPCell(new Phrase("N.Doss.", dataFont));
    c6.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAct.addCell(c6);

    c6 = new PdfPCell(new Phrase("Dure", dataFont));
    c6.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAct.addCell(c6);
    if (autreActs.isEmpty()) {
        c6 = new PdfPCell(new Phrase("Aucune autre Activite a t effectu", catFontempty));
        c6.setHorizontalAlignment(Element.ALIGN_CENTER);
        c6.setColspan(3);
        tableAct.addCell(c6);
    } else {

        for (Task autreA : autreActs) {

            tableAct.addCell(String.valueOf(autreA.getType()));
            tableAct.addCell(autreA.getNumDoss());
        }

    }
    tableAct.setSpacingAfter(10);
    subCatPart.add(tableAct);
    //-------------------------- END TAB MESSAGE -------------------//
}

From source file:tourma.views.report.HTMLtoPDF.java

public static void exportToPDF_Landscape(FileOutputStream output, String source, String title) {
    com.itextpdf.text.Rectangle A4H = new Rectangle(PageSize.A4.getHeight(), PageSize.A4.getWidth());
    exportToPDF(output, source, title, A4H);
}

From source file:tourma.views.report.HTMLtoPDF.java

public static void exportToPDF(FileOutputStream output, String source, String title) {
    exportToPDF(output, source, title, PageSize.A4);
}

From source file:userinterface.graph.Graph.java

License:Open Source License

/**
 * Exports the given chart to a pdf format file
 * @param file the file that has to be saved in pdf format
 * @param chart the chart that needs to be exported into pdf
 *//*from  w w w.  java2 s  . c  o  m*/

public static void exportToPDF(File file, JFreeChart chart) {

    PdfWriter out = null;
    com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.A4.rotate());

    int width = 800, height = 500;

    try {

        out = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        PdfContentByte contentByte = out.getDirectContent();
        PdfTemplate template = contentByte.createTemplate(width, height);
        @SuppressWarnings("deprecation")
        Graphics2D graphics2d = template.createGraphics(width, height, new DefaultFontMapper());
        Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width, height);

        chart.draw(graphics2d, rectangle2d);

        graphics2d.dispose();
        contentByte.addTemplate(template, 0, 0);

    } catch (Exception e) {

        JOptionPane.showMessageDialog(GUIPrism.getGUI(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
        return;
    }

    document.close();

}

From source file:userinterface.graph.Graph3D.java

License:Open Source License

/**
 * Exports the 3d graph as a pdf/*  w  w  w. ja v  a 2  s .  c o  m*/
 * 
 * @param file The pdf file to which the data should be written
 * @param panel The chart panel that has to be exported
 */
public static void exportToPDF(File file, Chart3DPanel panel) {

    PdfWriter out = null;
    Document document = new com.itextpdf.text.Document(PageSize.A4.rotate());

    int width = 800, height = 500;

    try {

        out = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        PdfContentByte contentByte = out.getDirectContent();
        PdfTemplate template = contentByte.createTemplate(width, height);
        @SuppressWarnings("deprecation")
        Graphics2D graphics2d = template.createGraphics(width, height, new DefaultFontMapper());
        Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width, height);

        panel.getChart().draw(graphics2d, rectangle2d);

        graphics2d.dispose();
        contentByte.addTemplate(template, 0, 0);

    } catch (Exception e) {
        // in case any error occurs tell the user what the error is (sometimes useful if there is a problem of writing rights)
        JOptionPane.showMessageDialog(GUIPrism.getGUI(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
        return;
    }

    document.close();
}