1. Products
  2.   PDF
  3.   GO
  4.   One File PDF
 
  

Open Source Go Library for PDF Document Generator

A minimalist PDF generator Go API that allows the developers to manipulate PDF Documents.

One File PDF is an open source PDF generation API for GO. It is a minimalist and lightweight PDF manipulation API. The main theme behind developing this API was to make and GO API as short as possible to cover 80% of PDF document generation needs. The small size of the API allows the developers.

The API provides a wide range of document generation features for generating a common business report. You can insert text, set font specify color, set columns, draw rectangles, circles, and ellipses, and insert JPEG, GIF, and PNG images in PDF files. Furthermore, the API allows setting metadata properties of PDF documents including author, creator, keywords, subject, and title.

.

Previous Next

Getting Started with One-File-PDF

To install the One-File-PDF on your system, please run the following command. 

Install One-File-PDF via GitHub

go get github.com/balacode/one-file-pdf

Generate PDF Document via Free Go Library

Generating PDF documents with Go is pretty simple. All you need to do is create a blank PDf document with A4 size by using pdf.NewPDF("A4") method of the API. You can set measurements of the document in centimeters using pdf.SetUnits("cm") method and Similarly draw a grid in the newly created PDF document using pdf.DrawUnitGrid() method.

Set Font in PDF using Free GO API

This lightweight open-source API allows basic document manipulation and generation operation for PDf documents. Once you have created a new document, you need to set font and font styles. Inorder to set fonts, pdf.SetFont() method, set position using pdf.SetXY() method and color of the text using pdf.SetColor() method respectively.

Draw Images in PDF Documents via Go

Images play a very significant part in conveying more information in a better and more complete way. The lightweight One File library provides complete support for drawing JPEG, GIF, and PNG Images as well as shapes in PDF files. It also provides support for modifying images according to your own needs.

Draw Images in PDF via Go

 func pngImages() {
	const FILENAME = "png_images.pdf"
	fmt.Println("Generating sample PDF:", FILENAME, "...")
	doc := pdf.NewPDF("A4")
	doc.SetUnits("cm")
	//
	// draw background pattern
	for x := 0.0; x < doc.PageWidth(); x += 6 {
		for y := 0.0; y < doc.PageHeight(); y += 5 {
			doc.DrawImage(x, y, 5, "../image/gophers.png", "cyan")
		}
	}
	// draw dice
	doc.SetColor("WHITE").FillBox(3.5, 4.5, 14.7, 17).
		//
		DrawImage(4, 5, 5, "../image/dice.png", "WHITE").
		DrawImage(11, 5, 5, "../image/dice.png", "RED").
		//
		DrawImage(4, 10.5, 5, "../image/dice.png", "GREEN").
		DrawImage(11, 10.5, 5, "../image/dice.png", "BLUE").
		//
		DrawImage(4, 16, 5, "../image/dice.png", "BLACK").
		SetFont("Helvetica-Bold", 50).
		SetXY(3, 3).SetColor("#009150").
		DrawText("PNG Image Demo")
	//
	doc.SaveFile(FILENAME)
} // pngImages
        
 English