Package org.pdfclown.documents

Examples of org.pdfclown.documents.Document


  private void apply(
    ComboBox field
    )
  {
    Document document = field.getDocument();
    Widget widget = field.getWidgets().get(0);

    Appearance appearance = widget.getAppearance();
    if(appearance == null)
    {widget.setAppearance(appearance = new Appearance(document));}
View Full Code Here


  private void apply(
    ListBox field
    )
  {
    Document document = field.getDocument();
    Widget widget = field.getWidgets().get(0);

    Appearance appearance = widget.getAppearance();
    if(appearance == null)
    {widget.setAppearance(appearance = new Appearance(document));}
View Full Code Here

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

    // 2. Applying the visual transitions...
    Transition.StyleEnum[] transitionStyles = Transition.StyleEnum.values();
    int transitionStylesLength = transitionStyles.length;
    for(Page page : document.getPages())
    {
      // Apply a transition to the page!
      page.setTransition(
        new Transition(
          document,
View Full Code Here

    /* NOTE: a File object is the low-level (syntactic) representation of a PDF file. */
    File file = new File();

    // 2. Get its corresponding document!
    /* NOTE: a Document object is the high-level (semantic) representation of a PDF file. */
    Document document = file.getDocument();

    // 3. Insert the contents into the document!
    populate(document);

    // (boilerplate metadata insertion -- ignore it)
View Full Code Here

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

    Document document = file.getDocument();

    // 2. Text extraction from the document pages.
    for(Page page : document.getPages())
    {
      if(!promptNextPage(page, false))
        return false;

      extract(
View Full Code Here

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

    Document document = file.getDocument();

    // 2. Plain text extraction from the document pages.
    TextExtractor extractor = new TextExtractor();
    for(Page page : document.getPages())
    {
      if(!promptNextPage(page, false))
        return false;

      // Extract plain text from the current page!
View Full Code Here

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

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

    Document document = file.getDocument();

    // 2. Create a watermark (form)!
    FormXObject watermark = createWatermark(document);

    // 3. Apply the watermark to the pages of the document!
View Full Code Here

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

    Document document = file.getDocument();

    // 2. Get the acroform!
    Form form = document.getForm();
    if(form == null)
    {System.out.println("\nNo acroform available (AcroForm dictionary not found).");}
    else
    {
      System.out.println("\nIterating through the fields collection...\n");
View Full Code Here

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

        // Serialize the main file!
        serialize(mainFile, action);
      } break;
      case PageMovement:
      {
        // First page to move.
        int fromSourcePageIndex = promptPageChoice("Select the start page to move", mainPagesCount);
        // Last page to move.
        int toSourcePageIndex = promptPageChoice("Select the end page to move", fromSourcePageIndex + 1, mainPagesCount) + 1;
        // Target position.
        int targetPageIndex = promptPageChoice("Select the position where to insert the pages", mainPagesCount + 1);

        // Move the chosen page range!
        new PageManager(mainDocument).move(
          fromSourcePageIndex,
          toSourcePageIndex,
          targetPageIndex
          );

        // Serialize the main file!
        serialize(mainFile, action);
      } break;
      case PageRemoval:
      {
        // First page to remove.
        int fromPageIndex = promptPageChoice("Select the start page to remove", mainPagesCount);
        // Last page to remove.
        int toPageIndex = promptPageChoice("Select the end page to remove", fromPageIndex + 1, mainPagesCount) + 1;

        // Remove the chosen page range!
        new PageManager(mainDocument).remove(
          fromPageIndex,
          toPageIndex
          );

        // Serialize the main file!
        serialize(mainFile, action);
      } break;
      case PageExtraction:
      {
        // First page to extract.
        int fromPageIndex = promptPageChoice("Select the start page", mainPagesCount);
        // Last page to extract.
        int toPageIndex = promptPageChoice("Select the end page", fromPageIndex + 1, mainPagesCount) + 1;

        // Extract the chosen page range!
        Document targetDocument = new PageManager(mainDocument).extract(
          fromPageIndex,
          toPageIndex
          );

        // Serialize the target file!
        serialize(targetDocument.getFile(), action);
      } break;
      case DocumentMerge:
      {
        // Source file.
        File sourceFile;
View Full Code Here

TOP

Related Classes of org.pdfclown.documents.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.