Package com.lowagie.text

Examples of com.lowagie.text.Document


    PdfCopyFieldsImp(OutputStream os, char pdfVersion) throws DocumentException {
        super(new PdfDocument(), os);
        pdf.addWriter(this);
        if (pdfVersion != 0)
            super.setPdfVersion(pdfVersion);
        nd = new Document();
        nd.addDocListener(pdf);
    }
View Full Code Here


public class RtfTableTest extends BaseTest
{
  public static void testRtfTable()
          throws DocumentException
  {
    Document document = new Document(new Rectangle(455, 600), 0, 0, 0, 0);
    RtfWriter2.getInstance(document, System.out);
    document.open();

    Table table = new Table (7, 2);
    boolean[][] occupiedCells = new boolean[7][2];
    float[] cellWidths = { 10, 10, 10, 10, 10, 10, 10 };
    table.setWidths(cellWidths);

    addCell(occupiedCells, table, 0, 0, 4, 2);
    addCell(occupiedCells, table, 4, 0, 2, 2);
    addCell(occupiedCells, table, 6, 0, 1, 1);
    addCell(occupiedCells, table, 6, 1, 1, 1);
/*
    addCell(occupiedCells, table, 0, 2, 3, 1);
    addCell(occupiedCells, table, 3, 2, 3, 1);
    addCell(occupiedCells, table, 6, 2, 1, 1);
    addCell(occupiedCells, table, 0, 3, 2, 1);
    addCell(occupiedCells, table, 2, 3, 3, 1);
    addCell(occupiedCells, table, 5, 3, 1, 1);
    addCell(occupiedCells, table, 6, 3, 1, 1);
    addCell(occupiedCells, table, 0, 4, 2, 1);
    addCell(occupiedCells, table, 2, 4, 3, 1);
    addCell(occupiedCells, table, 5, 4, 1, 1);
    addCell(occupiedCells, table, 6, 4, 1, 1);
    addCell(occupiedCells, table, 0, 5, 1, 1);
    addCell(occupiedCells, table, 1, 5, 1, 1);
    addCell(occupiedCells, table, 2, 5, 1, 1);
    addCell(occupiedCells, table, 3, 5, 1, 1);
    addCell(occupiedCells, table, 4, 5, 1, 1);
    addCell(occupiedCells, table, 5, 5, 1, 1);
    addCell(occupiedCells, table, 6, 5, 1, 1);
    addCell(occupiedCells, table, 0, 6, 3, 1);
    addCell(occupiedCells, table, 3, 6, 3, 1);
    addCell(occupiedCells, table, 6, 6, 1, 1);
    addCell(occupiedCells, table, 0, 7, 3, 1);
    addCell(occupiedCells, table, 3, 7, 3, 1);
    addCell(occupiedCells, table, 6, 7, 1, 1);
    addCell(occupiedCells, table, 0, 8, 2, 1);
    addCell(occupiedCells, table, 2, 8, 3, 1);
    addCell(occupiedCells, table, 5, 8, 1, 1);
    addCell(occupiedCells, table, 6, 8, 1, 1);
    addCell(occupiedCells, table, 0, 9, 2, 1);
    addCell(occupiedCells, table, 2, 9, 3, 1);
    addCell(occupiedCells, table, 5, 9, 1, 1);
    addCell(occupiedCells, table, 6, 9, 1, 1);
    addCell(occupiedCells, table, 0, 10, 1, 1);
    addCell(occupiedCells, table, 1, 10, 1, 1);
    addCell(occupiedCells, table, 2, 10, 1, 1);
    addCell(occupiedCells, table, 3, 10, 1, 1);
    addCell(occupiedCells, table, 4, 10, 1, 1);
    addCell(occupiedCells, table, 5, 10, 1, 1);
    addCell(occupiedCells, table, 6, 10, 1, 1);
    addCell(occupiedCells, table, 0, 11, 3, 1);
    addCell(occupiedCells, table, 3, 11, 3, 1);
    addCell(occupiedCells, table, 6, 11, 1, 1);
    addCell(occupiedCells, table, 0, 12, 3, 1);
    addCell(occupiedCells, table, 3, 12, 3, 1);
    addCell(occupiedCells, table, 6, 12, 1, 1);
    addCell(occupiedCells, table, 0, 13, 2, 1);
    addCell(occupiedCells, table, 2, 13, 3, 1);
    addCell(occupiedCells, table, 5, 13, 1, 1);
    addCell(occupiedCells, table, 6, 13, 1, 1);
    addCell(occupiedCells, table, 0, 14, 2, 1);
    addCell(occupiedCells, table, 2, 14, 3, 1);
    addCell(occupiedCells, table, 5, 14, 1, 1);
    addCell(occupiedCells, table, 6, 14, 1, 1);
    addCell(occupiedCells, table, 0, 15, 1, 1);
    addCell(occupiedCells, table, 1, 15, 1, 1);
    addCell(occupiedCells, table, 2, 15, 1, 1);
    addCell(occupiedCells, table, 3, 15, 1, 1);
    addCell(occupiedCells, table, 4, 15, 1, 1);
    addCell(occupiedCells, table, 5, 15, 1, 1);
    addCell(occupiedCells, table, 6, 15, 1, 1);
    addCell(occupiedCells, table, 0, 16, 3, 1);
    addCell(occupiedCells, table, 3, 16, 3, 1);
    addCell(occupiedCells, table, 6, 16, 1, 1);
    addCell(occupiedCells, table, 0, 17, 3, 1);
    addCell(occupiedCells, table, 3, 17, 3, 1);
    addCell(occupiedCells, table, 6, 17, 1, 1);
    addCell(occupiedCells, table, 0, 18, 2, 1);
    addCell(occupiedCells, table, 2, 18, 3, 1);
    addCell(occupiedCells, table, 5, 18, 1, 1);
    addCell(occupiedCells, table, 6, 18, 1, 1);
    addCell(occupiedCells, table, 0, 19, 2, 1);
    addCell(occupiedCells, table, 2, 19, 3, 1);
    addCell(occupiedCells, table, 5, 19, 1, 1);
    addCell(occupiedCells, table, 6, 19, 1, 1);
    addCell(occupiedCells, table, 0, 20, 1, 1);
    addCell(occupiedCells, table, 1, 20, 1, 1);
    addCell(occupiedCells, table, 2, 20, 1, 1);
    addCell(occupiedCells, table, 3, 20, 1, 1);
    addCell(occupiedCells, table, 4, 20, 1, 1);
    addCell(occupiedCells, table, 5, 20, 1, 1);
    addCell(occupiedCells, table, 6, 20, 1, 1);
    addCell(occupiedCells, table, 0, 21, 3, 1);
    addCell(occupiedCells, table, 3, 21, 3, 1);
    addCell(occupiedCells, table, 6, 21, 1, 1);
    addCell(occupiedCells, table, 0, 22, 3, 1);
    addCell(occupiedCells, table, 3, 22, 3, 1);
    addCell(occupiedCells, table, 6, 22, 1, 1);
    addCell(occupiedCells, table, 0, 23, 2, 1);
    addCell(occupiedCells, table, 2, 23, 3, 1);
    addCell(occupiedCells, table, 5, 23, 1, 1);
    addCell(occupiedCells, table, 6, 23, 1, 1);
    addCell(occupiedCells, table, 0, 24, 2, 1);
    addCell(occupiedCells, table, 2, 24, 3, 1);
    addCell(occupiedCells, table, 5, 24, 1, 1);
    addCell(occupiedCells, table, 6, 24, 1, 1);
    addCell(occupiedCells, table, 0, 25, 1, 1);
    addCell(occupiedCells, table, 1, 25, 1, 1);
    addCell(occupiedCells, table, 2, 25, 1, 1);
    addCell(occupiedCells, table, 3, 25, 1, 1);
    addCell(occupiedCells, table, 4, 25, 1, 1);
    addCell(occupiedCells, table, 5, 25, 1, 1);
    addCell(occupiedCells, table, 6, 25, 1, 1);
    addCell(occupiedCells, table, 0, 26, 3, 1);
    addCell(occupiedCells, table, 3, 26, 3, 1);
    addCell(occupiedCells, table, 6, 26, 1, 1);
    addCell(occupiedCells, table, 0, 27, 1, 1);
    addCell(occupiedCells, table, 1, 27, 1, 1);
    addCell(occupiedCells, table, 2, 27, 1, 1);
    addCell(occupiedCells, table, 3, 27, 1, 1);
    addCell(occupiedCells, table, 4, 27, 1, 1);
    addCell(occupiedCells, table, 5, 27, 1, 1);
    addCell(occupiedCells, table, 6, 27, 1, 1);
    addCell(occupiedCells, table, 0, 28, 6, 2);
    addCell(occupiedCells, table, 6, 28, 1, 1);
    addCell(occupiedCells, table, 6, 29, 1, 1);
*/   
    document.add(table);
    assertTrue(true);
  }
View Full Code Here

    return document;
  }

  public void open() throws DocumentException
  {
    this.document = new Document();
    //pageSize, marginLeft, marginRight, marginTop, marginBottom));

    writer = PdfWriter.getInstance(document, out);
    writer.setLinearPageMode();
View Full Code Here

        (page.getWidth() - page.getImageableWidth() - page.getImageableX());
    final float marginTop = (float) StrictGeomUtility.toExternalValue(page.getImageableY());
    final float marginBottom = (float) StrictGeomUtility.toExternalValue
        (page.getHeight() - page.getImageableHeight() - page.getImageableY());

    final Document document = getDocument();
    document.setPageSize(pageSize);
    document.setMargins(marginLeft, marginRight, marginTop, marginBottom);

    if (awaitOpenDocument)
    {
      document.open();
      awaitOpenDocument = false;
    }

    final PdfContentByte directContent = writer.getDirectContent();
    final Graphics2D graphics = new PdfGraphics2D(directContent, width, height, metaData);
    final PdfLogicalPageDrawable logicalPageDrawable =
        new PdfLogicalPageDrawable(logicalPage, metaData, writer, page, resourceManager, imageCache, version);
    final PhysicalPageDrawable drawable = new PhysicalPageDrawable(logicalPageDrawable, page);
    drawable.draw(graphics, new Rectangle2D.Double(0, 0, width, height));

    graphics.dispose();

    document.newPage();
  }
View Full Code Here

    final float width = (float) StrictGeomUtility.toExternalValue(logicalPage.getPageWidth());
    final float height = (float) StrictGeomUtility.toExternalValue(logicalPage.getPageHeight());

    final Rectangle pageSize = new Rectangle(width, height);

    final Document document = getDocument();
    document.setPageSize(pageSize);
    document.setMargins(0, 0, 0, 0);

    if (awaitOpenDocument)
    {
      document.open();
      awaitOpenDocument = false;
    }

    final Graphics2D graphics = new PdfGraphics2D(writer.getDirectContent(), width, height, metaData);
    // and now process the box ..
    final PdfLogicalPageDrawable logicalPageDrawable =
        new PdfLogicalPageDrawable(logicalPage, metaData, writer, null, resourceManager, imageCache, version);
    logicalPageDrawable.draw(graphics, new Rectangle2D.Double(0, 0, width, height));

    graphics.dispose();

    document.newPage();
  }
View Full Code Here

      final float marginBottom =
          (float) StrictGeomUtility.toExternalValue(pageFormat.getHeight()
              - pageFormat.getImageableHeight() - pageFormat.getImageableY());
      final Rectangle pageSize = new Rectangle(urx, ury);

      document = new Document(pageSize, marginLeft, marginRight, marginTop, marginBottom);
      imageCache = new RTFImageCache(resourceManager);

      // rtf does not support PageFormats or other meta data...
      final RtfWriter2 instance = RtfWriter2.getInstance(document, new NoCloseOutputStream(outputStream));
      instance.getDocumentSettings().setAlwaysUseUnicode(true);
View Full Code Here

  protected void exportReportToStream(OutputStream os) throws JRException
  {
    //ByteArrayOutputStream baos = new ByteArrayOutputStream();

    document =
      new Document(
        new Rectangle(
          jasperPrint.getPageWidth(),
          jasperPrint.getPageHeight()
        )
      );

    imageTesterDocument =
      new Document(
        new Rectangle(
          10, //jasperPrint.getPageWidth(),
          10 //jasperPrint.getPageHeight()
        )
      );
View Full Code Here

            }

            // init
            int pageOffset = 0;
            ArrayList master = new ArrayList();
            Document pdfDocument = null;
            int totalProcessedPages = 0;

            try {
                String[] pageSelections = inputCommand.getPageSelections();
                File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
                int length = ArrayUtils.getLength(pageSelections);

                for (int i = 0; i < fileList.length; i++) {

                    String currentPageSelection = ValidationUtility.ALL_STRING;
                    int currentDocumentPages = 0;
                    if (!ArrayUtils.isEmpty(pageSelections) && i <= length) {
                        currentPageSelection = pageSelections[i].toLowerCase();
                    }

                    String[] selectionGroups = StringUtils.split(currentPageSelection, ",");

                    pdfReader = new PdfReader(new RandomAccessFileOrArray(fileList[i].getFile().getAbsolutePath()),
                            fileList[i].getPasswordBytes());
                    pdfReader.removeUnusedObjects();
                    pdfReader.consolidateNamedDestinations();
                    int pdfNumberOfPages = pdfReader.getNumberOfPages();
                    BookmarksProcessor bookmarkProcessor = new BookmarksProcessor(SimpleBookmark.getBookmark(pdfReader), pdfNumberOfPages);

                    List boundsList = getBounds(pdfNumberOfPages, selectionGroups);
                    ValidationUtility.assertNotIntersectedBoundsList(boundsList);
                    String boundsString = "";

                    for (Iterator iter = boundsList.iterator(); iter.hasNext();) {
                        Bounds bounds = (Bounds) iter.next();
                        boundsString += (boundsString.length() > 0) ? "," + bounds.toString() : bounds.toString();

                        // bookmarks
                        List bookmarks = bookmarkProcessor.processBookmarks(bounds.getStart(), bounds.getEnd(),
                                pageOffset);
                        if (bookmarks != null) {
                            master.addAll(bookmarks);
                        }
                        int relativeOffset = (bounds.getEnd() - bounds.getStart()) + 1;
                        currentDocumentPages += relativeOffset;
                        pageOffset += relativeOffset;
                    }

                    // add pages
                    LOG.info(fileList[i].getFile().getAbsolutePath() + ": " + currentDocumentPages
                            + " pages to be added.");
                    if (pdfWriter == null) {
                        if (inputCommand.isCopyFields()) {
                            // step 1: we create a writer
                            pdfWriter = new PdfCopyFieldsConcatenator(new FileOutputStream(tmpFile), inputCommand
                                    .isCompress());
                            LOG.debug("PdfCopyFieldsConcatenator created.");
                            // output document version
                            if (inputCommand.getOutputPdfVersion() != null) {
                                pdfWriter.setPdfVersion(inputCommand.getOutputPdfVersion().charValue());
                            }
                            HashMap meta = pdfReader.getInfo();
                            meta.put("Creator", ConsoleServicesFacade.CREATOR);
                        } else {
                            // step 1: creation of a document-object
                            pdfDocument = new Document(pdfReader.getPageSizeWithRotation(1));
                            // step 2: we create a writer that listens to the document
                            pdfWriter = new PdfSimpleConcatenator(pdfDocument, new FileOutputStream(tmpFile),
                                    inputCommand.isCompress());
                            LOG.debug("PdfSimpleConcatenator created.");
                            // output document version
                            if (inputCommand.getOutputPdfVersion() != null) {
                                pdfWriter.setPdfVersion(inputCommand.getOutputPdfVersion().charValue());
                            }
                            // step 3: we open the document
                            pdfDocument.addCreator(ConsoleServicesFacade.CREATOR);
                            pdfDocument.open();
                        }
                    }
                    // step 4: we add content
                    pdfReader.selectPages(boundsString);
                    pdfWriter.addDocument(pdfReader);
                    // fix 03/07
                    // pdfReader = null;
                    pdfReader.close();
                    pdfWriter.freeReader(pdfReader);
                    totalProcessedPages += currentDocumentPages;
                    LOG.info(currentDocumentPages + " pages processed correctly.");
                    setPercentageOfWorkDone(((i + 1) * WorkDoneDataModel.MAX_PERGENTAGE) / fileList.length);
                }
                if (master.size() > 0) {
                    pdfWriter.setOutlines(master);
                }
                LOG.info("Total processed pages: " + totalProcessedPages + ".");
                if (pdfDocument != null) {
                    pdfDocument.close();
                }
                // rotations
                if (inputCommand.getRotations() != null && inputCommand.getRotations().length > 0) {
                    LOG.info("Applying pages rotation.");
                    File rotatedTmpFile = applyRotations(tmpFile, inputCommand);
View Full Code Here

      boolean resize = false;
      if (page.getBounds().getWidth() == 0 || page.getBounds().getHeight() == 0) {
        resize = true;
      }
      // Create a document in the requested ISO scale.
      Document document = new Document(page.getBounds(), 0, 0, 0, 0);
      PdfWriter writer;
      writer = PdfWriter.getInstance(document, baos);

      // Render in correct colors for transparent rasters
      writer.setRgbTransparencyBlending(true);

      // The mapView is not scaled to the document, we assume the mapView
      // has the right ratio.

      // Write document title and metadata
      document.open();
      PdfContext context = new PdfContext(writer);
      context.initSize(page.getBounds());
      // first pass of all children to calculate size
      page.calculateSize(context);
      if (resize) {
        // we now know the bounds of the document
        // round 'm up and restart with a new document
        int width = (int) Math.ceil(page.getBounds().getWidth());
        int height = (int) Math.ceil(page.getBounds().getHeight());
        page.getConstraint().setWidth(width);
        page.getConstraint().setHeight(height);
        document = new Document(new Rectangle(width, height), 0, 0, 0, 0);
        writer = PdfWriter.getInstance(document, baos);
        // Render in correct colors for transparent rasters
        writer.setRgbTransparencyBlending(true);
        document.open();
        baos.reset();
        context = new PdfContext(writer);
        context.initSize(page.getBounds());
      }
      // Actual drawing
      document.addTitle("Geomajas");
      // second pass to layout
      page.layout(context);
      // finally render
      page.render(context);
      document.add(context.getImage());
      // Now close the document
      document.close();
      // convert to non-pdf format
      switch (format) {
        case PDF:
          break;
        case PNG:
View Full Code Here

  /**
   * Writes to <code>outputStream</code> the print of a home in PDF format.
   */
  public void write(OutputStream outputStream) throws IOException {
    PageFormat pageFormat = HomePrintableComponent.getPageFormat(this.home.getPrint());
    Document pdfDocument = new Document(new Rectangle((float)pageFormat.getWidth(), (float)pageFormat.getHeight()));
    try {
      // Get a PDF writer that will write to the given PDF output stream
      PdfWriter pdfWriter = PdfWriter.getInstance(pdfDocument, outputStream);
      pdfDocument.open();
     
      // Set PDF document description
      pdfDocument.addAuthor(System.getProperty("user.name", ""));
      String pdfDocumentCreator = this.preferences.getLocalizedString(
          HomePDFPrinter.class, "pdfDocument.creator");   
      pdfDocument.addCreator(pdfDocumentCreator);
      pdfDocument.addCreationDate();
      String homeName = this.home.getName();
      if (homeName != null) {
        pdfDocument.addTitle(this.controller.getContentManager().getPresentationName(
            homeName, ContentManager.ContentType.PDF));
      }
     
      PdfContentByte pdfContent = pdfWriter.getDirectContent();
      HomePrintableComponent printableComponent =
          new HomePrintableComponent(this.home, this.controller, this.defaultFont);
      // Print each page
      for (int page = 0, pageCount = printableComponent.getPageCount(); page < pageCount; page++) {
        // Check current thread isn't interrupted
        if (Thread.interrupted()) {
          throw new InterruptedIOException();
        }
        PdfTemplate pdfTemplate = pdfContent.createTemplate((float)pageFormat.getWidth(),
            (float)pageFormat.getHeight());
        Graphics g = pdfTemplate.createGraphicsShapes((float)pageFormat.getWidth(),
            (float)pageFormat.getHeight());       
       
        printableComponent.print(g, pageFormat, page);
       
        pdfContent.addTemplate(pdfTemplate, 0, 0);
        g.dispose();
       
        if (page != pageCount - 1) {
          pdfDocument.newPage();
        }
      }
      pdfDocument.close();
    } catch (DocumentException ex) {
      IOException exception = new IOException("Couldn't print to PDF");
      exception.initCause(ex);
      throw exception;
    } catch (InterruptedPrinterException ex) {
View Full Code Here

TOP

Related Classes of com.lowagie.text.Document

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.