Open Source Go Library for PDF Document Generation
Open Source Go API for Batch Processing and Scripting PDF Documents.
PDFCPU is an open source comprehensive PDF processing library written in Go. It is built for batch processing and scripting PDF documents via a command line interface. Furthermore, the API makes it simple to integrate PDF documents into your applications using GO. The API makes it simple to create and manipulate PDF documents with a wide range of command sets.
Using the API, you can add attachments to your PDF document, change owner and user password, and encrypt or decrypt data. The API allows adding or removing pages from PDF documents, you can rotate, trim, split, and validate your PDF using the API as well. Furthermore, the API allows for adding keywords and optimizing PDF documents.
At A Glance
An overview of One File PDF features.
- Generate PDFs
PDFCPU only requires Go runtime.
- Go 1.14 and above.
Getting Started with PDFCPU
To install the PDFCPU on your system, please run the following command.
Install PDFCPU via GitHub
go get https://github.com/pdfcpu/pdfcpu
Encrypt PDF via Command Based Free Go Library
PDFCPU is a command-based PDF document manipulation API. The command based system allows the manipulation of large number of files efficiently. In order to encrypt PDF files, the API provides the following command.
pdfcpu encrypt [-v(erbose)|vv] [-q(uiet)] [-mode rc4|aes] [-key 40|128|256] [perm none|all] [-upw userpw] -opw ownerpw inFile [outFile]
Furthermore, the API provides other document protection features including decryption, changing user password, changing owner password, listing & permission by using the following commands.
Add Images to PDF via Free GO API
The open-source API PDFCPU allows addting & converting images to PDF easily and fastly. In order to convert the images you just need to run the following command and the output PDF document will be generated automatically.
Add Image to PDF Pages via Go
pdfcpu import [-v(erbose)|vv] [-q(uiet)] [description] outFile imageFile...
// Create a single page photo.pdf containing photo.png using the default positioning pos:full. pdfcpu import photo.pdf photo.png // Create a single page PDF using paper size f:A5 & positioning parameter pos:c to center the image pdfcpu import -- "f:A5, pos:c" photo.pdf photo.jpg // Create a PDF with picture to the right side vertically centered. pdfcpu import -- "form:A5L, pos:r, off:-20 0" photo.pdf photo.jpg //convert your input images to greyscale: pdfcpu import -- "gray:true" gray.pdf test.jpg
Add, Remove or List PDF Document Properties via GO
Using the API you can also add, remove or list PDF document properties. Adding a document property is pretty simple, you just need to write and add property command and input the name of the property and value.
Add PDF Document Properties via Go
// Adding a property pdfcpu properties add in.pdf name = value //Adding two properties cpu properties add in.pdf 'name1 = value1' 'name2 = value2'
Similary, you can remove specific PDF document properties by using the following command.
Remove PDF Document Properties via Go
//Remove a specific property from in.pdf pdfcpu prop remove in.pdf dept // Remove all properties: pdfcpu prop remove test.pdf