Before writing the specific code, let's look at the command-line tools that the Apache PDFBox API framework provides to us. With this command-line tool, we can understand most
Apache PDFBox provides us with powerful features.
Before we run the command, we first need to download the jar file that the command-line tool relies on, and you can go to any of the sites below to download it.
Http://apache.fayea.com/apache-mirror/pdfbox/1.8.5/pdfbox-app-1.8.5.jar
Http://mirrors.cnnic.cn/apache/pdfbox/1.8.5/pdfbox-app-1.8.5.jar
Http://apache.dataguru.cn/pdfbox/1.8.5/pdfbox-app-1.8.5.jar
Http://mirrors.hust.edu.cn/apache/pdfbox/1.8.5/pdfbox-app-1.8.5.jar
Http://mirror.bit.edu.cn/apache/pdfbox/1.8.5/pdfbox-app-1.8.5.jar
http://mirror.esocc.com/a Pache/pdfbox/1.8.5/pdfbox-app-1.8.5.jar
After the download is complete, you can put this jar into a file on the local computer, the author put it in the D:/pdftest directory,
Let's say we have an environment where Java home is well-configured. We personally configured is, jdk1.6.0; Depending on your actual installation environment, you can
Use a different JDK version.
The environment is ready, now everything is available, only under the actual operation. But before the actual operation, give everyone a simple wordy, Apache
In the end, did the PDFBox project bring those commands to operate the PDF file? In general, it includes some of the following commands.
- PDFBox command-line tools
- Decrypt: Decrypting a PDF document
- Encrypt: Encrypting a PDF document
- Extracttext: Extracting a string from a PDF document
- Overlaypdf: Overwrite PDF file
- Printpdf: Print PDF files
- Pdfdebugger: Listing information for the PDF document itself
- Pdfreader: Reading PDF documents
- Pdfmerger: Merging PDF documents
- Pdfsplit: Splitting a PDF document
- Pdftoimage: Converting a PDF document into a single image
- Texttopdf: Convert a piece of text into a PDF file
- Writedecodeddoc: Unzip a PDF file
Confined to the length of our current example. Only to demonstrate the use of four-to-five commands, others can refer to Https://pdfbox.apache.org/commandline/'s official website or the reader's own extrapolate.
(1) Before making all the commands, I definitely need a PDF file, then we'll use this tool to create a PDF file: texttopdf We're looking for an article online. We will take https://pdfbox.apache.org/architecture.html this article as an example, copy it to a test.txt file, and put the text file in the D:/pdftest folder. Then execute the following command.
D:\pdftest>java-jar D:/pdftest/pdfbox-app-1.8.5.jar texttopdf d:/pdftest/csdnblog.pdf d:/pdftest/test.txt
A test.pdf file will be generated in the D:\pdftest file. This PDF file contains 2 pages of paper.
(2) Now that we've created it, we'll use the command-line tool: Pdfreader look at it,
D:\pdftest>java-jar D:/pdftest/pdfbox-app-1.8.5.jar Pdfreader d:/pdftest/test.pdf
(3) As I mentioned above, the generated test.pdf has two pages. Now we'll use the Pdfsplit command to split the test.pdf into two PDF files.
D:\pdftest>java-jar D:/pdftest/pdfbox-app-1.8.5.jar pdfsplit-startpage 1-split 1 d:/pdftest/test.pdf
where-startpage 1 means splitting from the first page
-split 1 indicates how many pages each individual split PDF file has been split into
Is the result of the split, it can be seen that Test.pdf was split into 2 PDF files, test-0.pdf and test-1.pdf
(4) Finally show you the use of the Pdfdebugger command line tool.
D:\pdftest>java-jar D:/pdftest/pdfbox-app-1.8.5.jar Pdfdebugger d:/pdftest/test.pdf
after executing the above command, the following form will pop up. It shows some descriptive information about the PDF file itself.