Examples of LwgDocument


Examples of com.lowagie.text.LwgDocument

  
   protected void _execute(File[] flesIn, String[] strsLabel)
   {
      try
      {
         LwgDocument document = new LwgDocument();

         PdfWriter writer = PdfWriter.getInstance(document,
                     new FileOutputStream(this._strPathAbsOut));

         writer.setViewerPreferences(PdfWriter.PageModeUseThumbs);
         PdfPageLabels pageLabels = new PdfPageLabels();
        
         for (int i=0; i<flesIn.length; i++)
         {
            System.out.println("Testing image: " + flesIn[i].getName());
           
            LwgImage img = LwgImage.getInstance(flesIn[i].getAbsolutePath());
            String caption = "";

            int intDpiX = img.getDpiX();

            if (intDpiX == 0)
               intDpiX = GfrPdfPhotoAlbumFromAbs._INT_DEFAULT_DPI_;


            int intDpiY = img.getDpiY();

            if (intDpiY == 0)
               intDpiY = GfrPdfPhotoAlbumFromAbs._INT_DEFAULT_DPI_;

            float fltImgWidthPica = (GfrPdfPhotoAlbumFromAbs._INT_DEFAULT_DPI_ * img.getPlainWidth()) / intDpiX;
            float fltImgHeightPica = (GfrPdfPhotoAlbumFromAbs._INT_DEFAULT_DPI_ * img.getPlainHeight()) / intDpiY;
            img.scaleAbsolute(fltImgWidthPica, fltImgHeightPica);

            document.setPageSize(new LwgRectangle(fltImgWidthPica, fltImgHeightPica));

            if (document.isOpen())
            {
               document.newPage();
            }

            else
            {
               document.open();
            }

            img.setAbsolutePosition(0, 0);
            document.add(img);

            BaseFont bf = BaseFont.createFont("Helvetica",
                     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]);
         }
        
         if (document.isOpen())
         {
            writer.setPageLabels(pageLabels);
            document.close();
         } // ??? else ???
      }
     
      catch(Exception exc)
      {
View Full Code Here

Examples of com.lowagie.text.LwgDocument

                        "You need to choose a destination file");
            }
            File pdf_file = (File) getValue("destfile");
            int pageOffset = 0;
            ArrayList<HashMap<String, Object>> master = new ArrayList<HashMap<String, Object>>();
            LwgDocument document = null;
            PdfCopy writer = null;
            for (int i = 0; i < files.length; i++) {
                // we create a reader for a certain document
                PdfReader reader = new PdfReader(files[i].getAbsolutePath());
                reader.consolidateNamedDestinations();
                // we retrieve the total number of pages
                int n = reader.getNumberOfPages();
                List<HashMap<String, Object>> bookmarks = SimpleBookmark.getBookmark(reader);
                if (bookmarks != null) {
                    if (pageOffset != 0) {
                        SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null);
                    }
                    master.addAll(bookmarks);
                }
                pageOffset += n;
                System.out.println("There are " + n + " pages in " + files[i]);
                if (i == 0) {
                    // step 1: creation of a document-object
                    document = new LwgDocument(reader.getPageSizeWithRotation(1));
                    // step 2: we create a writer that listens to the document
                    writer = new PdfCopy(document,
                                         new FileOutputStream(pdf_file));
                    // step 3: we open the document
                    document.open();
                }
                // step 4: we add content
                PdfImportedPage page;
                for (int p = 0; p < n; ) {
                    ++p;
                    page = writer.getImportedPage(reader, p);
                    writer.addPage(page);
                    System.out.println("Processed page " + p);
                }
            }
            if (!master.isEmpty()) {
                writer.setOutlines(master);
            }
            // step 5: we close the document
            document.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

Examples of com.lowagie.text.LwgDocument

      PdfReader reader = new PdfReader(src.getAbsolutePath());
      // we retrieve the total number of pages
      int n = reader.getNumberOfPages();
      int digits = 1 + (n / 10);
      System.out.println("There are " + n + " pages in the original file.");
      LwgDocument document;
      int pagenumber;
      String filename;
            for (int i = 0; i < n; i++) {
              pagenumber = i + 1;
              filename = String.valueOf(pagenumber);
              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 {
          cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
        }
        // step 5: we close the document
        document.close();
      }
        }
        catch(Exception e) {
            e.printStackTrace();
        }
View Full Code Here

Examples of com.lowagie.text.LwgDocument

      LwgRectangle pageSize = reader.getPageSize(1);
      LwgRectangle newSize = new LwgRectangle(pageSize.getWidth() / 2, pageSize
          .getHeight());
      // 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;
      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) {
      e.printStackTrace();
    }
  }
View Full Code Here

Examples of com.lowagie.text.LwgDocument

        if (pagenumber < 2 || pagenumber > n) {
          throw new DocumentException(MessageLocalization.getComposedMessage("you.can.t.split.this.document.at.page.1.there.is.no.such.page", pagenumber));
        }
               
        // step 1: creation of a document-object
        LwgDocument document1 = new LwgDocument(reader.getPageSizeWithRotation(1));
        LwgDocument document2 = new LwgDocument(reader.getPageSizeWithRotation(pagenumber));
        // 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();
        document2.close();
            }
            catch(Exception e) {
                e.printStackTrace();
            }
        }
View Full Code Here

Examples of com.lowagie.text.LwgDocument

            }
            int n = (int)Math.pow(2, pow2);
            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();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

Examples of com.lowagie.text.LwgDocument

            try {
                int pageOffset = 0;
                ArrayList master = new ArrayList();
                int f = 0;
                String outFile = args[args.length-1];
                LwgDocument document = null;
                PdfCopy  writer = null;
                while (f < args.length-1) {
                    // we create a reader for a certain document
                    PdfReader reader = new PdfReader(args[f]);
                    reader.consolidateNamedDestinations();
                    // we retrieve the total number of pages
                    int n = reader.getNumberOfPages();
                    List bookmarks = SimpleBookmark.getBookmark(reader);
                    if (bookmarks != null) {
                        if (pageOffset != 0)
                            SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null);
                        master.addAll(bookmarks);
                    }
                    pageOffset += n;
                    System.out.println("There are " + n + " pages in " + args[f]);
                   
                    if (f == 0) {
                        // step 1: creation of a document-object
                        document = new LwgDocument(reader.getPageSizeWithRotation(1));
                        // step 2: we create a writer that listens to the document
                        writer = new PdfCopy(document, new FileOutputStream(outFile));
                        // step 3: we open the document
                        document.open();
                    }
                    // step 4: we add content
                    PdfImportedPage page;
                    for (int i = 0; i < n; ) {
                        ++i;
                        page = writer.getImportedPage(reader, i);
                        writer.addPage(page);
                        System.out.println("Processed page " + i);
                    }
                    writer.freeReader(reader);
                    f++;
                }
                if (!master.isEmpty())
                    writer.setOutlines(master);
                // step 5: we close the document
                document.close();
            }
            catch(Exception e) {
                e.printStackTrace();
            }
        }
View Full Code Here

Examples of com.lowagie.text.LwgDocument

        // we retrieve the total number of pages
        int n = reader.getNumberOfPages();
        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 {
            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();
          }
        }
        // step 5: we close the document
        document.close();
      }
      catch(Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
      }
    }
View Full Code Here

Examples of com.lowagie.text.LwgDocument

    public void execute() {
        try {
            // step 1: creation of a document-object
            LwgRectangle pageSize = new LwgRectangle(780, 525);
            if (getValue("backgroundcolor") != null) pageSize.setBackgroundColor((Color)getValue("backgroundcolor"));
            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);
              }
              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);
            }
            if (getValue("back") != null) {
              LwgImage back = (LwgImage)getValue("back");
              back.scaleToFit(370, 525);
              back.setAbsolutePosition((370f - back.getScaledWidth()) / 2f, (525f - back.getScaledHeight()) / 2f);
              document.add(back);
            }
            if (getValue("side") != null) {
              LwgImage side = (LwgImage)getValue("side");
              side.scaleToFit(40, 525);
              side.setAbsolutePosition(370 + (40f - side.getScaledWidth()) / 2f, (525f - side.getScaledHeight()) / 2f);
              document.add(side);
            }

            // step 5: we close the document
            document.close();
        }
        catch(Exception e) {
          JOptionPane.showMessageDialog(internalFrame,
                e.getMessage(),
                e.getClass().getName(),
View Full Code Here

Examples of com.lowagie.text.LwgDocument

     */
    public static void main(String[] args) {
       
        System.out.println("Using newPage()");       
        // step 1: creation of a document-object
        LwgDocument document = new LwgDocument();
       
        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("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();
            document.add(new Paragraph("You can also add something invisible if you want a blank page."));
            document.add(Chunk.NEXTPAGE);
            document.add(new Paragraph("Using Chunk.NEXTPAGE also jumps to the next page"));
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
       
        // step 5: we close the document
        document.close();
    }
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.