Examples of LwgRectangle


Examples of com.lowagie.text.LwgRectangle

      // we create a reader for a certain document
      PdfReader reader = new PdfReader(src.getAbsolutePath());
      // 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 = (pow2 % 2) == 0 ? new LwgRectangle(pageSize.getWidth(), pageSize.getHeight()) : new LwgRectangle(pageSize.getHeight(), pageSize.getWidth());
            LwgRectangle unitSize = new LwgRectangle(pageSize.getWidth(), pageSize.getHeight());
            LwgRectangle currentSize;
            for (int i = 0; i < pow2; i++) {
              unitSize = new LwgRectangle(unitSize.getHeight() / 2, unitSize.getWidth());
            }
            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();
View Full Code Here

Examples of com.lowagie.text.LwgRectangle

        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

Examples of com.lowagie.text.LwgRectangle

     * @see com.lowagie.toolbox.AbstractTool#execute()
     */
    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!");
View Full Code Here

Examples of com.lowagie.text.LwgRectangle

     */
    public static void main(String[] args) {
       
        System.out.println("Measurements");       
        // step 1: creation of a document-object
        LwgRectangle pageSize = new LwgRectangle(288, 720);
        LwgDocument document = new LwgDocument(pageSize, 36, 18, 72, 72);
       
        try {
           
            // step 2:
View Full Code Here

Examples of com.lowagie.text.LwgRectangle

    /**
     * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
     */
    public void onEndPage(PdfWriter writer, LwgDocument document) {
        try {
            LwgRectangle page = document.getPageSize();
            LwgPdfPTable head = new LwgPdfPTable(3);
            for (int k = 1; k <= 6; ++k)
                head.add("head " + k);
            head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(),
                writer.getDirectContent());
            LwgPdfPTable foot = new LwgPdfPTable(3);
            for (int k = 1; k <= 6; ++k)
                foot.add("foot " + k);
            foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
        }
        catch (Exception e) {
            throw new ExceptionConverter(e);
View Full Code Here

Examples of com.lowagie.text.LwgRectangle

    public void setBox(LwgRectangle box) {
      if (box == null) {
        this.box = null;
      }
      else {
        this.box = new LwgRectangle(box);
        this.box.normalize();
      }
    }
View Full Code Here

Examples of com.lowagie.text.LwgRectangle

      document.add(table);
      widths[0] = 40f;
      widths[1] = 40f;
      widths[2] = 20f;
      widths[3] = 300f;
      LwgRectangle r = new LwgRectangle(LwgPageSize.A4.getRight(72), LwgPageSize.A4.getTop(72));
      table.setWidthPercentage(widths, r);
      document.add(new Paragraph("We change the percentage using absolute widths:\n\n"));
      document.add(table);
      document.add(new Paragraph("We use a locked width:\n\n"));
      table.setTotalWidth(300);
View Full Code Here

Examples of com.lowagie.text.LwgRectangle

            gstate = new PdfGState();
            gstate.setFillOpacity(0.3f);
            gstate.setStrokeOpacity(0.3f);
            // initialization of the template
            tpl = writer.getDirectContent().createTemplate(100, 100);
            tpl.setBoundingBox(new LwgRectangle(-20, -20, 100, 100));
            // initialization of the font
            helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false);
        }
        catch(Exception e) {
            throw new ExceptionConverter(e);
View Full Code Here

Examples of com.lowagie.text.LwgRectangle

        }
        int narrow = bars.length - wide;
        float fullWidth = x * (narrow + wide * n);
        fullWidth = Math.max(fullWidth, fontX);
        float fullHeight = barHeight + fontY;
        return new LwgRectangle(fullWidth, fullHeight);
    }
View Full Code Here

Examples of com.lowagie.text.LwgRectangle

      document.open();
      // step 4:
      PdfContentByte cb = writer.getDirectContent();
      // page 1
            PdfFileSpecification fs = PdfFileSpecification.fileExtern(writer, "cards.mpg");
            writer.addAnnotation(PdfAnnotation.createScreen(writer, new LwgRectangle(200f, 700f, 300f, 800f), "cards.mpg",fs,"video/mpeg",true));
      PdfAnnotation a = new PdfAnnotation(writer, 200f, 550f, 300f, 650f,
          PdfAction.javaScript("app.alert('Hello');\r", writer));
      document.add(new Chunk("click to trigger javascript").setAnnotation(a).setLocalDestination("top"));
      writer.addAnnotation(a);
      writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new LwgRectangle(100f, 650f, 150f, 700f), "This is some text", "some text".getBytes(), null, "some.txt"));
      writer.addAnnotation(PdfAnnotation.createText(writer, new LwgRectangle(200f, 400f, 300f, 500f), "Help", "This Help annotation was made with 'createText'", false, "Help"));
      writer.addAnnotation(PdfAnnotation.createText(writer, new LwgRectangle(200f, 250f, 300f, 350f), "Help", "This Comment annotation was made with 'createText'", true, "Comment"));
      cb.rectangle(200, 700, 100, 100);
      cb.rectangle(200, 550, 100, 100);
      cb.rectangle(200, 400, 100, 100);
      cb.rectangle(200, 250, 100, 100);
      cb.stroke();
      document.newPage();
      // page 2
      writer.addAnnotation(PdfAnnotation.createLink(writer, new LwgRectangle(200f, 700f, 300f, 800f), PdfAnnotation.HIGHLIGHT_TOGGLE, PdfAction.javaScript("app.alert('Hello');\r", writer)));
      writer.addAnnotation(PdfAnnotation.createLink(writer, new LwgRectangle(200f, 550f, 300f, 650f), PdfAnnotation.HIGHLIGHT_OUTLINE, "top"));
      writer.addAnnotation(PdfAnnotation.createLink(writer, new LwgRectangle(200f, 400f, 300f, 500f), PdfAnnotation.HIGHLIGHT_PUSH, 1, new PdfDestination(PdfDestination.FIT)));
      writer.addAnnotation(PdfAnnotation.createSquareCircle(writer, new LwgRectangle(200f, 250f, 300f, 350f), "This Comment annotation was made with 'createSquareCircle'", false));
      document.newPage();
      // page 3
      PdfContentByte pcb = new PdfContentByte(writer);
      pcb.setColorFill(new Color(0xFF, 0x00, 0x00));
      writer.addAnnotation(PdfAnnotation.createFreeText(writer, new LwgRectangle(200f, 700f, 300f, 800f), "This is some free text, blah blah blah", pcb));
      writer.addAnnotation(PdfAnnotation.createLine(writer, new LwgRectangle(200f, 550f, 300f, 650f), "this is a line", 200, 550, 300, 650));
      writer.addAnnotation(PdfAnnotation.createStamp(writer, new LwgRectangle(200f, 400f, 300f, 500f), "This is a stamp", "Stamp"));
      writer.addAnnotation(PdfAnnotation.createPopup(writer, new LwgRectangle(200f, 250f, 300f, 350f), "Hello, I'm a popup!", true));
      cb.rectangle(200, 700, 100, 100);
      cb.rectangle(200, 550, 100, 100);
      cb.rectangle(200, 250, 100, 100);
      cb.stroke();
     
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.