Convert Figma logo to code with AI

unidoc logounipdf

Golang PDF library for creating and processing PDF files (pure go)

2,543
250
2,543
52

Top Related Projects

4,318

A PDF document generator with high level support for text, drawing and images

2,509

A simple library for generating PDF written in Go lang

1,629

A maroto way to create PDFs. Maroto is inspired in Bootstrap and uses gofpdf. Fast and simple.

6,748

A PDF processor written in Go.

Quick Overview

UniPDF is a powerful PDF library for Go (Golang) that allows developers to create, manipulate, and extract content from PDF files. It provides a comprehensive set of tools for working with PDFs, including reading, writing, and modifying PDF documents programmatically.

Pros

  • Comprehensive PDF manipulation capabilities
  • Written in pure Go, with no external dependencies
  • High performance and efficient memory usage
  • Active development and community support

Cons

  • Commercial license required for most use cases
  • Limited free version with watermarking
  • Steeper learning curve compared to some simpler PDF libraries
  • Documentation could be more extensive for advanced features

Code Examples

  1. Creating a new PDF document:
import (
    "github.com/unidoc/unipdf/v3/creator"
    "github.com/unidoc/unipdf/v3/model"
)

c := creator.New()
c.NewPage()
c.DrawText("Hello, World!", 100, 100)
err := c.WriteToFile("output.pdf")
  1. Extracting text from a PDF:
import (
    "github.com/unidoc/unipdf/v3/extractor"
    "github.com/unidoc/unipdf/v3/model"
)

f, err := os.Open("input.pdf")
pdfReader, err := model.NewPdfReader(f)
page, err := pdfReader.GetPage(1)
ex, err := extractor.New(page)
text, err := ex.ExtractText()
  1. Merging multiple PDFs:
import (
    "github.com/unidoc/unipdf/v3/model"
)

pdfWriter := model.NewPdfWriter()
for _, file := range []string{"file1.pdf", "file2.pdf"} {
    f, _ := os.Open(file)
    pdfReader, _ := model.NewPdfReader(f)
    numPages, _ := pdfReader.GetNumPages()
    for i := 1; i <= numPages; i++ {
        page, _ := pdfReader.GetPage(i)
        err = pdfWriter.AddPage(page)
    }
}
pdfWriter.WriteToFile("merged.pdf")

Getting Started

To get started with UniPDF, follow these steps:

  1. Install UniPDF:

    go get github.com/unidoc/unipdf/v3
    
  2. Import the necessary packages in your Go code:

    import (
        "github.com/unidoc/unipdf/v3/creator"
        "github.com/unidoc/unipdf/v3/model"
    )
    
  3. Create a simple PDF:

    c := creator.New()
    c.NewPage()
    c.DrawText("My First PDF with UniPDF", 100, 100)
    err := c.WriteToFile("output.pdf")
    if err != nil {
        panic(err)
    }
    

Note: Make sure to handle errors appropriately in your production code.

Competitor Comparisons

4,318

A PDF document generator with high level support for text, drawing and images

Pros of gofpdf

  • Completely free and open-source, with no licensing restrictions
  • Simpler API, easier to learn and use for basic PDF generation tasks
  • Lighter weight and faster for basic PDF creation

Cons of gofpdf

  • Limited features compared to unipdf, especially for complex PDF operations
  • Lacks advanced capabilities like PDF parsing, form filling, and digital signatures
  • Less active development and community support

Code Comparison

gofpdf:

pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Arial", "B", 16)
pdf.Cell(40, 10, "Hello, World!")
pdf.OutputFileAndClose("hello.pdf")

unipdf:

pdf := creator.New()
page := pdf.NewPage()
font, _ := pdf.NewFont("Arial")
text := page.NewTextBox("Hello, World!")
text.SetFont(font)
text.SetFontSize(16)
pdf.Draw(text)
pdf.WriteToFile("hello.pdf")

Both libraries offer straightforward ways to create simple PDFs, but unipdf provides more advanced features and flexibility for complex PDF manipulation tasks.

2,509

A simple library for generating PDF written in Go lang

Pros of gopdf

  • Simpler API and easier to use for basic PDF generation tasks
  • Lightweight with fewer dependencies
  • Free and open-source without commercial licensing restrictions

Cons of gopdf

  • Limited features compared to unipdf, especially for complex PDF operations
  • Less active development and community support
  • Lacks advanced capabilities like PDF form filling and digital signatures

Code Comparison

gopdf:

pdf := gopdf.GoPdf{}
pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4})
pdf.AddPage()
pdf.SetFont("Arial", "", 14)
pdf.Cell(nil, "Hello, World!")

unipdf:

pdf := creator.New()
page := pdf.NewPage()
font, _ := pdf.NewFont("Arial")
p := creator.NewParagraph("Hello, World!")
p.SetFont(font)
page.Draw(p)

Both libraries offer straightforward ways to create simple PDFs, but unipdf provides more advanced features and flexibility for complex document generation tasks.

1,629

A maroto way to create PDFs. Maroto is inspired in Bootstrap and uses gofpdf. Fast and simple.

Pros of Maroto

  • Simpler API for creating PDFs, focusing on high-level components
  • Built-in support for common elements like tables, images, and QR codes
  • Designed specifically for generating reports and documents

Cons of Maroto

  • Less flexible for low-level PDF manipulation
  • Limited to creating new PDFs, not modifying existing ones
  • Smaller community and fewer features compared to UniPDF

Code Comparison

Maroto example:

m := maroto.New()
m.Row(40, func() {
    m.Col(12, func() {
        m.Text("Hello World")
    })
})
m.OutputFileAndClose("output.pdf")

UniPDF example:

pdf := creator.New()
p := pdf.NewPage()
p.DrawText("Hello World", 10, 10)
pdf.WriteToFile("output.pdf")

Both libraries offer ways to create PDFs in Go, but Maroto provides a more structured approach with rows and columns, while UniPDF offers lower-level control over element placement. Maroto is better suited for quickly generating reports, while UniPDF is more versatile for complex PDF operations.

6,748

A PDF processor written in Go.

Pros of pdfcpu

  • Open-source and free to use, with a permissive Apache 2.0 license
  • Lightweight and focused solely on PDF manipulation
  • Supports both CLI and API usage for flexibility

Cons of pdfcpu

  • Limited feature set compared to unipdf
  • Less active development and smaller community
  • Lacks advanced features like form filling and digital signatures

Code Comparison

pdfcpu:

import "github.com/pdfcpu/pdfcpu/pkg/api"

err := api.Validate(inputFile, nil)
err = api.Optimize(inputFile, outputFile, nil)

unipdf:

import "github.com/unidoc/unipdf/v3/model"

reader, _ := model.NewPdfReader(inputFile)
writer := model.NewPdfWriter()
err := writer.AddPage(reader.GetPage(1))
err = writer.WriteToFile(outputFile)

Both libraries offer straightforward APIs for PDF manipulation, but unipdf provides more comprehensive functionality for complex operations. pdfcpu focuses on core PDF tasks with a simpler interface, while unipdf offers a wider range of features at the cost of a steeper learning curve.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

UniPDF - PDF for Go

UniDoc UniPDF is a PDF library for Go (golang) with capabilities for creating and reading, processing PDF files. The library is written and supported by FoxyUtils.com, where the library is used to power many of its services.

GitHub (pre-)release License: UniDoc EULA ApiDocs

Features

Multiple examples are provided in our example repository https://github.com/unidoc/unipdf-examples.

Contact us if you need any specific examples.

Installation

With modules:

go get github.com/unidoc/unipdf/v3

License key

This software package (unipdf) is a commercial product and requires a license code to operate.

To Get a Metered License API Key in for free in the Free Tier, sign up on https://cloud.unidoc.io

How can I convince myself and my boss to buy unipdf rather using a free alternative?

The choice is yours. There are multiple respectable efforts out there that can do many useful things.

In UniDoc, we work hard to provide production quality builds taking every detail into consideration and providing excellent support to our customers. See our testimonials for example.

Security. We take security very seriously and we restrict access to github.com/unidoc/unipdf repository with protected branches and only the founders have access and every commit is reviewed prior to being accepted.

The profits are invested back into making unipdf better. We want to make the best possible product and in order to do that we need the best people to contribute. A large fraction of the profits made goes back into developing unipdf. That way we have been able to get many excellent people to work and contribute to unipdf that would not be able to contribute their work for free.

Contributing

If you are interested in contributing, please contact us.

Go Version Compatibility

Officially we support three latest Go versions, but internally we would test the build with up to five latest Go versions in our CI runner.

Support and consulting

Please email us at support@unidoc.io for any queries.

If you have any specific tasks that need to be done, we offer consulting in certain cases. Please contact us with a brief summary of what you need and we will get back to you with a quote, if appropriate.

License agreement

The use of this software package is governed by the end-user license agreement (EULA) available at: https://unidoc.io/eula/