Package com.lowagie.text

Examples of com.lowagie.text.LwgRectangle


            PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(
                    (File) getValue("destfile")));
            float txtwidth = bf.getWidthPoint(text, fontsize);
            for (int i = 1; i <= pagecount; i++) {
                PdfContentByte seitex = stamp.getOverContent(i);
                LwgRectangle recc = reader.getCropBox(i);
                float winkel = (float) Math.atan(recc.getHeight() /
                                                 recc.getWidth());
                float m1 = (float) Math.cos(winkel);
                float m2 = (float) - Math.sin(winkel);
                float m3 = (float) Math.sin(winkel);
                float m4 = (float) Math.cos(winkel);
                float xoff = (float) ( -Math.cos(winkel) * txtwidth / 2 - Math
                                      .sin(winkel)
                                      * fontsize / 2);
                float yoff = (float) (Math.sin(winkel) * txtwidth / 2 - Math
                                      .cos(winkel)
                                      * fontsize / 2);
                seitex.saveState();
                seitex.setGState(gs1);
                seitex.beginText();
                seitex.setFontAndSize(bf, fontsize);
                seitex.setTextMatrix(m1, m2, m3, m4, xoff + recc.getWidth() / 2,
                                     yoff + recc.getHeight() / 2);
                seitex.showText(text);
                seitex.endText();
                seitex.restoreState();
            }
            stamp.close();
View Full Code Here


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

                        dpiY = 72;
                    }
                    imgWidthPica = (72 * img.getPlainWidth()) / dpiX;
                    imgHeightPica = (72 * img.getPlainHeight()) / dpiY;
                    img.scaleAbsolute(imgWidthPica, imgHeightPica);
                    document.setPageSize(new LwgRectangle(imgWidthPica,
                            imgHeightPica));
                    if (document.isOpen()) {
                        document.newPage();
                    } else {
                        document.open();
View Full Code Here

      if ("ORIGINAL".equals(getValue("pagesize"))) {
        LwgImage img = TiffImage.getTiffImage(ra, 1);
                if (img.getDpiX() > 0 && img.getDpiY() > 0) {
                    img.scalePercent(7200f / img.getDpiX(), 7200f / img.getDpiY());
                }
        document.setPageSize(new LwgRectangle(img.getScaledWidth(), img.getScaledHeight()));
        adjustSize = true;
      }
      else if ("LETTER".equals(getValue("pagesize"))) {
        document.setPageSize(LwgPageSize.LETTER);
                width = LwgPageSize.LETTER.getWidth() - 40;
                height = LwgPageSize.LETTER.getHeight() - 120;
      }
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdf_file));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
            for (int c = 0; c < comps; ++c) {
                LwgImage img = TiffImage.getTiffImage(ra, c + 1);
                if (img != null) {
                    if (img.getDpiX() > 0 && img.getDpiY() > 0) {
                        img.scalePercent(7200f / img.getDpiX(), 7200f / img.getDpiY());
                    }
                  if (adjustSize) {
              document.setPageSize(new LwgRectangle(img.getScaledWidth(),
                  img.getScaledHeight()));
                        document.newPage();
                    img.setAbsolutePosition(0, 0);
                  }
                  else {
View Full Code Here

        if (isDocumentRoot(name)) {
            String key;
            String value;
            // pagesize and orientation specific code suggested by Samuel Gabriel
            // Updated by Ricardo Coutinho. Only use if set in html!
      LwgRectangle pageSize = null;
      String orientation = null;
            for (Iterator i = attributes.keySet().iterator(); i.hasNext();) {
                key = (String) i.next();
                value = attributes.getProperty(key);
                try {
                    // margin specific code suggested by Reza Nasiri
                    if (ElementTags.LEFT.equalsIgnoreCase(key))
                        leftMargin = Float.parseFloat(value + "f");
                    if (ElementTags.RIGHT.equalsIgnoreCase(key))
                        rightMargin = Float.parseFloat(value + "f");
                    if (ElementTags.TOP.equalsIgnoreCase(key))
                        topMargin = Float.parseFloat(value + "f");
                    if (ElementTags.BOTTOM.equalsIgnoreCase(key))
                        bottomMargin = Float.parseFloat(value + "f");
                } catch (Exception ex) {
                    throw new ExceptionConverter(ex);
                }
                if (ElementTags.PAGE_SIZE.equals(key)) {
                    try {
                        String pageSizeName = value;
                        Field pageSizeField = LwgPageSize.class
                                .getField(pageSizeName);
                        pageSize = (LwgRectangle) pageSizeField.get(null);
                    } catch (Exception ex) {
                        throw new ExceptionConverter(ex);
                    }
                } else if (ElementTags.ORIENTATION.equals(key)) {
                    try {
                        if ("landscape".equals(value)) {
                            orientation = "landscape";
                        }
                    } catch (Exception ex) {
                        throw new ExceptionConverter(ex);
                    }
                } else {
                    try {
                        document.add(new Meta(key, value));
                    } catch (DocumentException de) {
                        throw new ExceptionConverter(de);
                    }
                }
            }
            if(pageSize != null) {
              if ("landscape".equals(orientation)) {
                pageSize = pageSize.rotate();
              }
              document.setPageSize(pageSize);
            }
            document.setMargins(leftMargin, rightMargin, topMargin,
                    bottomMargin);
View Full Code Here

  public void execute() {
    try {
            String line = null;
            LwgDocument document;
            LwgFont f;
            LwgRectangle pagesize = (LwgRectangle)getValue("pagesize");
            if ("LANDSCAPE".equals(getValue("orientation"))) {
                f = FontFactory.getFont(FontFactory.COURIER, 10);
                document = new LwgDocument(pagesize.rotate(), 36, 9, 36, 36);
            }
            else {
                f = FontFactory.getFont(FontFactory.COURIER, 11);
                document = new LwgDocument(pagesize, 72, 36, 36, 36);
            }
View Full Code Here

      if (getValue("destfile") == null) throw new InstantiationException("You need to choose a destination file");
      File pdf_file = (File)getValue("destfile");
      RandomAccessFileOrArray odd = new RandomAccessFileOrArray(odd_file.getAbsolutePath());
      RandomAccessFileOrArray even = new RandomAccessFileOrArray(even_file.getAbsolutePath());
      LwgImage img = TiffImage.getTiffImage(odd, 1);
      LwgDocument document = new LwgDocument(new LwgRectangle(img.getScaledWidth(),
          img.getScaledHeight()));
      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 {
          LwgImage imgOdd = TiffImage.getTiffImage(odd, c + 1);
          LwgImage imgEven = TiffImage.getTiffImage(even, count - c);
          document.setPageSize(new LwgRectangle(imgOdd.getScaledWidth(),
              imgOdd.getScaledHeight()));
          document.newPage();
          imgOdd.setAbsolutePosition(0, 0);
          cb.addImage(imgOdd);
          document.setPageSize(new LwgRectangle(imgEven.getScaledWidth(),
              imgEven.getScaledHeight()));
          document.newPage();
          imgEven.setAbsolutePosition(0, 0);
          cb.addImage(imgEven);
View Full Code Here

         int width,
         int height,
         String strPathAbsoluteFile)
   {
      // step 1
      LwgDocument document = new LwgDocument(new LwgRectangle(width, height));
      try
      {
         // step 2
         PdfWriter writer;
         writer = PdfWriter.getInstance(document, new FileOutputStream(strPathAbsoluteFile));
View Full Code Here

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

      // we retrieve the total number of pages and the page size
      int total = reader.getNumberOfPages();
      System.out.println("There are " + total
          + " pages in the original file.");

      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);

      }
View Full Code Here

TOP

Related Classes of com.lowagie.text.LwgRectangle

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.