Package com.itextpdf.text

Examples of com.itextpdf.text.Document


   * Creates an instance of the concatenation class.
   * @param os  the OutputStream for the PDF document
   * @param smart  do we want PdfCopy to detect redundant content?
   */
  public PdfConcatenate(OutputStream os, boolean smart) throws DocumentException {
    document = new Document();
    if (smart)
      copy = new PdfSmartCopy(document, os);
    else
      copy = new PdfCopy(document, os)
  }
View Full Code Here


    PdfCopyFieldsImp(OutputStream os, char pdfVersion) throws DocumentException {
        super(new PdfDocument(), os);
        pdf.addWriter(this);
        if (pdfVersion != 0)
            super.setPdfVersion(pdfVersion);
        nd = new Document();
        nd.addDocListener(pdf);
    }
View Full Code Here

            + userRole
            + "' and user.idClasse = classe.id order by classe.libelle, user.nom, user.prenom";

      ResultSet rs = select.executeQuery(sql);

      Document document = new Document(PageSize.A4);

      try {
        OutputStream out = response.getOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, out);
        writer.setViewerPreferences(PdfWriter.PageLayoutSinglePage
            | PdfWriter.PageModeUseThumbs);

        document.open();
        int cpt = 0;
        while (rs.next()) {
          String string = new String();
          cpt += 3;
          string = "Nom : "
              + rs.getString("nom")
              + ", Prenom :  "
              + rs.getString("prenom")
              + ((userRole == "eleve") ? "    (Classe :  "
                  + rs.getString("libelle") + ")" : "")
              + "\n Login : "
              + rs.getString("login")
              + ", Mot de passe : "
              + rs.getString("mdp")
              + "\n"
              + "--------------------------------------------------------------";

          if (cpt >= 39) {
            string += "\n\n\n";
            cpt = 0;
          }
          document.add(new Paragraph(string));
        }

      } catch (DocumentException de) {
        de.printStackTrace();
      } catch (IOException ioe) {
        ioe.printStackTrace();
      }
      document.close();

    } catch (SQLException e) {
      e.printStackTrace();
    }
View Full Code Here

    try {
      Connection con = ds.getConnection();
      Statement select = con.createStatement();
      ResultSet rs = select
          .executeQuery("SELECT user.* FROM user where id = " + id);
      Document document = new Document(PageSize.A4);

      try {
        OutputStream out = response.getOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, out);
        writer.setViewerPreferences(PdfWriter.PageLayoutSinglePage
            | PdfWriter.PageModeUseThumbs);

        document.open();

        rs.last();
        String eleve = "Nom : " + rs.getString("nom");
        eleve += "\nPrénom : " + rs.getString("prenom");
        if (rs.getString("role").equals("eleve")) {
          int idClasse = rs.getInt("idClasse");
          rs.beforeFirst();
          ResultSet rs2 = select
              .executeQuery("SELECT classe.* from classe where id = "
                  + idClasse);
          rs2.last();
          eleve += "\nClasse : " + rs2.getString("libelle")
              + "\n\n\n";
          rs2.beforeFirst();
        }

        Paragraph paragraph = new Paragraph(eleve);
        paragraph.setAlignment(Element.ALIGN_LEFT);
        document.add(paragraph);

        com.itextpdf.text.Font fontbold = FontFactory.getFont(
            "Times-Roman", 18, Font.BOLD);
        paragraph = new Paragraph("Les demandes de validations\n\n",
            fontbold);
        paragraph.setAlignment(Element.ALIGN_CENTER);
        document.add(paragraph);

        int timeTT = 0, timeVal = 0, timeAtt = 0, timeRef = 0;
        for (int i = 0; i < dctap.size(); i++) {
          if (dctap.get(i).getEtat() != 8) {
            timeTT += dctap.get(i).getMinutes();
          }
          if (dctap.get(i).getEtat() == 1
              || dctap.get(i).getEtat() == 32) {
            timeVal += dctap.get(i).getMinutes();
          } else if (dctap.get(i).getEtat() == 2
              || dctap.get(i).getEtat() == 64) {
            timeRef += dctap.get(i).getMinutes();
          } else if (dctap.get(i).getEtat() == 0
              || dctap.get(i).getEtat() == 4
              || dctap.get(i).getEtat() > 1023) {
            timeAtt += dctap.get(i).getMinutes();
          }

        }

        double timeTTpercent = timeTT, timeValPercent = timeVal, timeAttPercent = timeAtt, timeRefPercent = timeRef;
        timeTTpercent = Math.round((timeTTpercent / (72 * 60) * 100)
            * Math.pow(10.0, 2))
            / Math.pow(10.0, 2);
        timeValPercent = Math.round(((timeValPercent / timeTT) * 100)
            * Math.pow(10.0, 2))
            / Math.pow(10.0, 2);
        timeAttPercent = Math.round(((timeAttPercent / timeTT) * 100)
            * Math.pow(10.0, 2))
            / Math.pow(10.0, 2);
        timeRefPercent = Math.round(((timeRefPercent / timeTT) * 100)
            * Math.pow(10.0, 2))
            / Math.pow(10.0, 2);

        PdfPTable table = new PdfPTable(4);

        PdfPCell c1 = new PdfPCell(new Phrase(
            "Temps total effectué (72h)", FontFactory.getFont(
                FontFactory.TIMES_ROMAN, 15,
                com.itextpdf.text.Font.BOLD)));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(7);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase("Temps total validé",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 15,
                com.itextpdf.text.Font.BOLD)));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(7);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase("Temps total en attente",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 15,
                com.itextpdf.text.Font.BOLD)));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(7);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Temps total refusé",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 15,
                com.itextpdf.text.Font.BOLD)));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(7);
        table.addCell(c1);

        table.setHeaderRows(1);

        c1 = new PdfPCell(new Phrase((timeTT / 60 - (timeTT % 60 / 60))
            + "h " + (timeTT % 60) + "min"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(
            (timeVal / 60 - (timeVal % 60 / 60)) + "h "
                + (timeVal % 60) + "min"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(
            (timeAtt / 60 - (timeAtt % 60 / 60)) + "h "
                + (timeAtt % 60) + "min"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(
            (timeRef / 60 - (timeRef % 60 / 60)) + "h "
                + (timeRef % 60) + "min"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase(timeTTpercent + "%"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(timeValPercent + "%"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(timeAttPercent + "%"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(timeRefPercent + "%"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);

        document.add(table);

      } catch (DocumentException de) {
        de.printStackTrace();
      } catch (IOException ioe) {
        ioe.printStackTrace();
      }
      document.close();

    } catch (SQLException e) {
      e.printStackTrace();
    }

View Full Code Here

            size = new Rectangle(pageSize.rotate());
        }
        Color col = props.getColorValue(PreviewProperty.BACKGROUND_COLOR);
        size.setBackgroundColor(new BaseColor(col.getRed(), col.getGreen(), col.getBlue()));

        Document document = new Document(size);
        PdfWriter pdfWriter = null;
        try {
            pdfWriter = PdfWriter.getInstance(document, stream);
            pdfWriter.setPdfVersion(PdfWriter.PDF_VERSION_1_5);
            pdfWriter.setFullCompression();

        } catch (DocumentException ex) {
            Exceptions.printStackTrace(ex);
        }
        document.open();
        PdfContentByte cb = pdfWriter.getDirectContent();
        cb.saveState();

        props.putValue(PDFTarget.LANDSCAPE, landscape);
        props.putValue(PDFTarget.PAGESIZE, size);
        props.putValue(PDFTarget.MARGIN_TOP, new Float((float) marginTop));
        props.putValue(PDFTarget.MARGIN_LEFT, new Float((float) marginLeft));
        props.putValue(PDFTarget.MARGIN_BOTTOM, new Float((float) marginBottom));
        props.putValue(PDFTarget.MARGIN_RIGHT, new Float((float) marginRight));
        props.putValue(PDFTarget.PDF_CONTENT_BYTE, cb);
        target = (PDFTarget) controller.getRenderTarget(RenderTarget.PDF_TARGET, workspace);
        if (target instanceof LongTask) {
            ((LongTask) target).setProgressTicket(progress);
        }

        try {
            controller.render(target, workspace);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        cb.restoreState();
        document.close();

        Progress.finish(progress);

        props.putValue(PDFTarget.PDF_CONTENT_BYTE, null);
        props.putValue(PDFTarget.PAGESIZE, null);
View Full Code Here

public class App
{
    public static void main( String[] args ) throws DocumentException, IOException
    {
      // step 1
      Document document = new Document();
        // step 2
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf.pdf"));
        // step 3
        document.open();
        // step 4
        XMLWorkerHelper.getInstance().parseXHtml(writer, document,
                new FileInputStream("index.html"))
        //step 5
         document.close();

        System.out.println( "PDF Created!" );
    }
View Full Code Here

    }

    public static void render(Drawable drawable, Rectangle2D bounds, File file) {
        initialize();
        Rectangle size = new Rectangle((float) bounds.getWidth(), (float) bounds.getHeight());
        Document document = new Document(size);
        FileOutputStream fos;
        try {
            fos = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException("The file " + file + "could not be created", e);
        }
        PdfWriter writer;
        try {
            writer = PdfWriter.getInstance(document, fos);
        } catch (DocumentException e) {
            throw new RuntimeException("An error occurred while creating a PdfWriter object.", e);
        }
        document.open();
        PdfContentByte contentByte = writer.getDirectContent();
        Graphics2D g = new PdfGraphics2D(contentByte, (float) bounds.getWidth(), (float) bounds.getHeight(), fontMapper);
        g.translate(-bounds.getX(), -bounds.getY());
        drawable.draw(g);
        g.dispose();
        document.close();
    }
View Full Code Here

public class App
{
    public static void main( String[] args ) throws FileNotFoundException, DocumentException
    {
      // step 1
      Document document = new Document();
      document.setPageSize(PageSize.A4);
       
      // step 2
      PdfWriter.getInstance(document, new FileOutputStream("pdf.pdf"));
       
      // step 3
        document.open();
       
        // step 4 create PDF contents
        document.add(TableBuilder.createTable());
       
        //step 5
        document.close();

        System.out.println( "PDF Created!" );
   
View Full Code Here

    public static void main( String[] args )
    {
        try {
         
          // 1. create the document page size: A4, margins: left:20 right:20 top:40 bottom:40
          Document document = new Document(PageSize.A4, 20f,20f,40f,40);
         
          //for custom pagesize
          //Rectangle pagesize = new Rectangle(216f, 720f);
         
          // 2. get PdfWriter
      PdfWriter.getInstance(document, new FileOutputStream("pagesettings.pdf"));
      // 3. open the document
          document.open();
          // 4. add the content
          document.add(new Paragraph("Hello World!"));
          // 5. close the document
          document.close();
         
          System.out.println("Document created!");
     
    } catch (FileNotFoundException e) {
      e.printStackTrace();
View Full Code Here

    public static void main( String[] args )
    {
        try {
         
          // 1. create the document
          Document document = new Document();
          // 2. get PdfWriter
      PdfWriter.getInstance(document, new FileOutputStream("helloworld.pdf"));
      // 3. open the document
          document.open();
          // 4. add the content
          document.add(new Paragraph("Hello World!"));
          // 5. close the document
          document.close();
         
          System.out.println("Document created!");
     
    } catch (FileNotFoundException e) {
      e.printStackTrace();
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.