Package org.pdfclown.files

Examples of org.pdfclown.files.File


  @Override
  public boolean run(
    )
  {
    // 1. PDF file instantiation.
    File file = new File();
    Document document = file.getDocument();

    // 2. Content creation.
    build(document);

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


  @Override
  public boolean run(
    )
  {
    // 1. Opening the PDF file...
    File file;
    {
      String filePath = promptPdfFileChoice("Please select a PDF file");

      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())
View Full Code Here

  public boolean run(
    )
  {
    // 1. Instantiate a new PDF file!
    /* 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

    )
  {
    String filePath = promptPdfFileChoice("Please select a PDF file");

    // 1. Open the PDF file!
    File file;
    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))
View Full Code Here

    )
  {
    String filePath = promptPdfFileChoice("Please select a PDF file");

    // 1. Open the PDF file!
    File file;
    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())
    {
View Full Code Here

  @Override
  public boolean run(
    )
  {
    // 1. Opening the PDF file...
    File file;
    {
      String filePath = promptPdfFileChoice("Please select a PDF file");

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

{
  @Override
  public boolean run(
    )
  {
    File file;
    {
      String filePath = promptPdfFileChoice("Please select a PDF file");

      // 1. Open the PDF file!
      try
      {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

    )
  {
    String filePath = promptPdfFileChoice("Please select a PDF file");

    // 1. Open the PDF file!
    File file;
    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).");}
View Full Code Here

    )
  {
    final String mainFilePath = promptPdfFileChoice("Please select a PDF file");

    // Open the PDF file!
    final File mainFile;
    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;
        {
          String sourceFilePath = promptPdfFileChoice("Select the source PDF file");
          try
          {sourceFile = new File(sourceFilePath);}
          catch(Exception e)
          {throw new RuntimeException(sourceFilePath + " file access error.",e);}
        }

        // Append the chosen source document to the main document!
        new PageManager(mainDocument).add(sourceFile.getDocument());

        // Serialize the main file!
        serialize(mainFile, action);
      } break;
      case DocumentBurst:
View Full Code Here

  @Override
  public boolean run(
    )
  {
    // 1. PDF file instantiation.
    File file = new File();
    Document document = file.getDocument();
    // Set default page size (A4)!
    document.setPageSize(PageFormat.getSize());

    // 2. Content creation.
    Date creationDate = new Date();
View Full Code Here

TOP

Related Classes of org.pdfclown.files.File

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.