Examples of PdfContentByte


Examples of com.lowagie.text.pdf.PdfContentByte

                     BaseFont.WINANSI,
                     false);

            PdfGState gs1 = new PdfGState();
            gs1.setBlendMode(PdfGState.BM_OVERLAY);
            PdfContentByte cb = writer.getDirectContent();
            cb.saveState();
            cb.setGState(gs1);
            cb.beginText();
            cb.setFontAndSize(bf, 40);
            cb.setTextMatrix(50, 50);
            cb.showText(caption);
            cb.endText();
            cb.restoreState();

            pageLabels.addPageLabel(writer.getPageNumber(),
                                    PdfPageLabels.EMPTY, strsLabel[i]);

            System.out.println("Added image: " + strsLabel[i]);
View Full Code Here

Examples of com.lowagie.text.pdf.PdfContentByte

              document = new LwgDocument(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).getHeight());
        }
        else {
          cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
        }
        // step 5: we close the document
        document.close();
      }
        }
View Full Code Here

Examples of com.lowagie.text.pdf.PdfContentByte

      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;
      int p;
      for (int i = 0; i < total; i++) {
        p = i + 1;
        pageSize = reader.getPageSize(p);
        newSize = new LwgRectangle(pageSize.getWidth() / 2, pageSize.getHeight());

        document.newPage();
        offsetX = 0;
        offsetY = 0;
        page = writer.getImportedPage(reader, p);
        cb.addTemplate(page, 1, 0, 0, 1, offsetX, offsetY);
        document.newPage();
        offsetX = -newSize.getWidth();
        offsetY = 0;
        page = writer.getImportedPage(reader, p);
        cb.addTemplate(page, 1, 0, 0, 1, offsetX, offsetY);

      }
      // step 5: we close the document
      document.close();
    } catch (Exception e) {
View Full Code Here

Examples of com.lowagie.text.pdf.PdfContentByte

        // step 2: we create a writer that listens to the document
        PdfWriter writer1 = PdfWriter.getInstance(document1, new FileOutputStream(args[1]));
        PdfWriter writer2 = PdfWriter.getInstance(document2, new FileOutputStream(args[2]));
        // 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).getHeight());
          }
          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).getHeight());
          }
          else {
            cb2.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
          }
          System.out.println("Processed page " + i);
        }
        // step 5: we close the document
        document1.close();
View Full Code Here

Examples of com.lowagie.text.pdf.PdfContentByte

      // 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.getWidth() * ((i % n) % c);
        offsetY = newSize.getHeight() - (unitSize.getHeight() * (((i % n) / c) + 1));
        currentSize = reader.getPageSize(p);
        factor = Math.min(unitSize.getWidth() / currentSize.getWidth(), unitSize.getHeight() / currentSize.getHeight());
        offsetX += (unitSize.getWidth() - (currentSize.getWidth() * factor)) / 2f;
        offsetY += (unitSize.getHeight() - (currentSize.getHeight() * factor)) / 2f;
        page = writer.getImportedPage(reader, p);
        cb.addTemplate(page, factor, 0, 0, factor, offsetX, offsetY);
      }
      // step 5: we close the document
      document.close();
        }
        catch(Exception e) {
View Full Code Here

Examples of com.lowagie.text.pdf.PdfContentByte

        LwgDocument document = new LwgDocument(LwgPageSize.A4);
        // step 2: we create a writer that listens to the document
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(args[1]));
        // step 3: we open the document
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        PdfImportedPage page;
        int rotation;
        int i = 0;
        int p = 0;
        // step 4: we add content
        while (i < n) {
          i++;
          LwgRectangle rect = reader.getPageSizeWithRotation(i);
          float factorx = (x2 - x1) / rect.getWidth();
          float factory = (y1[p] - y2[p]) / rect.getHeight();
          float factor = (factorx < factory ? factorx : factory);
          float dx = (factorx == factor ? 0f : ((x2 - x1) - rect.getWidth() * factor) / 2f);
          float dy = (factory == factor ? 0f : ((y1[p] - y2[p]) - rect.getHeight() * factor) / 2f);
          page = writer.getImportedPage(reader, i);
          rotation = reader.getPageRotation(i);
          if (rotation == 90 || rotation == 270) {
            cb.addTemplate(page, 0, -factor, factor, 0, x1 + dx, y2[p] + dy + rect.getHeight() * factor);
          }
          else {
            cb.addTemplate(page, factor, 0, 0, factor, x1 + dx, y2[p] + dy);
          }
          cb.setRGBColorStroke(0xC0, 0xC0, 0xC0);
          cb.rectangle(x3 - 5f, y2[p] - 5f, x4 - x3 + 10f, y1[p] - y2[p] + 10f);
          for (float l = y1[p] - 19; l > y2[p]; l -= 16) {
            cb.moveTo(x3, l);
            cb.lineTo(x4, l);
          }
          cb.rectangle(x1 + dx, y2[p] + dy, rect.getWidth() * factor, rect.getHeight() * factor);
          cb.stroke();
          System.out.println("Processed page " + i);
          p++;
          if (p == pages) {
            p = 0;
            document.newPage();
View Full Code Here

Examples of com.lowagie.text.pdf.PdfContentByte

            // step 3: we open the document
            document.open();

            // step 4:
          PdfContentByte cb = writer.getDirectContent();
            if (getValue("title") != null) {
              cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false), 24);
              cb.beginText();
              if (getValue("front") == null) {
                cb.showTextAligned(LwgElement.ALIGN_CENTER, (String)getValue("title"), 595f, 262f, 0f);
              }
              if (getValue("side") == null) {
                cb.showTextAligned(LwgElement.ALIGN_CENTER, (String)getValue("title"), 385f, 262f, 270f);
              }
              cb.endText();
            }
            cb.moveTo(370, 0);
            cb.lineTo(370, 525);
            cb.moveTo(410, 525);
            cb.lineTo(410, 0);
            cb.stroke();
            if (getValue("front") != null) {
              LwgImage front = (LwgImage)getValue("front");
              front.scaleToFit(370, 525);
              front.setAbsolutePosition(410f + (370f - front.getScaledWidth()) / 2f, (525f - front.getScaledHeight()) / 2f);
              document.add(front);
View Full Code Here

Examples of com.lowagie.text.pdf.PdfContentByte

         float fltHeight)
   {
         int width = (int)(fltWidth);
         int height = (int)(fltHeight);
         // step 4
         PdfContentByte cb = writer.getDirectContent();

         PdfTemplate tp = cb.createTemplate(width, height);

         Graphics2D g2d = tp.createGraphics(width, height, new DefaultFontMapper());

         Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height);

         chart.draw(g2d, r2d);
         g2d.dispose();

         tp.sanityCheck();
         cb.addTemplate(tp, fltX, fltY);
         cb.sanityCheck();
     
   }
View Full Code Here

Examples of com.lowagie.text.pdf.PdfContentByte

            writer.setPdfVersion(PdfWriter.VERSION_1_5);
            writer.setViewerPreferences(PdfWriter.PageModeUseOC);
            // step 3
            document.open();
            // step 4
            PdfContentByte cb = writer.getDirectContent();
            LwgPhrase explanation = new LwgPhrase("Layer radio group and zoom", new LwgFont(LwgFont.HELVETICA, 20, LwgFont.BOLD, Color.red));
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, explanation, 50, 650, 0);
            PdfLayer title = PdfLayer.createTitle("Layer radio group", writer);
            PdfLayer l1 = new PdfLayer("Layer 1", writer);
            PdfLayer l2 = new PdfLayer("Layer 2", writer);
            PdfLayer l3 = new PdfLayer("Layer 3", writer);
            PdfLayer l4 = new PdfLayer("Layer 4", writer);
            title.addChild(l1);
            title.addChild(l2);
            title.addChild(l3);
            l4.setZoom(2, -1);
            l4.setOnPanel(false);
            l4.setPrint("Print", true);
            l2.setOn(false);
            l3.setOn(false);
            ArrayList radio = new ArrayList();
            radio.add(l1);
            radio.add(l2);
            radio.add(l3);
            writer.addOCGRadioGroup(radio);
            LwgPhrase p1 = new LwgPhrase("Text in layer 1");
            LwgPhrase p2 = new LwgPhrase("Text in layer 2");
            LwgPhrase p3 = new LwgPhrase("Text in layer 3");
            LwgPhrase p4 = new LwgPhrase("Text in layer 4");
            cb.beginLayer(l1);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p1, 50, 600, 0);
            cb.endLayer();
            cb.beginLayer(l2);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p2, 50, 550, 0);
            cb.endLayer();
            cb.beginLayer(l3);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p3, 50, 500, 0);
            cb.endLayer();
            cb.beginLayer(l4);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p4, 50, 450, 0);
            cb.endLayer();
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, new LwgPhrase("<< Zoom here!", new LwgFont(LwgFont.COURIER, 12, LwgFont.NORMAL, Color.blue)), 150, 450, 0);
            // step 5
            document.close();
        }
        catch(Exception de) {
View Full Code Here

Examples of com.lowagie.text.pdf.PdfContentByte

    /**
     * @see com.lowagie.text.pdf.PdfPageEventHelper#onStartPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
     */
    public void onStartPage(PdfWriter writer, LwgDocument document) {
        if (writer.getPageNumber() < 3) {
            PdfContentByte cb = writer.getDirectContentUnder();
            cb.saveState();
            cb.setColorFill(Color.pink);
            cb.beginText();
            cb.setFontAndSize(helv, 48);
            cb.showTextAligned(LwgElement.ALIGN_CENTER, "My Watermark Under " + writer.getPageNumber(), document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45);
            cb.endText();
            cb.restoreState();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.