Examples UniPDF

Starting from an example can speed up code development significantly.

Examples

Starting from an example can speed up code development significantly. Start from one of our provided examples, or contact us via [email protected] if the example you need is not provided.

The examples are also available on our UniPDF Examples repository:

View on Github

TitleDescription
Generate PDF reportsDemonstrates many of the common components used when creating a PDF report with UniPDF. Great starting point for creating advanced reports.
Crop pagesDemonstrates how to crop the MediaBox of a page in a PDF document using UniPDF.
Merge PDFsSimply loads all pages for each file and writes to the output file.
Advanced mergingFor a more basic merging of PDF page contents, see pdf_merge.go
Page infoPrints PDF page info: Mediabox size and other parameters
Rotate pageRotate pages in a PDF file. Degrees needs to be a multiple of 90
Split PDFBasic PDF split example: Splitting by page range
Advanced splittingAdvanced PDF split example: Takes into account optional content - OCProperties (rarely used)
Insert image to PDFAdds image to a specific page of a PDF. xPos and yPos define the upper left corner of the image location, and width
Extract images from PDF as ZIPExtract images from a PDF file. Passes through each page, goes through the content stream and finds instances of both
Convert images to PDFAdd images to a PDF file, one image per page
List of all images in PDFList images in a PDF file. Passes through each page, goes through the content stream and finds instances of both
Watermark PDFAdd watermark image to each page of a PDF file
Insert QR codeCreate a barcode or a QR code and insert on a specific location in a PDf file
Insert barcodeCreate a barcode and insert on a specific location in a PDf file
Check access permissionsCheck access permissions for a specified PDF
Protect PDFProtects PDF files by setting a password on it. This example both sets user and opening password and hard-codes the protection bits here, but easily adjusted in the code here although not on the command line.
Unlock PDF - remove passwordUnlocks PDF files, tries to decrypt encrypted documents with the given password, if that fails it tries an empty password as best effort.
Get PDF security infoOutputs protection information about locked PDFs.
Extract text from PDFPDF to text: Extract all text for each page of a pdf file.
Detect certain text in PDFBasic example for text searching: Retrieving position of a signature line in PDF where the signature line is given by text. And positioned with a Tm operation above.
Insert text to PDFInsert text to a specific page, location in a PDF file.
Draw line to PDFDraw a line in a new PDF file.
List of form fieldsLists form fields in a PDF file.
Detect scanned PDFDetect scanned PDF files by looking through the object types and determining whether it is likely to be a scanned file.
Get PDF objectGet specific object from a PDF by number. Prints the trailer dictionary if no number specified.
Basic PDF infoPrints basic PDF info: number of pages and encryption status.
Inspect PDF objectsInspect PDF object types. This example shows the capability of assessing the object types in PDF files.
Print content streamsList all content streams for all pages in a pdf file.
Annotate ellipseAnnotate/mark up pages of a PDF file.
Annotate lineAdd a line with arrowhead between two specified points on a page.
Annotate rectangleAdd a rectangle annotation to a specified location on a page.
Annotate w/textAdds a text annotation with a user specified string to a fixed location on every page.
List annotationsLists annotations in a PDF file.
Convert PDF to grayscaleConvert a PDF to grayscale in a vectorized fashion, including images and all content.

Ready to get started?