Examples of PdfWriter


Examples of com.lowagie.text.pdf.PdfWriter

              while (filename.length() < digits) filename = "0" + filename;
              filename = "_" + filename + ".pdf";
              // step 1: creation of a document-object
              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 {
View Full Code Here

Examples of com.lowagie.text.pdf.PdfWriter

            int r = (int)Math.pow(2, pow2 / 2);
            int c = n / r;
      // step 1: creation of a document-object
      LwgDocument document = new LwgDocument(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.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();
        }
View Full Code Here

Examples of com.lowagie.text.pdf.PdfWriter

        System.out.println("There are " + n + " pages in the original file.");
               
        // step 1: creation of a document-object
        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 {
View Full Code Here

Examples of com.lowagie.text.pdf.PdfWriter

            LwgDocument document = new LwgDocument(pageSize);
            // step 2:
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file
          if (getValue("destfile") == null) throw new DocumentException("You must provide a destination file!");
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream((File)getValue("destfile")));

            // 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);
View Full Code Here

Examples of com.lowagie.text.pdf.PdfWriter

      System.out.println("layer radio group and zoom");
        try {
          // step 1
            LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
            // step 2
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("layers.pdf"));
            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);
View Full Code Here

Examples of com.lowagie.text.pdf.PdfWriter

        try {
           
            // step 2:
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("spotcolor.pdf"));
            BaseFont bf = BaseFont.createFont("Helvetica", "winansi", BaseFont.NOT_EMBEDDED);
           
            // step 3: we open the document
            document.open();
           
            // step 4: we grab the ContentByte and do some stuff with it
            PdfContentByte cb = writer.getDirectContent();
           
            // step 5: we instantiate PdfSpotColor
           
            // Note: I made up these names unless someone give me a PANTONE swatch as gift (phillip@formstar.com)
            PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV", new CMYKColor(0.9f, .2f, .3f, .1f));
View Full Code Here

Examples of com.lowagie.text.pdf.PdfWriter

    public static void main(String args[]) {
        try {
          // step 1: creating the document
            LwgDocument doc = new LwgDocument(LwgPageSize.A4, 50, 50, 100, 72);
            // step 2: creating the writer
            PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("pageNumbersWatermark.pdf"));
            // step 3: initialisations + opening the document
            writer.setPageEvent(new PageNumbersWatermark());
            doc.open();
            // step 4: adding content
            String text = "some padding text ";
            for (int k = 0; k < 10; ++k)
                text += text;
View Full Code Here

Examples of com.lowagie.text.pdf.PdfWriter

     */
    public static void main(String[] args)
    {
        LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 70, 70);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("endpage.pdf"));
            writer.setPageEvent(new EndPage());
            document.open();
            String text = "Lots of text. ";
            for (int k = 0; k < 10; ++k)
                text += text;
            document.add(new Paragraph(text));
View Full Code Here

Examples of com.lowagie.text.pdf.PdfWriter

           
            // step 2:
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file
           
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("NewPage.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4:
            document.add(new Paragraph("This is the first page."));
            document.newPage();
            document.add(new Paragraph("This is a new page"));
            document.newPage();
            document.newPage();
            document.add(new Paragraph("We invoked new page twice, yet there was no blank page added. Between the second page and this one. This is normal behaviour."));
            document.newPage();
            writer.setPageEmpty(false);
            document.newPage();
            document.add(new Paragraph("We told the writer the page wasn't empty."));
            document.newPage();
            document.add(Chunk.NEWLINE);
            document.newPage();
View Full Code Here

Examples of com.lowagie.text.pdf.PdfWriter

    System.out.println("Transparency Groups");
        // step 1: creation of a document-object
        LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
        try {
            // step 2: creation of a writer
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("groups.pdf"));
            // step 3: we open the document
            document.open();
            // step 4: content
            PdfContentByte cb = writer.getDirectContent();
            float gap = (document.getPageSize().getWidth() - 400) / 3;
           
            pictureBackdrop(gap, 500, cb);
            pictureBackdrop(200 + 2 * gap, 500, cb);
            pictureBackdrop(gap, 500 - 200 - gap, cb);
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.