Package com.itextpdf.text

Examples of com.itextpdf.text.Document


        Rectangle size = new Rectangle(pageSize);
        if (landscape) {
            size = new Rectangle(pageSize.rotate());
        }
        size.setBackgroundColor(new BaseColor(Lookup.getDefault().lookup(PreviewController.class).getModel().getBackgroundColor()));
        document = new Document(size);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, stream);
        document.open();
        cb = pdfWriter.getDirectContent();
        cb.saveState();
View Full Code Here


  }

  @Override
  public void processExport(OutputStream output) {

    Document document = null;
    if (exportConf.getOrientation() != null && exportConf.getOrientation().equals(Orientation.LANDSCAPE)) {
      document = new Document(PageSize.LETTER.rotate());
    }
    else{
      document = new Document();
    }
   
    PdfWriter pdfWriter;
    try {
      pdfWriter = PdfWriter.getInstance(document, output);
      pdfWriter.setViewerPreferences(PdfWriter.PageLayoutSinglePage);

      document.open();
      addTitle(document);
      addTable(document);

    } catch (DocumentException e) {
      StringBuilder sb = new StringBuilder("Something went wrong during the PDF generation of the table '");
      sb.append(table.getOriginalId());
      sb.append("' and with the following export configuration: ");
      sb.append(exportConf.toString());
      throw new ExportException(sb.toString(), e);
    } finally {
      document.close();
    }
  }
View Full Code Here

    public void doExport(final Profile profile, final int width, final int height) {
        final PauseTransition pt = new PauseTransition();
        pt.setDuration(Duration.millis(profile.getPause()));
        final AtomicInteger cpt = new AtomicInteger();
        final Document document = new Document(new Rectangle(width, height), 0, 0, 0, 0);
        try {
            PdfWriter.getInstance(document, new FileOutputStream(exportFile));
        } catch (DocumentException | FileNotFoundException e) {
            handleError(e);
            return;
        }
        document.open();
        profile.setDocument(document);
        pt.setOnFinished(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                WritableImage image = browser.snapshot(null, null);
                BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null);
                double scaler = ((document.getPageSize().getWidth() - document.leftMargin()
                        - document.rightMargin()) / image.getWidth()) * 100;

                try {
                    com.itextpdf.text.Image image2 =
                            com.itextpdf.text.Image.getInstance(bufferedImage, null);
                    image2.scalePercent((float) scaler);
                    document.add(image2);
                    document.newPage();
                    int current = cpt.incrementAndGet();
                    int nbSlides = profile.getSlideCount();
                    System.out.println("Exported slide " + current + (nbSlides > 0 ? "/" + nbSlides : ""));
                    if (!profile.isLastSlide(current)) {
                        profile.nextSlide();
                        pt.setDuration(Duration.millis(profile.getPause()));
                        pt.play();
                    } else {
                        profile.finish();
                        document.close();
                        System.out.println("Export complete.");
                        Platform.exit();
                    }
                } catch (IOException | DocumentException e) {
                    handleError(e);
View Full Code Here

  public class pdf {
      
      public void createPdf()
          throws IOException, DocumentException, SQLException {
        File file=new File("vipul.pdf");
        Document document = new Document();
          PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
          HeaderFooter event = new HeaderFooter();
          writer.setBoxSize("art", new Rectangle(36, 54, 559, 788));
          writer.setPageEvent(event);
         document.open();
         
      Paragraph p=new Paragraph();
      for (int i=0; i<=1000; i++){
      p.add("dnfkjnsdjkfjknsdkjfnknsdkfjbsdkjfs");}
      document.add(p);
     
          document.close();
       }
View Full Code Here

        PdfReader reader = new PdfReader(input);
        int n = reader.getNumberOfPages();
        Rectangle pageSize = reader.getPageSize(1);

        System.out.println("Input page size: " + pageSize);
        Document doc = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
        PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(output));
        doc.open();
        // splitLine(doc, writer);
        PdfContentByte cb = writer.getDirectContent();
        float bottom = (doc.top() - pageSize.getHeight()) / 2 + kOffset;
        float left = doc.right() / 2 - (pageSize.getWidth() + kTextWidth) / 2 - kMargin;
        float right = doc.right() / 2 - (pageSize.getWidth() - kTextWidth) / 2 + kMargin;

        for (int i = 0; i <= n;) {
            PdfImportedPage page = getPage(writer, reader, i++);
            if (page != null)
                cb.addTemplate(page, left, bottom);

            page = getPage(writer, reader, i++);
            if (page != null)
                cb.addTemplate(page, right, bottom);

            doc.newPage();
        }
        doc.close();
    }
View Full Code Here

        PdfReader reader = new PdfReader(input);
        int n = reader.getNumberOfPages();
        Rectangle pageSize = reader.getPageSize(1);

        System.out.println("Input page size: " + pageSize);
        Document doc = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
        PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(output));
        doc.open();
        splitLine(doc, writer);
        int[] pages = new int[(n + 3) / 4 * 4];
        int x = 1, y = pages.length;
        for (int i = 0; i < pages.length;) {
            pages[i++] = y--;
            pages[i++] = x++;
            pages[i++] = x++;
            pages[i++] = y--;
        }
        PdfContentByte cb = writer.getDirectContent();
        float bottom = (doc.top() - pageSize.getHeight()) / 2 + kOffset;
        float left = doc.right() / 2 - (pageSize.getWidth() + kTextWidth) / 2 - kMargin;
        float right = doc.right() / 2 - (pageSize.getWidth() - kTextWidth) / 2 + kMargin;

        for (int i = 0; i < pages.length;) {
            PdfImportedPage page = getPage(writer, reader, pages[i++]);
            if (page != null)
                cb.addTemplate(page, left, bottom);

            page = getPage(writer, reader, pages[i++]);
            if (page != null)
                cb.addTemplate(page, right, bottom);

            doc.newPage();
        }
        doc.close();
    }
View Full Code Here

   *
   * @param airport
   */
  public int generate(String airport) {

    Document doc = null;
    Paragraph p1 = new Paragraph(
        "                             A   Monsieur le directeur de l'aéroport",
        CATFONT);
    ajouterLigneVide(p1, 2);
    Paragraph p2 = new Paragraph(
        "Objet : Signature à apposer sur Procés-Verbal", CATFONT);
    ajouterLigneVide(p2, 2);
    Paragraph p3 = new Paragraph("Monsieur,", CATFONT);
    ajouterLigneVide(p3, 1);
    Paragraph p4 = new Paragraph(
        "Nous avons élaboré le rapport des actions à faire suites aux réclamations que vous avez reçu dans votre aéroport. ",
        CATFONT);
    ajouterLigneVide(p4, 1);
    Paragraph p5 = new Paragraph(
        "Comme, nous vous remercions aux efforts que vous fournissez pour collaborer à ce travail. Nous insistons sur le faite de nous envoyer un rapport détaillé englobant toutes les Actions Entreprises Parmi celles incluent dans le tableau suivant :",
        CATFONT);
    ajouterLigneVide(p5, 2);
    Paragraph p6 = new Paragraph(
        "Nous vous prions d'agréer, Monsieur, nos salutations distinguées.",
        CATFONT);

    SimpleDateFormat formatter = new SimpleDateFormat("dd_MM_yyyy");
    String file = "/home/matrix/Desktop/pvs/PV_" + formatter.format(new Date())
        + "_" + airport + ".pdf";

    try {

      doc = new Document();

      PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(
          file));
      writer.setPdfVersion(PdfWriter.PDF_VERSION_1_6);

      // opening the document for writing
      doc.open();

      Image _logo = Image
          .getInstance("/home/matrix/apps/workspace/reclaadmin/WebContent/VAADIN/themes/reindeer/layouts/images/logo.gif");
      _logo.setAlignment(1);
      _logo.scalePercent(50);

      Image logo = Image
          .getInstance("/home/matrix/apps/workspace/reclaadmin/WebContent/VAADIN/themes/reindeer/layouts/images/slogon.gif");
      logo.setAlignment(1);
      logo.scalePercent(50);

      Paragraph p0 = new Paragraph();
      p0.add(_logo);
      p0.add(logo);

      ajouterLigneVide(p0, 3);

      doc.add(p0);
      doc.add(p1);
      doc.add(p2);
      doc.add(p3);
      doc.add(p4);
      doc.add(p5);
      doc.add(createTable(airport));
      doc.add(p6);

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

    // Closing the document
    doc.close();

    return 0;
  }
View Full Code Here

     */
    public int generate(ReclaadminApplication application)
    {
      __app = application;
     
        Document document = null;

        try
        {
            document = new Document();
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("/home/matrix/Desktop/pv.pdf"));
            writer.setPdfVersion(PdfWriter.PDF_VERSION_1_6);
            //open document for writing
            document.open();
            Image _logo = Image.getInstance("/home/matrix/apps/workspace/reclaadmin/WebContent/VAADIN/themes/reindeer/layouts/images/logo.gif");
            Image logo = Image.getInstance("/home/matrix/apps/workspace/reclaadmin/WebContent/VAADIN/themes/reindeer/layouts/images/slogon.gif");
           
            _logo.setAlignment(Image.MIDDLE);
            _logo.scalePercent(50);
           
            logo.setAlignment(Image.MIDDLE);
            logo.scalePercent(50);
           
            document.add(_logo);
            document.add(logo);
           
            document.add(new Paragraph("--Header--"));
           
        } catch (Exception e) {
            e.printStackTrace();
        }
       
        //closing the document
        document.close();
     
      return 0;
    }
View Full Code Here

    window.addComponent(e);
    application.getMainWindow().addWindow(window);
  }

  private void prepareContent() {
    Document document = null;

    try {
      BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250,
          BaseFont.EMBEDDED);
      Font f = new Font(bf, 12, Font.NORMAL);

      document = new Document(PageSize.A4, 10, 10, 50, 50);
      PdfWriter instance = PdfWriter.getInstance(document, os);
      document.open();

      Paragraph paragraph = new Paragraph("Zestawienie czasu pracy pracownika za " + date
          + " - " + person, f);
      paragraph.setAlignment(Element.ALIGN_CENTER);
      document.add(paragraph);
      addEmptyLine(document, 2);
      PdfPTable table = new PdfPTable(5);

      Phrase phrase = new Phrase("Dzień miesiąca", f);
      PdfPCell c1 = new PdfPCell(phrase);
      c1.setHorizontalAlignment(Element.ALIGN_CENTER);
      table.addCell(c1);

      c1 = new PdfPCell(new Phrase("Czas pracy\u0144", f));
      c1.setHorizontalAlignment(Element.ALIGN_CENTER);
      table.addCell(c1);

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

      c1 = new PdfPCell(new Phrase("Czas nieobecności", f));
      c1.setHorizontalAlignment(Element.ALIGN_CENTER);
      table.addCell(c1);

      c1 = new PdfPCell(new Phrase("Przyczyna nieobecność", f));
      c1.setHorizontalAlignment(Element.ALIGN_CENTER);
      table.addCell(c1);

      table.setHeaderRows(1);

      for (Day day : days) {
        PdfPCell cell = new PdfPCell(new Phrase(getValue(day.getDay()), f));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(getValue(day.getWorkTime()), f));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(getValue(day.getProgram()), f));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(getValue(day.getAbsenceTime()), f));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(getValue(day.getAbsenceReason()), f));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

      }
      document.add(table);

      addEmptyLine(document, 3);
      Paragraph paragraph2 = new Paragraph("Podpis pracownika");
      paragraph2.setAlignment(Element.ALIGN_CENTER);
      document.add(paragraph2);
      Paragraph paragraph3 = new Paragraph("...........................................");
      paragraph3.setAlignment(Element.ALIGN_CENTER);
      document.add(paragraph3);
    } catch (Exception e) {
      throw new RuntimeException(e);
    } finally {
      if (document != null) {
        document.close();
      }
    }
  }
View Full Code Here

    return bao.toByteArray();
  }
 
  public static void generate(String[] pageURIs, Resolution resolution, OutputStream out)
      throws IOException {
    Document document = initialPDF();
   
    try {
      PdfWriter.getInstance(document, out);
      document.open();
      mergeAllPages(pageURIs, resolution, document);
    } catch (DocumentException e) {
      e.printStackTrace();
    } finally {
      document.close();
      IOUtils.closeQuietly(out);
    }
  }
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.