Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfWriter


        Rectangle psize = reader.getPageSize(1);
        float width = psize.getHeight();
        float height = psize.getWidth();

        Document document = new Document(new Rectangle(height, width));
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream( output ));

        document.open();

        PdfContentByte cb = writer.getDirectContent();

        int i = 0;
        while (i < n) {
            i++;
            document.newPage();
            PdfImportedPage page = writer.getImportedPage(reader, i);
            cb.addTemplate(page, factor, 0, 0, factor, left, down);
        }

        document.close();
    }
View Full Code Here


        writeChartToPDF(generateBarChart(), 500, 400, "C://barchart.pdf");
        writeChartToPDF(generatePieChart(), 500, 400, "C://piechart.pdf");
    }
    public static void writeChartToPDF(JFreeChart chart, int width, int height, String fileName) {
        PdfWriter writer = null;
    
        Document document = new Document();
    
        try {
            writer = PdfWriter.getInstance(document, new FileOutputStream(
                    fileName));
            document.open();
            PdfContentByte contentByte = writer.getDirectContent();
            PdfTemplate template = contentByte.createTemplate(width, height);
            Graphics2D graphics2d = template.createGraphics(width, height,
                    new DefaultFontMapper());
            Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width,
                    height);
View Full Code Here

    private void storePDF(File target, boolean shapes, int xWidth, int yWidth) {
        this.setBackground(Color.white);
       
        Document document = new Document();
        try {
           PdfWriter writer;
           if (shapes)
              writer = PdfWriter.getInstance(document,
                 new FileOutputStream(target));
           else
              writer = PdfWriter.getInstance(document,
                 new FileOutputStream(target));
           document.open();
           PdfContentByte cb = writer.getDirectContent();
           PdfTemplate tp = cb.createTemplate(xWidth, yWidth);
           Graphics2D g2;
           if (shapes) {
              g2 = tp.createGraphicsShapes(xWidth, yWidth);
           } else {
View Full Code Here

    // IE workaround: write into byte array first.
    ByteArrayOutputStream baos = createTemporaryOutputStream();

    // Apply preferences and build metadata.
    Document document = newDocument();
    PdfWriter writer = newWriter(document, baos);
    prepareWriter(model, writer, request);
    buildPdfMetadata(model, document, request);

    // Build PDF document.
    document.open();
View Full Code Here

        int height,
        FontMapper mapper) throws IOException {
        Rectangle pagesize = new Rectangle(width, height);
        Document document = new Document(pagesize, 50, 50, 50, 50);
        try {
        PdfWriter writer = PdfWriter.getInstance(document, out);
        document.addAuthor("JFreeChart");
        document.addSubject("Demonstration");
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(width, height);
        Graphics2D g2 = tp.createGraphics(width, height, mapper);
        Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height);
        chart.draw(g2, r2D);
        g2.dispose();
View Full Code Here

    public static void savePDF(File filename, JFreeChart chart, int width, int height) {
      try {
      // step 1
        Document document = new Document(new Rectangle(width, height));
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        // step 3
        document.open();
        // step 4
        PdfContentByte canvas = writer.getDirectContent();
        Graphics2D g2 = canvas.createGraphics(width, height);
        Rectangle2D area = new Rectangle2D.Double(0, 0, width, height);
        chart.draw(g2, area);
        g2.dispose();
        // step 5
View Full Code Here

              while (filename.length() < digits) filename = "0" + filename;
              filename = "_" + filename + ".pdf";
              // step 1: creation of a document-object
              document = new Document(reader.getPageSizeWithRotation(pagenumber));
        // step 2: we create a writer that listens to the document
              PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(directory, name + filename)));
              // step 3: we open the document
              document.open();
              PdfContentByte cb = writer.getDirectContent();
        PdfImportedPage page = writer.getImportedPage(reader, pagenumber);
        int rotation = reader.getPageRotation(pagenumber);
        if (rotation == 90 || rotation == 270) {
          cb.addTemplate(page, 0, -1f, 1f, 0, 0, reader.getPageSizeWithRotation(pagenumber).height());
        }
        else {
View Full Code Here

      RandomAccessFileOrArray odd = new RandomAccessFileOrArray(odd_file.getAbsolutePath());
      RandomAccessFileOrArray even = new RandomAccessFileOrArray(even_file.getAbsolutePath());
      Image img = TiffImage.getTiffImage(odd, 1);
      Document document = new Document(new Rectangle(img.scaledWidth(),
          img.scaledHeight()));
      PdfWriter writer = PdfWriter.getInstance(document,
          new FileOutputStream(pdf_file));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      int count = Math.max(TiffImage.getNumberOfPages(odd), TiffImage
          .getNumberOfPages(even));
      for (int c = 0; c < count; ++c) {
        try {
          Image imgOdd = TiffImage.getTiffImage(odd, c + 1);
View Full Code Here

      // step 1: creation of a document-object
      Document document1 = new Document(reader.getPageSizeWithRotation(1));
      Document document2 = new Document(reader.getPageSizeWithRotation(pagenumber));
      // step 2: we create a writer that listens to the document
      PdfWriter writer1 = PdfWriter.getInstance(document1, new FileOutputStream(file1));
      PdfWriter writer2 = PdfWriter.getInstance(document2, new FileOutputStream(file2));
      // step 3: we open the document
      document1.open();
      PdfContentByte cb1 = writer1.getDirectContent();
      document2.open();
      PdfContentByte cb2 = writer2.getDirectContent();
      PdfImportedPage page;
      int rotation;
      int i = 0;
      // step 4: we add content
      while (i < pagenumber - 1) {
        i++;
        document1.setPageSize(reader.getPageSizeWithRotation(i));
        document1.newPage();
        page = writer1.getImportedPage(reader, i);
        rotation = reader.getPageRotation(i);
        if (rotation == 90 || rotation == 270) {
          cb1.addTemplate(page, 0, -1f, 1f, 0, 0, reader.getPageSizeWithRotation(i).height());
        }
        else {
          cb1.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
        }
      }
      while (i < n) {
        i++;
        document2.setPageSize(reader.getPageSizeWithRotation(i));
        document2.newPage();
        page = writer2.getImportedPage(reader, i);
        rotation = reader.getPageRotation(i);
        if (rotation == 90 || rotation == 270) {
          cb2.addTemplate(page, 0, -1f, 1f, 0, 0, reader.getPageSizeWithRotation(i).height());
        }
        else {
View Full Code Here

            int r = (int)Math.pow(2, (int)pow2 / 2);
            int c = n / r;
      // step 1: creation of a document-object
      Document document = new Document(newSize, 0, 0, 0, 0);
      // step 2: we create a writer that listens to the document
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
      // step 3: we open the document
      document.open();
      // step 4: adding the content
      PdfContentByte cb = writer.getDirectContent();
      PdfImportedPage page;
      float offsetX, offsetY, factor;
      int p;
      for (int i = 0; i < total; i++) {
        if (i % n == 0) {
          document.newPage();
        }
        p = i + 1;
        offsetX = unitSize.width() * ((i % n) % c);
        offsetY = newSize.height() - (unitSize.height() * (((i % n) / c) + 1));
        currentSize = reader.getPageSize(p);
        factor = Math.min(unitSize.width() / currentSize.width(), unitSize.height() / currentSize.height());
        offsetX += (unitSize.width() - (currentSize.width() * factor)) / 2f;
        offsetY += (unitSize.height() - (currentSize.height() * factor)) / 2f;
        page = writer.getImportedPage(reader, p);
        cb.addTemplate(page, factor, 0, 0, factor, offsetX, offsetY);
      }
      // step 5: we close the document
      document.close();
        }
View Full Code Here

TOP

Related Classes of com.lowagie.text.pdf.PdfWriter

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.