pdf

package
v1.32.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 12 Imported by: 0

README

PDF Functions

  • ConvertHTMLToPDF: Converts an HTML string into a PDF document. Supports basic HTML elements including headings (<h1><h6>), paragraphs (<p>), bold (<b>, <strong>), italic (<i>, <em>), line breaks (<br>), links (<a>), and local images (<img>).
  • ExtractTextFromPDF: Extracts plain text content from all pages of a PDF file and returns it as a string.
  • MergePDFs: Combines multiple PDF files into a single output document, appending pages in order.
  • SplitPDF: Splits a PDF file into multiple smaller PDFs based on specified page ranges (e.g., "1-3", "5", "7-10").

Examples:

For examples of each function, please checkout EXAMPLES.md


Documentation

Overview

Package pdf provides utilities for creating and manipulating PDF documents.

This package includes functions for:

  • Converting HTML content to PDF documents
  • Extracting plain text from PDF files
  • Merging multiple PDF files into a single document
  • Splitting a PDF into multiple files based on page ranges

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertHTMLFileToPDF

func ConvertHTMLFileToPDF(inputPath string, outputPath string) error

ConvertHTMLFileToPDF reads an HTML file at inputPath and converts it to a PDF saved at outputPath. Supports the same HTML elements as ConvertHTMLToPDF.

func ConvertHTMLToPDF

func ConvertHTMLToPDF(htmlContent string, outputPath string) error

ConvertHTMLToPDF converts an HTML string into a PDF document and saves it to the specified output path.

Supported HTML elements:

  • Headings: <h1> through <h6>
  • Paragraphs: <p>
  • Bold: <b>, <strong>
  • Italic: <i>, <em>
  • Line breaks: <br>
  • Links: <a href="..."> (rendered as underlined text)
  • Images: <img src="..."> (local file paths only)

This function does not support CSS stylesheets, JavaScript, or complex HTML layouts such as tables or flexbox.

func ExtractTextFromPDF

func ExtractTextFromPDF(inputPath string) (string, error)

ExtractTextFromPDF extracts the plain text content from all pages of a PDF file and returns it as a single string. Pages are separated by a newline.

func MergePDFs

func MergePDFs(inputFiles []string, outputFile string) error

MergePDFs combines multiple PDF files into a single output document. The pages from each input file are appended in the order provided. At least two input files must be specified.

func SplitPDF

func SplitPDF(inputFile string, pageRanges []string, outputDir string) error

SplitPDF splits a PDF file into multiple smaller PDF files based on the specified page ranges. Each range produces a separate output PDF.

Page ranges are specified as strings such as "1-3", "5", or "7-10". Output files are saved in the specified directory with names like "pages_1-3.pdf", "pages_5-5.pdf", etc.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL