Package com.itextpdf.text

Examples of com.itextpdf.text.Rectangle


                width *= INCH;
                height *= INCH;
            }
            float w = (float) width;
            float h = (float) height;
            Rectangle rect = new Rectangle(w, h);
            pdfExporter.setPageSize(rect);
        } else {
            pdfExporter.setPageSize(((PageSizeItem) pageSizeCombo.getSelectedItem()).getPageSize());
        }

View Full Code Here


            }
        }

        Progress.switchToDeterminate(progress, max);

        Rectangle size = new Rectangle(pageSize);
        if (landscape) {
            size = new Rectangle(pageSize.rotate());
        }
        size.setBackgroundColor(new BaseColor(Lookup.getDefault().lookup(PreviewController.class).getModel().getBackgroundColor()));
        document = new Document(size);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, stream);
        document.open();
        cb = pdfWriter.getDirectContent();
        cb.saveState();

        //Limits
        float minX = Float.POSITIVE_INFINITY;
        float maxX = Float.NEGATIVE_INFINITY;
        float minY = Float.POSITIVE_INFINITY;
        float maxY = Float.NEGATIVE_INFINITY;
        for (Node n : graph.getNodes()) {
            minX = Math.min(minX, n.getPosition().getX() - n.getRadius() - n.getBorderWidth());
            maxX = Math.max(maxX, n.getPosition().getX() + n.getRadius() + n.getBorderWidth());
            minY = Math.min(minY, -n.getPosition().getY() - n.getRadius() - n.getBorderWidth());
            maxY = Math.max(maxY, -n.getPosition().getY() + n.getRadius() + n.getBorderWidth());
        }

        double graphWidth = maxX - minX;
        double graphHeight = maxY - minY;
        double centerX = minX + graphWidth / 2.;
        double centerY = minY + graphHeight / 2.;

        //Transform
        double pageWidth = size.getWidth() - marginLeft - marginRight;
        double pageHeight = size.getHeight() - marginTop - marginBottom;
        double ratioWidth = pageWidth / graphWidth;
        double ratioHeight = pageHeight / graphHeight;
        double scale = ratioWidth < ratioHeight ? ratioWidth : ratioHeight;
        double translateX = (marginLeft + pageWidth / 2.) / scale;
        double translateY = (marginBottom + pageHeight / 2.) / scale;
View Full Code Here

    public void doExport(final Profile profile, final int width, final int height) {
        final PauseTransition pt = new PauseTransition();
        pt.setDuration(Duration.millis(profile.getPause()));
        final AtomicInteger cpt = new AtomicInteger();
        final Document document = new Document(new Rectangle(width, height), 0, 0, 0, 0);
        try {
            PdfWriter.getInstance(document, new FileOutputStream(exportFile));
        } catch (DocumentException | FileNotFoundException e) {
            handleError(e);
            return;
View Full Code Here

          public void onStartPage(PdfWriter writer, Document document) {
              pagenumber++;
          }
  
          public void onEndPage(PdfWriter writer, Document document) {
              Rectangle rect = writer.getBoxSize("art");

              switch(writer.getPageNumber() % 2) {
              case 0:
                  ColumnText.showTextAligned(writer.getDirectContent(),
                          Element.ALIGN_RIGHT, header[0],
                          rect.getRight(), rect.getTop(), 0);
                  break;
              case 1:
                  ColumnText.showTextAligned(writer.getDirectContent(),
                          Element.ALIGN_LEFT, header[1],
                          rect.getLeft(), rect.getTop(), 0);
                  break;
              }
              ColumnText.showTextAligned(writer.getDirectContent(),
                      Element.ALIGN_CENTER, new Phrase(String.format("page %d", pagenumber)),
                      (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 18, 0);
          }
View Full Code Here

          throws IOException, DocumentException, SQLException {
        File file=new File("vipul.pdf");
        Document document = new Document();
          PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
          HeaderFooter event = new HeaderFooter();
          writer.setBoxSize("art", new Rectangle(36, 54, 559, 788));
          writer.setPageEvent(event);
         document.open();
         
      Paragraph p=new Paragraph();
      for (int i=0; i<=1000; i++){
View Full Code Here

    private static void crop(String input) throws Exception {
        String output = input.replace(".pdf", "-crop.pdf");
        PdfReader reader = new PdfReader(input);
        final int n = reader.getNumberOfPages();
        Rectangle pageSize = reader.getPageSize(1);

        System.out.println("Input page size: " + pageSize);
        float left = (pageSize.getWidth() - kTextWidth) / 2 - kMargin;
        float right = pageSize.getWidth() - left;
        float bottom = (pageSize.getHeight() - kTextHeight) / 2;
        float top = pageSize.getHeight() - bottom;
        PdfRectangle rect = new PdfRectangle(left, bottom + kOffset, right, top + kOffset);
        for (int i = 1; i <= n; i++) {
            PdfDictionary pageDict = reader.getPageN(i);
            pageDict.put(PdfName.CROPBOX, rect);
        }
View Full Code Here

    private static void twoup(String input) throws Exception {
        String output = input.replace(".pdf", "-twoup.pdf");
        PdfReader reader = new PdfReader(input);
        int n = reader.getNumberOfPages();
        Rectangle pageSize = reader.getPageSize(1);

        System.out.println("Input page size: " + pageSize);
        Document doc = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
        PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(output));
        doc.open();
        // splitLine(doc, writer);
        PdfContentByte cb = writer.getDirectContent();
        float bottom = (doc.top() - pageSize.getHeight()) / 2 + kOffset;
        float left = doc.right() / 2 - (pageSize.getWidth() + kTextWidth) / 2 - kMargin;
        float right = doc.right() / 2 - (pageSize.getWidth() - kTextWidth) / 2 + kMargin;

        for (int i = 0; i <= n;) {
            PdfImportedPage page = getPage(writer, reader, i++);
            if (page != null)
                cb.addTemplate(page, left, bottom);
View Full Code Here

    private static void booklet(String input) throws Exception {
        String output = input.replace(".pdf", "-booklet.pdf");
        PdfReader reader = new PdfReader(input);
        int n = reader.getNumberOfPages();
        Rectangle pageSize = reader.getPageSize(1);

        System.out.println("Input page size: " + pageSize);
        Document doc = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
        PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(output));
        doc.open();
        splitLine(doc, writer);
        int[] pages = new int[(n + 3) / 4 * 4];
        int x = 1, y = pages.length;
        for (int i = 0; i < pages.length;) {
            pages[i++] = y--;
            pages[i++] = x++;
            pages[i++] = x++;
            pages[i++] = y--;
        }
        PdfContentByte cb = writer.getDirectContent();
        float bottom = (doc.top() - pageSize.getHeight()) / 2 + kOffset;
        float left = doc.right() / 2 - (pageSize.getWidth() + kTextWidth) / 2 - kMargin;
        float right = doc.right() / 2 - (pageSize.getWidth() - kTextWidth) / 2 + kMargin;

        for (int i = 0; i < pages.length;) {
            PdfImportedPage page = getPage(writer, reader, pages[i++]);
            if (page != null)
                cb.addTemplate(page, left, bottom);
View Full Code Here

                throw new IllegalArgumentException(MessageLocalization.getComposedMessage("the.field.1.already.exists", fieldName));
            this.fieldName = fieldName;
        }
        if (page < 1 || page > writer.reader.getNumberOfPages())
            throw new IllegalArgumentException(MessageLocalization.getComposedMessage("invalid.page.number.1", page));
        this.pageRect = new Rectangle(pageRect);
        this.pageRect.normalize();
        rect = new Rectangle(this.pageRect.getWidth(), this.pageRect.getHeight());
        this.page = page;
        newField = true;
    }
View Full Code Here

        PdfArray r = merged.getAsArray(PdfName.RECT);
        float llx = r.getAsNumber(0).floatValue();
        float lly = r.getAsNumber(1).floatValue();
        float urx = r.getAsNumber(2).floatValue();
        float ury = r.getAsNumber(3).floatValue();
        pageRect = new Rectangle(llx, lly, urx, ury);
        pageRect.normalize();
        page = item.getPage(0).intValue();
        int rotation = writer.reader.getPageRotation(page);
        Rectangle pageSize = writer.reader.getPageSizeWithRotation(page);
        switch (rotation) {
            case 90:
                pageRect = new Rectangle(
                pageRect.getBottom(),
                pageSize.getTop() - pageRect.getLeft(),
                pageRect.getTop(),
                pageSize.getTop() - pageRect.getRight());
                break;
            case 180:
                pageRect = new Rectangle(
                pageSize.getRight() - pageRect.getLeft(),
                pageSize.getTop() - pageRect.getBottom(),
                pageSize.getRight() - pageRect.getRight(),
                pageSize.getTop() - pageRect.getTop());
                break;
            case 270:
                pageRect = new Rectangle(
                pageSize.getRight() - pageRect.getBottom(),
                pageRect.getLeft(),
                pageSize.getRight() - pageRect.getTop(),
                pageRect.getRight());
                break;
        }
        if (rotation != 0)
            pageRect.normalize();
        rect = new Rectangle(this.pageRect.getWidth(), this.pageRect.getHeight());
    }
View Full Code Here

TOP

Related Classes of com.itextpdf.text.Rectangle

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.