Package com.itextpdf.text

Examples of com.itextpdf.text.Document


     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("application/pdf");
        OutputStream out = response.getOutputStream();
        Document document = new Document();

        try {
            PdfWriter.getInstance(document, out);
            document.open();

            HttpSession session = request.getSession(true);
            Panier panier = (Panier) session.getAttribute("lePanier");
            if (panier == null) // il n'y a pas de paniers
            {
                document.add(new Paragraph("Votre panier est vide"));

            } else {
                Paragraph titre = new Paragraph("Facture", FontFactory.getFont(FontFactory.TIMES, 18, Font.BOLDITALIC, BaseColor.BLUE));
                titre.setAlignment(Element.ALIGN_CENTER);
                titre.setSpacingAfter(30f);

                document.add(titre);

                int prixTotal = 0;
                PdfPTable table = new PdfPTable(3);

                table.addCell(new Paragraph("Epreuve", FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLDITALIC, BaseColor.BLACK)));
                table.addCell(new Paragraph("Prix unitaire", FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLDITALIC, BaseColor.BLACK)));
                table.addCell(new Paragraph("nombre", FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLDITALIC, BaseColor.BLACK)));
                for (ArticlePanier a : panier) {
                    table.addCell(" " + a.getEpreuve().getNom() + " ");
                    table.addCell(" " + 15 + " Euros");
                    table.addCell(" " + a.getQuantite());
                }
                document.add(table);
//                Paragraph paraPrixTotal = new Paragraph("Prix total HT : " + panier.getPrixTotalHT() + " Euros");
//                paraPrixTotal.setSpacingBefore(20f);
//                document.add(paraPrixTotal);
                Paragraph paraPrixTotalTTC = new Paragraph("Prix total TTC : " + panier.getPrixTotalTTC() + " Euros");
                paraPrixTotalTTC.setSpacingBefore(20f);
                document.add(paraPrixTotalTTC);
            }
            document.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here


    @Test
    public void createPdfTest() throws IOException, DocumentException, XMPException {
        String fileName = "xmp_metadata.pdf";
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(OUT_FOLDER + fileName));
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XmpWriter xmp = new XmpWriter(os);

        DublinCoreProperties.addSubject(xmp.getXmpMeta(), "Hello World");
        DublinCoreProperties.addSubject(xmp.getXmpMeta(), "XMP & Metadata");
        DublinCoreProperties.addSubject(xmp.getXmpMeta(), "Metadata");

        PdfProperties.setKeywords(xmp.getXmpMeta(), "Hello World, XMP & Metadata, Metadata");
        PdfProperties.setVersion(xmp.getXmpMeta(), "1.4");

        xmp.close();

        writer.setXmpMetadata(os.toByteArray());
        // step 3
        document.open();
        // step 4
        document.add(new Paragraph("Hello World"));
        // step 5
        document.close();

        CompareTool ct = new CompareTool();
        Assert.assertNull(ct.compareXmp(OUT_FOLDER + fileName, CMP_FOLDER + fileName, true));
    }
View Full Code Here

    @Test
    public void createPdfAutomaticTest() throws IOException, DocumentException {
        String fileName = "xmp_metadata_automatic.pdf";
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(OUT_FOLDER + fileName));
        document.addTitle("Hello World example");
        document.addSubject("This example shows how to add metadata & XMP");
        document.addKeywords("Metadata, iText, step 3");
        document.addCreator("My program using 'iText'");
        document.addAuthor("Bruno Lowagie & Paulo Soares");
        writer.createXmpMetadata();
        // step 3
        document.open();
        // step 4
        document.add(new Paragraph("Hello World"));
        // step 5
        document.close();
        CompareTool ct = new CompareTool();
        Assert.assertNull(ct.compareXmp(OUT_FOLDER + fileName, CMP_FOLDER + fileName, true));
    }
View Full Code Here

    @Test
    public void deprecatedLogicTest() throws IOException, DocumentException {
        String fileName = "xmp_metadata_deprecated.pdf";
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(OUT_FOLDER + fileName));
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XmpWriter xmp = new XmpWriter(os);
        XmpSchema dc = new com.itextpdf.text.xml.xmp.DublinCoreSchema();
        XmpArray subject = new XmpArray(XmpArray.UNORDERED);
        subject.add("Hello World");
        subject.add("XMP & Metadata");
        subject.add("Metadata");
        dc.setProperty(DublinCoreSchema.SUBJECT, subject);
        xmp.addRdfDescription(dc.getXmlns(), dc.toString());
        PdfSchema pdf = new PdfSchema();
        pdf.setProperty(PdfSchema.KEYWORDS, "Hello World, XMP & Metadata, Metadata");
        pdf.setProperty(PdfSchema.VERSION, "1.4");
        xmp.addRdfDescription(pdf);
        xmp.close();
        writer.setXmpMetadata(os.toByteArray());
        // step 3
        document.open();
        // step 4
        document.add(new Paragraph("Hello World"));
        // step 5
        document.close();
        CompareTool ct = new CompareTool();
        Assert.assertNull(ct.compareXmp(OUT_FOLDER + fileName, CMP_FOLDER + "xmp_metadata.pdf", true));
    }
View Full Code Here

    FileUtils.deleteFile(pdfFile);
    return filePath;
  }

  private void createPdfDocumentFileFromTIFF(File tiffFile, File pdfFile) throws Exception {
    Document document = new Document(PageSize.A4, 0.0f, 0.0f, 0.0f, 0.0f);
    PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
    document.open();
    RandomAccessFileOrArray ra = new RandomAccessFileOrArray(tiffFile.getCanonicalPath());
    int pageCount = TiffImage.getNumberOfPages(ra);
    for (int i = 0; i < pageCount; ++i) {
      Image img = TiffImage.getTiffImage(ra, i + 1);
      if (img != null) {
        if (i != 0) {
          document.newPage();
        }
        if (img.getWidth() > PageSize.A4.getWidth() || img.getHeight() > PageSize.A4.getHeight()) {
          img.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight());
        }
        document.add(img);
      }
    }
    ra.close();
    document.close();
  }
View Full Code Here

    ra.close();
    document.close();
  }

  private void createPdfDocumentFileFromSingleImageFile(File imageFile, File pdfFile) throws Exception {
    Document document = new Document(PageSize.A4, 0.0f, 0.0f, 0.0f, 0.0f);
    PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
    document.open();
    Image image = Image.getInstance(imageFile.getCanonicalPath());
    image.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight());
    document.add(image);
    document.close();
  }
View Full Code Here

    }
    return pdfFile;
  }

  private void createPdfDocumentFileFromTIFF(File tiffFile, File pdfFile) throws Exception {
    Document document = new Document(PageSize.A4, 0.0f, 0.0f, 0.0f, 0.0f);
    PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
    document.open();
    RandomAccessFileOrArray ra = new RandomAccessFileOrArray(tiffFile.getCanonicalPath());
    int pageCount = TiffImage.getNumberOfPages(ra);
    for (int i = 0; i < pageCount; ++i) {
      God.appWindow.getStatusBar().setInitProgress(i, pageCount);
      Image img = TiffImage.getTiffImage(ra, i + 1);
      if (img != null) {
        if (i != 0) {
          document.newPage();
        }
        if (img.getWidth() > PageSize.A4.getWidth() || img.getHeight() > PageSize.A4.getHeight()) {
          img.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight());
        }
        document.add(img);
      }
    }
    God.appWindow.getStatusBar().setInitProgress(pageCount, pageCount);
    ra.close();
    document.close();
  }
View Full Code Here

    ra.close();
    document.close();
  }

  private void createPdfDocumentFileFromSingleImageFile(File imageFile, File pdfFile) throws Exception {
    Document document = new Document(PageSize.A4, 0.0f, 0.0f, 0.0f, 0.0f);
    PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
    document.open();
    Image image = Image.getInstance(imageFile.getCanonicalPath());
    image.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight());
    document.add(image);
    document.close();
  }
View Full Code Here

  private void generatePDF(String filepath) {

    com.itextpdf.text.Rectangle r = new com.itextpdf.text.Rectangle(0, 0,
        graphContainer.getWidth(), graphContainer.getHeight());

    Document document = new Document(r);
    try {
      PdfWriter writer;
      writer = PdfWriter.getInstance(document, new FileOutputStream(
          filepath));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      PdfTemplate tp = cb.createTemplate(graphContainer.getWidth(),
          graphContainer.getHeight());
      Graphics2D g2d = tp.createGraphics(graphContainer.getWidth(),
          graphContainer.getHeight(), new DefaultFontMapper());

      graphContainer.addNotify();
      graphContainer.validate();

      graphContainer.paint(g2d);
      g2d.dispose();

      cb.addTemplate(tp, 0, 0);
    } catch (Exception e) {
      e.printStackTrace();
    }

    document.close();

  }
View Full Code Here

  }

  private static void createPDF(String filename, String title,
      List<JFreeChart> charts) throws IOException {
    Rectangle rect = PageSize.A4.rotate();
    Document document = new Document(rect);
    OutputStream out = new FileOutputStream(filename);
    try {
      PdfWriter writer = PdfWriter.getInstance(document, out);
      document.addAuthor("Daniel Velten");
      document.addTitle(title);
      document.open();
     
      for (JFreeChart chart : charts) {
        addChartToPDF(chart, rect, writer);       
        document.newPage();
      }
    } catch (DocumentException de) {
      System.err.println(de.getMessage());
    }
    document.close();
    out.close();
  }
View Full Code Here

TOP

Related Classes of com.itextpdf.text.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.