All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.pdfbox.tools.PDFBox Maven / Gradle / Ivy

Go to download

The Apache PDFBox library is an open source Java tool for working with PDF documents. This artefact contains commandline tools using Apache PDFBox.

There is a newer version: 3.0.3
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.pdfbox.tools;

import org.apache.pdfbox.debugger.PDFDebugger;

/**
 * Simple wrapper around all the command line utilities included in PDFBox.
 * Used as the main class in the runnable standalone PDFBox jar.
 *
 * @see PDFBOX-687
 */
public final class PDFBox 
{

    private PDFBox()
    {
    }
    
    /**
     * Main method.
     * 
     * @param args command line arguments
     */
    public static void main(String[] args) throws Exception
    {
        // suppress the Dock icon on OS X
        System.setProperty("apple.awt.UIElement", "true");

        if (args.length > 0) 
        {
            String command = args[0];
            String[] arguments = new String[args.length - 1];
            System.arraycopy(args, 1, arguments, 0, arguments.length);
            boolean exitAfterCallingMain = true;
            if (command.equals("Decrypt"))
            {
                Decrypt.main(arguments);
            }
            else if (command.equals("Encrypt"))
            {
                Encrypt.main(arguments);
            }
            else if (command.equals("ExtractText"))
            {
                ExtractText.main(arguments);
            }
            else if (command.equals("ExtractImages"))
            {
                ExtractImages.main(arguments);
            }
            else if (command.equals("OverlayPDF"))
            {
                OverlayPDF.main(arguments);
            }
            else if (command.equals("PrintPDF"))
            {
                PrintPDF.main(arguments);
            }
            else if (command.equals("PDFDebugger") || command.equals("PDFReader"))
            {
                PDFDebugger.main(arguments);
                exitAfterCallingMain = false;
            }
            else if (command.equals("PDFMerger"))
            {
                PDFMerger.main(arguments);
            }
            else if (command.equals("PDFSplit"))
            {
                PDFSplit.main(arguments);
            }
            else if (command.equals("PDFToImage"))
            {
                PDFToImage.main(arguments);
            }
            else if (command.equals("TextToPDF"))
            {
                TextToPDF.main(arguments);
            }
            else if (command.equals("WriteDecodedDoc"))
            {
                WriteDecodedDoc.main(arguments);
            }
            else
            {
                showMessageAndExit();
            }
            if (exitAfterCallingMain)
            {
                System.exit(0);
            }
        }
        else 
        {
            showMessageAndExit();
        }
    }

    private static void showMessageAndExit() 
    {
        String message = "PDFBox version: \""+ Version.getVersion()+ "\""
                + "\nUsage: java -jar pdfbox-app-x.y.z.jar  \n"
                + "\nPossible commands are:\n"
                + "  Decrypt\n"
                + "  Encrypt\n"
                + "  ExtractText\n"
                + "  ExtractImages\n"
                + "  OverlayPDF\n"
                + "  PrintPDF\n"
                + "  PDFDebugger\n"
                + "  PDFMerger\n"
                + "  PDFReader\n"
                + "  PDFSplit\n"
                + "  PDFToImage\n"
                + "  TextToPDF\n"
                + "  WriteDecodedDoc";
        
        System.err.println(message);
        System.exit(1);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy