Package org.pdfclown.documents

Examples of org.pdfclown.documents.Pages


    {file = new File(filePath);}
    catch(Exception e)
    {throw new RuntimeException(filePath + " file access error.",e);}

    Document document = file.getDocument();
    Pages pages = document.getPages();

    // 2. Page rasterization.
    int pageIndex = promptPageChoice("Select the page to render", pages.size());
    Page page = pages.get(pageIndex);
    Dimension2D imageSize = page.getSize();
    Renderer renderer = new Renderer();
    BufferedImage image = renderer.render(page, imageSize);

    // 3. Save the page image!
View Full Code Here


      {file = new File(filePath);}
      catch(Exception e)
      {throw new RuntimeException(filePath + " file access error.",e);}
    }
    Document document = file.getDocument();
    Pages pages = document.getPages();

    // 2. Inserting page destinations...
    Names names = document.getNames(); if(names == null){document.setNames(names = new Names(document));}
    NamedDestinations destinations = names.getDestinations(); if(destinations == null){names.setDestinations(destinations = new NamedDestinations(document));}
    destinations.put(new PdfString("First page"), new LocalDestination(pages.get(0)));
    if(pages.size() > 1)
    {
      destinations.put(new PdfString("Second page"), new LocalDestination(pages.get(1), Destination.ModeEnum.FitHorizontal, new Float[]{0f}));

      if(pages.size() > 2)
      {destinations.put(new PdfString("Third page"), new LocalDestination(pages.get(2), Destination.ModeEnum.XYZ, new Float[]{50f,null,null}));}
    }

    // (boilerplate metadata insertion -- ignore it)
    buildAccessories(document,"Named destinations","manipulating named destinations");
View Full Code Here

    {mainFile = new File(mainFilePath);}
    catch(Exception e)
    {throw new RuntimeException(mainFilePath + " file access error.",e);}

    final Document mainDocument = mainFile.getDocument();
    final Pages mainPages = mainDocument.getPages();
    final int mainPagesCount = mainPages.size();

    final ActionEnum action = promptAction();
    switch(action)
    {
      case PageDataSizeCalculation:
      {
        System.out.println("\nThis algorithm calculates the data size (expressed in bytes) of the selected document's pages.");
        System.out.println("Legend:");
        System.out.println(" * full: page data size encompassing all its dependencies (like shared resources) -- this is the size of the page when extracted as a single-page document;");
        System.out.println(" * differential: additional page data size -- this is the extra-content that's not shared with previous pages;");
        System.out.println(" * incremental: data size of the page sublist encompassing all the previous pages and the current one.\n");

        // Calculating the page data sizes...
        Set<PdfReference> visitedReferences = new HashSet<PdfReference>();
        long incrementalDataSize = 0;
        for(Page page : mainPages)
        {
          long pageFullDataSize = PageManager.getSize(page);
          long pageDifferentialDataSize = PageManager.getSize(page, visitedReferences);
          incrementalDataSize += pageDifferentialDataSize;

          System.out.println(
            "Page " + (page.getIndex()+1) + ": "
              + pageFullDataSize + " (full); "
              + pageDifferentialDataSize + " (differential); "
              + incrementalDataSize + " (incremental)"
            );
        }
      } break;
      case PageAddition:
      {
        // Source file.
        File sourceFile;
        {
          String sourceFilePath = promptPdfFileChoice("Select the source PDF file");
          try
          {sourceFile = new File(sourceFilePath);}
          catch(Exception e)
          {throw new RuntimeException(sourceFilePath + " file access error.",e);}
        }
        // Source page collection.
        Pages sourcePages = sourceFile.getDocument().getPages();
        // Source page count.
        int sourcePagesCount = sourcePages.size();

        // First page to add.
        int fromSourcePageIndex = promptPageChoice("Select the start source page to add", sourcePagesCount);
        // Last page to add.
        int toSourcePageIndex = promptPageChoice("Select the end source page to add", fromSourcePageIndex + 1, sourcePagesCount) + 1;
        // Target position.
        int targetPageIndex = promptPageChoice("Select the position where to insert the source pages", mainPagesCount + 1);

        // Add the chosen page range to the main document!
        new PageManager(mainDocument).add(
          targetPageIndex,
          sourcePages.subList(
            fromSourcePageIndex,
            toSourcePageIndex
            )
          );

View Full Code Here

  private void buildAccessories(
    Document document
    )
  {
    Pages pages = document.getPages();

    // Bookmarks.
    Bookmarks bookmarks = new Bookmarks(document);
    document.setBookmarks(bookmarks);
    document.setPageMode(PageModeEnum.Bookmarks);
    Page page = pages.get(0);
    Bookmark rootBookmark = new Bookmark(
      document,
      "Creation Sample",
      new LocalDestination(
        page,
        Destination.ModeEnum.Fit,
        null
        )
      );
    bookmarks.add(rootBookmark);
    bookmarks = rootBookmark.getBookmarks();
    page = pages.get(1);
    Bookmark bookmark = new Bookmark(
      document,
      "2nd page (close-up view)",
      new LocalDestination(
        page,
        Destination.ModeEnum.XYZ,
        new Float[]{0f,250f,2f}
        )
      );
    bookmarks.add(bookmark);
    bookmark.getBookmarks().add(
      new Bookmark(
        document,
        "2nd page (mid view)",
        new LocalDestination(
          page,
          Destination.ModeEnum.XYZ,
          new Float[]{0f,(float)page.getSize().getHeight() - 250,1f}
          )
        )
      );
    page = pages.get(2);
    bookmarks.add(
      new Bookmark(
        document,
        "3rd page (fit horizontal view)",
        new LocalDestination(
View Full Code Here

      StandardType1Font.FamilyEnum.Courier,
      true,
      false
      );

    Pages pages = document.getPages();
    for(PageFormat.SizeEnum pageFormat
      : EnumSet.allOf(PageFormat.SizeEnum.class))
    {
      for(PageFormat.OrientationEnum pageOrientation
        : EnumSet.allOf(PageFormat.OrientationEnum.class))
      {
        // Add a page to the document!
        Page page = new Page(document); // Instantiates the page inside the document context.
        pages.add(page); // Puts the page in the pages collection.

        // Set the page size!
        page.setSize(
          PageFormat.getSize(
            pageFormat,
View Full Code Here

    for(Map.Entry<String,Integer> entry : objCounters.entrySet())
    {System.out.println(" " + entry.getKey() + ": " + entry.getValue());}
    System.out.println("Indirect objects total count: " + file.getIndirectObjects().size());

    // 2.3. Showing some page information...
    Pages pages = document.getPages();
    int pageCount = pages.size();
    System.out.println("\nPage count: " + pageCount);

    int pageIndex = (int)Math.floor((float)pageCount / 2);
    System.out.println("Mid page:");
    printPageInfo(pages.get(pageIndex),pageIndex);

    pageIndex++;
    if(pageIndex < pageCount)
    {
      System.out.println("Next page:");
      printPageInfo(pages.get(pageIndex),pageIndex);
    }
   
    return true;
  }
View Full Code Here

 
  private void buildLinks(
    Document document
    )
  {
    Pages pages = document.getPages();
    Page page = new Page(document);
    pages.add(page);

    StandardType1Font font = null;
    try
    {
      font = new StandardType1Font(
View Full Code Here

    // Get the abstract barcode entity!
    EAN13Barcode barcode = new EAN13Barcode("8012345678901");
    // Create the reusable barcode within the document!
    XObject barcodeXObject = barcode.toXObject(document);

    Pages pages = document.getPages();
    // Page 1.
    {
      Page page = new Page(document);
      pages.add(page);
      Dimension2D pageSize = page.getSize();

      PrimitiveComposer composer = new PrimitiveComposer(page);
      {
        BlockComposer blockComposer = new BlockComposer(composer);
        blockComposer.setHyphenation(true);
        blockComposer.begin(
          new Rectangle2D.Double(
            Margin,
            Margin,
            (float)pageSize.getWidth() - Margin * 2,
            (float)pageSize.getHeight() - Margin * 2
            ),
          AlignmentXEnum.Left,
          AlignmentYEnum.Top
          );
        StandardType1Font bodyFont = new StandardType1Font(
          document,
          StandardType1Font.FamilyEnum.Courier,
          true,
          false
          );
        composer.setFont(bodyFont,32);
        blockComposer.showText("Barcode sample"); blockComposer.showBreak();
        composer.setFont(bodyFont,16);
        blockComposer.showText("Showing the EAN-13 Bar Code on different compositions:"); blockComposer.showBreak();
        blockComposer.showText("- page 1: on the lower right corner of the page, 100pt wide;"); blockComposer.showBreak();
        blockComposer.showText("- page 2: on the middle of the page, 1/3-page wide, 25 degree counterclockwise rotated;"); blockComposer.showBreak();
        blockComposer.showText("- page 3: filled page, 90 degree clockwise rotated."); blockComposer.showBreak();
        blockComposer.end();
      }

      // Show the barcode!
      composer.showXObject(
        barcodeXObject,
        new Point2D.Double(
          (float)pageSize.getWidth() - Margin,
          (float)pageSize.getHeight() - Margin
          ),
        new Dimension(100,0),
        AlignmentXEnum.Right,
        AlignmentYEnum.Bottom,
        0
        );
      composer.flush();
    }

    // Page 2.
    {
      Page page = new Page(document);
      pages.add(page);
      Dimension2D pageSize = page.getSize();

      PrimitiveComposer composer = new PrimitiveComposer(page);
      // Show the barcode!
      composer.showXObject(
        barcodeXObject,
        new Point2D.Double(
          (float)pageSize.getWidth() / 2,
          (float)pageSize.getHeight() / 2
          ),
        new Dimension((int)pageSize.getWidth()/3,0),
        AlignmentXEnum.Center,
        AlignmentYEnum.Middle,
        25
        );
      composer.flush();
    }

    // Page 3.
    {
      Page page = new Page(document);
      pages.add(page);
      Dimension2D pageSize = page.getSize();

      PrimitiveComposer composer = new PrimitiveComposer(page);
      // Show the barcode!
      composer.showXObject(
View Full Code Here

TOP

Related Classes of org.pdfclown.documents.Pages

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.