### Install UniPDF Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/README.md Import the primary package to begin using UniPDF. A valid license from cloud.unidoc.io is required. ```go import "github.com/unidoc/unipdf/v4" ``` -------------------------------- ### Install UniPDF Go Library Source: https://github.com/unidoc/unipdf/blob/master/README.md Use this command to add the UniPDF library to your Go project with modules. ```go go get github.com/unidoc/unipdf/v4 ``` -------------------------------- ### Example of import group styles Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide An example illustrating the import grouping style with specific packages from the standard library, external dependencies, and UniPDF. ```go import ( "errors" "io/ioutil" "strings" "golang.org/x/text/unicode/norm" "github.com/unidoc/unipdf/v3/common" "github.com/unidoc/unipdf/v3/core" "github.com/unidoc/unipdf/v3/internal/textencoding" "github.com/unidoc/unipdf/v3/model/internal/fonts" ) ``` -------------------------------- ### Format Go section comments correctly Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Use a specific format for section comments: start with an empty line, then `//`, the comment, and another `//` followed by an empty line. ```go // Context defines operations for rendering to a particular target. type Context interface { // // Graphics state operations // // Push adds the current context state on the stack. Push() // Pop removes the most recent context state from the stack. Pop() // // Matrix operations // // Matrix returns the current transformation matrix. Matrix() // SetMatrix modifies the transformation matrix. SetMatrix(m transform.Matrix) } ``` -------------------------------- ### Explicitly declare unsigned 64-bit integer with initial value Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide If both the initial value and type are important and not obvious, declare them explicitly. This example shows an unsigned 64-bit integer initialized to 0. ```go offset := uint64(0) ``` -------------------------------- ### Explicitly declare boolean with initial value Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide When both the initial value and type are important and not obvious, declare them explicitly. This example shows a boolean initialized to false. ```go useX := false ``` -------------------------------- ### Initialize License Key Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/configuration.md Configure the UniPDF license key via environment variables or programmatically to enable library functionality. ```go import ( "github.com/unidoc/unipdf/v4/model" ) // License key is set via environment variable or configuration // Set UNIDOC_LICENSE_API_KEY environment variable // or configure programmatically if API allows // Once configured, usage is automatic reader, _ := model.NewReader(file) // Library checks license validity internally ``` -------------------------------- ### Create a simple PDF document Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/creator.md Demonstrates the basic workflow of creating a document, adding a page, inserting a paragraph, and saving to a file. ```go import ( "github.com/unidoc/unipdf/v4/creator" "github.com/unidoc/unipdf/v4/model" ) // Create document c := creator.New() c.SetPageSize(creator.PageSizeLetter) // Add page page := c.AddPage() // Add content paragraph := creator.NewParagraph("Hello, PDF!") page.Add(paragraph) // Save to file c.WriteToFile("output.pdf") ``` -------------------------------- ### Create and add tables Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/creator.md Initializes a table structure, defines column widths, and populates cells. ```go import ( "github.com/unidoc/unipdf/v4/creator" ) c := creator.New() page := c.AddPage() // Create table table := creator.NewTable(3, 2) table.SetColumnWidth(0, 200) table.SetColumnWidth(1, 200) // Add cells cell1 := creator.NewTableCell("Name") cell2 := creator.NewTableCell("Value") table.SetCell(0, 0, cell1) table.SetCell(0, 1, cell2) // Add to page page.Add(table) c.WriteToFile("table.pdf") ``` -------------------------------- ### Configure Creator Options in Go Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/configuration.md Set page dimensions, margins, PDF versions, and output destinations for the PDF creator. ```go import ( "github.com/unidoc/unipdf/v4/creator" ) c := creator.New() // Page size c.SetPageSize(creator.PageSizeLetter) // Custom page dimensions c.SetPageSize(pageWidth, pageHeight) // in points (1/72 inch) // Margins (left, right, top, bottom) c.SetPageMargins(50, 50, 50, 50) // PDF version (default 1.4) c.SetPdfVersion(1, 7) // Output PDF to file c.WriteToFile("output.pdf") // Output PDF to stream c.Write(outputWriter) // Get page count numPages := c.GetPages() ``` -------------------------------- ### Initialize a PDF Writer Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/core.md Creates a new instance of a PDF writer for generating PDF documents. ```go import ( "github.com/unidoc/unipdf/v4/core" ) writer := core.NewWriter() // Use writer to create PDF objects and write file ``` -------------------------------- ### Create PDF Objects Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/core.md Shows how to instantiate common PDF object types like dictionaries, arrays, and strings. ```go import ( "github.com/unidoc/unipdf/v4/core" ) // Create a dictionary dict := core.NewPdfObjectDictionary() dict.Set(core.PdfObjectName("Type"), core.MakeName("Catalog")) dict.Set(core.PdfObjectName("Pages"), core.MakeInteger(5)) // Create an array array := core.NewPdfObjectArray() array.Append(core.MakeInteger(100)) array.Append(core.MakeFloat(3.14)) // Create a string str := core.MakeString("Hello, PDF!") ``` -------------------------------- ### Read PDF Objects Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/core.md Demonstrates how to open a file, retrieve the trailer dictionary, and iterate through objects by index. ```go import ( "os" "github.com/unidoc/unipdf/v4/core" ) file, _ := os.Open("input.pdf") defer file.Close() parser, _ := core.NewParser(file) trailer, _ := parser.GetTrailerDict() // Iterate through PDF objects for objNum := 0; objNum < 100; objNum++ { obj, _ := parser.GetObject(objNum, 0) // Process object } ``` -------------------------------- ### Initialize empty map Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide For empty maps where the size is not known a priori, use `make` without a capacity hint. ```go m := make(map[x]y) ``` -------------------------------- ### Initialize a new Creator instance Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/creator.md Creates a new PDF creator object and sets the page size. ```go import ( "github.com/unidoc/unipdf/v4/creator" ) c := creator.New() c.SetPageSize(creator.PageSizeLetter) ``` -------------------------------- ### Initialize a Console Logger Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/common.md Creates a logger instance that outputs to standard output with a specified minimum log level. ```go logger := common.NewConsoleLogger(common.LogLevelDebug) ``` -------------------------------- ### Standard import group style Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Demonstrates the recommended import grouping style, separating standard library, external dependencies, and internal UniPDF imports. ```go import ( // standard library imports // external dependency imports // unipdf public imports // unipdf internal imports ) ``` -------------------------------- ### Build a multi-page report Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/creator.md Shows how to manage multiple pages and set margins for a document. ```go import ( "github.com/unidoc/unipdf/v4/creator" ) c := creator.New() c.SetPageSize(creator.PageSizeLetter) c.SetPageMargins(50, 50, 50, 50) // Page 1 page1 := c.AddPage() title := creator.NewParagraph("Report Title") page1.Add(title) // Page 2 c.NewPage() page2 := c.AddPage() content := creator.NewParagraph("Content for page 2") page2.Add(content) c.WriteToFile("report.pdf") ``` -------------------------------- ### Initialize a PDF Parser Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/core.md Creates a new parser instance from an io.ReadSeeker. Ensure the reader is seekable and points to a valid PDF file. ```go import ( "os" "github.com/unidoc/unipdf/v4/core" ) file, _ := os.Open("document.pdf") defer file.Close() parser, err := core.NewParser(file) if err != nil { panic(err) } version, _, _ := parser.GetVersion() // version is now the PDF version number ``` -------------------------------- ### Initialize map with known size Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide When the map size is known beforehand, use `make` with a capacity hint for potential performance benefits. ```go m := make(map[x]y, 10) ``` -------------------------------- ### Configure Console Logging in Go Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/common.md Initializes the console logger and demonstrates conditional logging to optimize performance during expensive operations. ```go import ( "log" "github.com/unidoc/unipdf/v4/common" ) func main() { // Set up logging common.SetLogger(common.NewConsoleLogger(common.LogLevelDebug)) // Check log level before expensive operations if common.Log.IsLogLevel(common.LogLevelDebug) { // This code only runs if debug level is enabled common.Log.Debug("Processing PDF: %v", expensiveDebugInfo()) } } ``` -------------------------------- ### Initialize a Writer Logger Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/common.md Creates a logger instance that writes logs to a specified io.Writer, such as a file. ```go logFile, _ := os.Create("app.log") defer logFile.Close() logger := common.NewWriterLogger(common.LogLevelInfo, logFile) ``` -------------------------------- ### Initialize Extractor with Options Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/extractor.md Configures extraction behavior using custom options such as skipping images or handling missing fonts. ```go opts := &extractor.Options{ SkipImages: true, SkipMissingFonts: false, } ex, _ := extractor.NewWithOptions(page, opts) ``` -------------------------------- ### Handle permission denied errors Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/errors.md Use os.IsPermission to identify file access issues. ```go import ( "os" ) err := writer.WriteToFile("output.pdf") if err != nil { if os.IsPermission(err) { // Permission denied } } ``` -------------------------------- ### License header format for Go files Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Ensures a consistent license header is present at the beginning of each Go file, preceding the package declaration. ```go /* * This file is subject to the terms and conditions defined in * file 'LICENSE.md', which is part of this source code package. */ package ... ``` -------------------------------- ### Iterate Through PDF Pages Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/model.md Demonstrates how to open a PDF and iterate through its pages to process content. ```go import ( "os" "github.com/unidoc/unipdf/v4/model" ) file, _ := os.Open("input.pdf") defer file.Close() reader, _ := model.NewReader(file) // Iterate through pages for i := 1; i <= reader.GetPageCount(); i++ { page, _ := reader.GetPage(i) contents, _ := page.GetContents() // Process page content } ``` -------------------------------- ### Initialize WriterLogger Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/common.md Configures a logger to write output to a specific file. ```go import ( "os" "github.com/unidoc/unipdf/v4/common" ) // Create a logger that writes to a file logFile, _ := os.Create("unipdf.log") logger := common.NewWriterLogger(common.LogLevelDebug, logFile) common.SetLogger(logger) ``` -------------------------------- ### Create a Complete PDF Form Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/annotator.md Demonstrates the workflow for adding multiple field types to a PDF page and saving the resulting document. ```go import ( "github.com/unidoc/unipdf/v4/annotator" "github.com/unidoc/unipdf/v4/model" ) reader, _ := model.NewReader(file) writer := model.NewWriter() page, _ := reader.GetPage(1) // Add text field textOpts := annotator.TextFieldOptions{Value: ""} textField, _ := annotator.NewTextField(page, "name", []float64{100, 700, 300, 720}, textOpts) // Add checkbox checkboxOpts := annotator.CheckboxFieldOptions{Checked: false} checkboxField, _ := annotator.NewCheckboxField(page, "agree", []float64{100, 650, 130, 680}, checkboxOpts) // Add dropdown comboOpts := annotator.ComboboxFieldOptions{ Options: []string{"Yes", "No"}, Value: "No", } comboField, _ := annotator.NewComboboxField(page, "question", []float64{100, 600, 250, 620}, comboOpts) // Add submit button submitOpts := annotator.FormSubmitActionOptions{ Url: "https://api.example.com/forms", } submitBtn, _ := annotator.NewFormSubmitButtonField(page, submitOpts) writer.AddPage(page) writer.WriteToFile("form.pdf") ``` -------------------------------- ### Create a PDF Document Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/README.md Generate a new PDF file with custom page sizes and added content using the creator package. ```go import ( "github.com/unidoc/unipdf/v4/creator" ) c := creator.New() c.SetPageSize(creator.PageSizeLetter) page := c.AddPage() paragraph := creator.NewParagraph("Hello, PDF!") page.Add(paragraph) c.WriteToFile("output.pdf") ``` -------------------------------- ### Initialize ConsoleLogger Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/common.md Configures a console logger to output messages at the Info level and above. ```go import ( "github.com/unidoc/unipdf/v4/common" ) // Create a console logger that outputs info level and above logger := common.NewConsoleLogger(common.LogLevelInfo) common.SetLogger(logger) ``` -------------------------------- ### Run Go Vet Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Check the unidoc project for suspicious constructs. This command should not return any issues. ```go go vet github.com/unidoc/unidoc/... ``` -------------------------------- ### Initialize and Parse Content Stream Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/contentstream.md Creates a parser instance from a raw content string and executes the parsing process to retrieve operations. ```go import ( "github.com/unidoc/unipdf/v4/contentstream" ) content := "BT /F1 12 Tf 100 700 Td (Hello World) Tj ET" parser := contentstream.NewParser(content) ops, _ := parser.Parse() ``` -------------------------------- ### Initialize a PDF Reader Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/model.md Creates a new reader instance from an io.ReadSeeker source. Ensure the file is closed after processing. ```go import ( "os" "github.com/unidoc/unipdf/v4/model" ) file, _ := os.Open("document.pdf") defer file.Close() reader, err := model.NewReader(file) if err != nil { panic(err) } numPages := reader.GetPageCount() ``` -------------------------------- ### Handle file not found errors Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/errors.md Use os.IsNotExist to identify missing file errors. ```go import ( "os" ) file, err := os.Open("nonexistent.pdf") if err != nil { if os.IsNotExist(err) { // File not found } } ``` -------------------------------- ### Create a new content block Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/creator.md Initializes a block container with specific dimensions to hold content. ```go block := creator.NewBlock(500, 300) block.Add(paragraph) ``` -------------------------------- ### Apply Extraction Options Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/configuration.md Initializes an extractor with custom options to process page content. ```go import ( "github.com/unidoc/unipdf/v4/extractor" ) opts := &extractor.Options{ SkipImages: true, SkipMissingFonts: false, IncludeMetadata: true, } ex, _ := extractor.NewWithOptions(page, opts) text, _ := ex.ExtractText() marks, _ := ex.ExtractTextMarks() ``` -------------------------------- ### Documenting Interface Implementation in Go Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide When implementing an interface, add a comment indicating this. If the function has unusual behavior, note it. ```go // ToPdfObject implements interface PdfModel. func (stamp *PdfAnnotationStamp) ToPdfObject() core.PdfObject { stamp.PdfAnnotation.ToPdfObject() container := stamp.container d := container.PdfObject.(*core.PdfObjectDictionary) stamp.PdfAnnotationMarkup.appendToPdfDictionary(d) d.SetIfNotNil("Subtype", core.MakeName("Stamp")) d.SetIfNotNil("Name", stamp.Name) return container } ``` ```go // ToPdfObject implements interface PdfModel. // Note: Call the sub-annotation's ToPdfObject to set both the generic and non-generic information. func (a *PdfAnnotation) ToPdfObject() core.PdfObject { ... ``` -------------------------------- ### Run Go Tests Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Execute all tests in the unidoc project. This command should pass without exceptions. ```go go test -v github.com/unidoc/unidoc/... ``` -------------------------------- ### Check document permissions Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/errors.md Verify if the document allows specific operations. ```go document, err := reader.GetDocument() if err == nil { // Check permissions if available // Permissions are typically enforced by PDF viewers } ``` -------------------------------- ### Rotate and Scale PDF Pages Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/model.md Shows how to read pages from an existing document, apply rotation, and save them to a new file. ```go import ( "github.com/unidoc/unipdf/v4/model" ) reader, _ := model.NewReader(file) writer := model.NewWriter() for i := 1; i <= reader.GetPageCount(); i++ { page, _ := reader.GetPage(i) // Rotate 90 degrees page.SetRotate(90) writer.AddPage(page) } writer.WriteToFile("rotated.pdf") ``` -------------------------------- ### creator.New() Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/creator.md Initializes a new PDF creator instance used to build documents. ```APIDOC ## func New() ### Description Creates a new PDF creator instance. ### Returns - ***Creator** - New document creator ### Example ```go c := creator.New() c.SetPageSize(creator.PageSizeLetter) ``` ``` -------------------------------- ### Manage PDF Versioning Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/configuration.md Sets the output PDF version for a writer and retrieves the version from an existing reader. ```go import ( "github.com/unidoc/unipdf/v4/core" "github.com/unidoc/unipdf/v4/model" ) reader, _ := model.NewReader(file) writer := model.NewWriter() // Set output version writer.SetPdfVersion(1, 7) // Get current version from reader parser, _ := core.NewParser(file) major, minor, _ := parser.GetVersion() ``` -------------------------------- ### Configure UniPDF logging levels Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/errors.md Set the global logger to Debug or Trace levels to troubleshoot internal processing issues. ```go import ( "github.com/unidoc/unipdf/v4/common" ) // Enable debug logging for troubleshooting common.SetLogger(common.NewConsoleLogger(common.LogLevelDebug)) // Enable trace for very detailed output common.SetLogger(common.NewConsoleLogger(common.LogLevelTrace)) ``` -------------------------------- ### Configure Stream Encoders Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/configuration.md Select appropriate encoders for PDF stream compression based on performance and file size requirements. ```go import ( "github.com/unidoc/unipdf/v4/core" ) // No compression (fast, large files) encoder := &core.RawEncoder{} // Deflate/Zlib (good compression, fast) encoder := &core.FlateEncoder{} // JPEG/DCT (lossy image compression) encoder := &core.DCTEncoder{ Quality: 85, // 0-100, higher = better quality } // ASCII Hex (text-safe, no compression) encoder := &core.ASCIIHexEncoder{} // Run-length (minimal compression) encoder := &core.RunLengthEncoder{} // LZW (moderate compression) encoder := &core.LZWEncoder{} // For fax documents encoder := &core.CCITTFaxEncoder{ K: -1, // Group 4 encoding } ``` -------------------------------- ### Create signature field options in Go Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/annotator.md Initializes default appearance options for a signature field, which can then be modified. ```go opts := annotator.NewSignatureFieldOpts() opts.FontSize = 14 opts.FillOpacity = 0.9 ``` -------------------------------- ### Configure PDF Encryption Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/configuration.md Sets user and owner passwords with specific encryption permissions before writing to a file. ```go import ( "github.com/unidoc/unipdf/v4/model" ) writer := model.NewWriter() // Set user and owner passwords err := writer.SetEncryption("userpassword", "ownerpassword", model.EncryptionPermissions40Bit) if err != nil { panic(err) } writer.WriteToFile("encrypted.pdf") ``` -------------------------------- ### Extract with Custom Options Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/extractor.md Configures extraction behavior using the Options struct. ```go import ( "github.com/unidoc/unipdf/v4/extractor" ) opts := &extractor.Options{ SkipImages: true, SkipAnnotations: true, IncludeMetadata: true, } ex, _ := extractor.NewWithOptions(page, opts) text, _ := ex.ExtractText() ``` -------------------------------- ### Create a new text field in Go Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/annotator.md Initializes a text input field on a specific PDF page with defined dimensions and configuration options. ```go import ( "github.com/unidoc/unipdf/v4/annotator" "github.com/unidoc/unipdf/v4/model" ) page, _ := reader.GetPage(1) opts := annotator.TextFieldOptions{ Value: "Default text", MaxLen: 100, } field, _ := annotator.NewTextField(page, "myTextField", []float64{50, 50, 200, 80}, opts) field.SetValue("User input") ``` -------------------------------- ### Create Content Stream in Go Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/contentstream.md Constructs a new content stream by adding text rendering and graphics operations, then applies it to a page. ```go import ( "github.com/unidoc/unipdf/v4/contentstream" "github.com/unidoc/unipdf/v4/core" ) ops := &contentstream.ContentStreamOperations{} // Text rendering ops.AddOperationWithParams("BT") ops.AddOperationWithParams("Tf", core.MakeName("F1"), core.MakeFloat(12)) ops.AddOperationWithParams("Td", core.MakeFloat(50), core.MakeFloat(700)) ops.AddOperationWithParams("Tj", core.MakeString("Sample Text")) ops.AddOperationWithParams("ET") // Graphics ops.AddOperationWithParams("q") ops.AddOperationWithParams("1", core.MakeFloat(0), core.MakeFloat(0), core.MakeFloat(1), core.MakeFloat(100), core.MakeFloat(100)) ops.AddOperationWithParams("S") ops.AddOperationWithParams("Q") // Set to page contentBytes := []byte(ops.String()) page.SetContents(contentBytes) ``` -------------------------------- ### Define Extraction Options Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/configuration.md Defines the configuration structure for controlling content extraction behavior. ```go type Options struct { SkipImages bool // Skip image content SkipAnnotations bool // Skip annotation content SkipMissingFonts bool // Skip text with missing fonts IncludeMetadata bool // Include text metadata } ``` -------------------------------- ### Add images to a document Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/creator.md Loads an image from a file, sets its display width, and adds it to a page. ```go import ( "github.com/unidoc/unipdf/v4/creator" ) c := creator.New() page := c.AddPage() // Add image img, _ := creator.NewImage("logo.png") img.SetWidth(200) page.Add(img) c.WriteToFile("with_image.pdf") ``` -------------------------------- ### Create a new combobox field in Go Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/annotator.md Creates a dropdown selection field with a predefined list of options. ```go opts := annotator.ComboboxFieldOptions{ Options: []string{"Option 1", "Option 2", "Option 3"}, Value: "Option 1", } field, _ := annotator.NewComboboxField(page, "choice", []float64{50, 150, 200, 180}, opts) ``` -------------------------------- ### Define TextFieldOptions structure Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/annotator.md Configures properties for text field creation. ```go type TextFieldOptions struct { Value string MaxLen int Appearance FieldAppearance Required bool DefaultValue string } ``` -------------------------------- ### Options Type Definition Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/extractor.md Defines configuration settings for controlling extraction behavior. ```go type Options struct { // Extraction options } ``` -------------------------------- ### Access Library Version Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/common.md Retrieves the current version string of the UniPDF library. ```go import ( "log" "github.com/unidoc/unipdf/v4/common" ) log.Printf("UniPDF version: %s", common.Version) ``` -------------------------------- ### Verify image dimensions Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/errors.md Compare image sample size against expected dimensions. ```go width := img.GetWidth() height := img.GetHeight() samples := img.GetSamples() if len(samples) != width*height*components { // Image data size mismatch } ``` -------------------------------- ### Use blank lines to separate logic within long Go blocks Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Employ blank lines judiciously to separate distinct logical sections within complex code blocks, improving comprehension. ```go if condition1 { // many lines of code ... } if condition2 { // many lines of code ... } ``` -------------------------------- ### NewWithOptions Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/extractor.md Creates a new extractor instance with custom configuration options. ```APIDOC ## func NewWithOptions(page *model.PdfPage, opts *Options) (*Extractor, error) ### Description Creates a new extractor with custom options. ### Parameters - **page** (*model.PdfPage) - Required - Page to extract from - **opts** (*Options) - Required - Extraction options ### Returns - (*Extractor, error) - Extractor instance, or error ### Example ```go opts := &extractor.Options{ SkipImages: true, SkipMissingFonts: false, } ex, _ := extractor.NewWithOptions(page, opts) ``` ``` -------------------------------- ### Iterator loop with explicit initialization Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Demonstrates a basic for loop with an explicitly initialized counter variable. ```go for i := 0; i < 20; i++ { ... } ``` -------------------------------- ### Create Block from Page Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/extractor.md Generates a block structure from page content to facilitate structured text retrieval. ```go block, _ := extractor.NewBlockFromPage(page) text := block.Text() ``` -------------------------------- ### Initialize Extractor Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/extractor.md Creates a new extractor instance for a specific PDF page to enable text extraction. ```go import ( "github.com/unidoc/unipdf/v4/model" "github.com/unidoc/unipdf/v4/extractor" ) reader, _ := model.NewReader(file) page, _ := reader.GetPage(1) ex, _ := extractor.New(page) text, _ := ex.ExtractText() ``` -------------------------------- ### TODO/FIXME/NOTE Comment Convention Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide When using TODO, FIXME, or NOTE comments, include the author's GitHub handle. ```go // FIXME(gunnsth): Not working for case t = 3. ``` -------------------------------- ### Create a form submit button in Go Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/annotator.md Adds a button to the PDF that triggers a form submission to a specified URL. ```go opts := annotator.FormSubmitActionOptions{ Url: "https://example.com/form-submit", IncludeEmptyFields: false, SubmitAsPDF: true, } button, _ := annotator.NewFormSubmitButtonField(page, opts) ``` -------------------------------- ### Utility functions for PdfObject type conversions (v3) Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide A list of utility functions available in the core package (v3) for converting PdfObject to specific types and retrieving their values. ```go func GetBool(obj PdfObject) (bo *PdfObjectBool, found bool) {} func GetBoolVal(obj PdfObject) (b bool, found bool) {} func GetInt(obj PdfObject) (into *PdfObjectInteger, found bool) {} func GetIntVal(obj PdfObject) (val int, found bool) {} func GetFloat(obj PdfObject) (fo *PdfObjectFloat, found bool) {} func GetFloatVal(obj PdfObject) (val float64, found bool) {} func GetString(obj PdfObject) (so *PdfObjectString, found bool) {} func GetStringVal(obj PdfObject) (val string, found bool) {} func GetStringBytes(obj PdfObject) (val []byte, found bool) {} func GetName(obj PdfObject) (name *PdfObjectName, found bool) {} func GetArray(obj PdfObject) (arr *PdfObjectArray, found bool) {} func GetDict(obj PdfObject) (dict *PdfObjectDictionary, found bool) {} func GetIndirect(obj PdfObject) (ind *PdfIndirectObject, found bool) {} func GetStream(obj PdfObject) (stream *PdfObjectStream, found bool) {} func GetNumberAsFloat(obj PdfObject) (float64, error) {} func GetNumbersAsFloat(objects []PdfObject) (floats []float64, err error) {} func GetNumberAsInt64(obj PdfObject) (int64, error) {} ``` -------------------------------- ### Define Color Spaces in Go Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/configuration.md Create color objects using Grayscale, RGB, or CMYK color spaces. Values for components typically range from 0.0 to 1.0. ```go import ( "github.com/unidoc/unipdf/v4/model" ) // Grayscale (0.0 = black, 1.0 = white) gray := model.NewPdfColorDeviceGray(0.5) // RGB (0.0-1.0 per component) red := model.NewPdfColorDeviceRGB(1.0, 0.0, 0.0) green := model.NewPdfColorDeviceRGB(0.0, 1.0, 0.0) blue := model.NewPdfColorDeviceRGB(0.0, 0.0, 1.0) // CMYK (0.0-1.0 per component) cyan := model.NewPdfColorDeviceCMYK(1.0, 0.0, 0.0, 0.0) magenta := model.NewPdfColorDeviceCMYK(0.0, 1.0, 0.0, 0.0) yellow := model.NewPdfColorDeviceCMYK(0.0, 0.0, 1.0, 0.0) black := model.NewPdfColorDeviceCMYK(0.0, 0.0, 0.0, 1.0) // Common colors white := model.NewPdfColorDeviceRGB(1.0, 1.0, 1.0) black := model.NewPdfColorDeviceRGB(0.0, 0.0, 0.0) ``` -------------------------------- ### Initialize Standard Fonts in Go Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/configuration.md Use built-in fonts that do not require embedding. These fonts are available by default in the model package. ```go import ( "github.com/unidoc/unipdf/v4/model" ) // Use built-in fonts helvetica := model.NewPdfFontHelvetica() times := model.NewPdfFontTimes() courier := model.NewPdfFontCourier() symbol := model.NewPdfFontSymbol() zapfdingbats := model.NewPdfFontZapfDingbats() // Default font defaultFont := model.DefaultFont() // Add to page style := creator.TextStyle{ Font: helvetica, FontSize: 12, } ``` -------------------------------- ### Create a styled text chunk Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/creator.md Defines a text segment with specific font size and color properties. ```go style := creator.TextStyle{ FontSize: 12, Color: creator.ColorBlack, } chunk := creator.NewTextChunk("Hello World", style) ``` -------------------------------- ### Validate required PDF fields Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/errors.md Check for missing required dictionary entries like MediaBox. ```go page, err := reader.GetPage(1) if err != nil { // Page structure is invalid } mediaBox := page.GetMediaBox() if mediaBox == nil { // MediaBox is missing } ``` -------------------------------- ### Implement a Custom Logger in Go Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/common.md Defines a custom logger structure by implementing the required interface methods and registering it with the common package. ```go type CustomLogger struct { minLevel common.LogLevel } func (cl *CustomLogger) Error(format string, args ...interface{}) { // Custom error handling } func (cl *CustomLogger) IsLogLevel(level common.LogLevel) bool { return level <= cl.minLevel } // ... implement other Logger methods ... // Use the custom logger common.SetLogger(&CustomLogger{minLevel: common.LogLevelInfo}) ``` -------------------------------- ### Define ComboboxFieldOptions structure Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/annotator.md Configures properties for dropdown or combobox field creation. ```go type ComboboxFieldOptions struct { Options []string Value string Appearance FieldAppearance } ``` -------------------------------- ### Logging Program Flow with Trace Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Use Trace level for frequent messages to understand program flow during debugging. ```go bb, _ := parser.reader.Peek(100) common.Log.Trace("OBJ peek \"%s\"", string(bb)) ``` -------------------------------- ### Create a Form Reset Button Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/annotator.md Initializes a new form reset button field with specified target fields. ```go opts := annotator.FormResetActionOptions{ Fields: []string{"field1", "field2"}, } button, _ := annotator.NewFormResetButtonField(page, opts) ``` -------------------------------- ### Prefer direct package imports in Go Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Avoid using package aliases for imports unless absolutely necessary, such as when importing packages with identical names. ```go import ( aimage "a/image" bimage "b/image" ) ``` ```go import ( "a/image" bimage "b/image" ) ``` ```go import ( "f/somepackage" ) ``` ```go import ( somepkg "f/somepackage" ) ``` -------------------------------- ### Create a new signature field in Go Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/annotator.md Generates a signature field with custom display lines and appearance settings. ```go signature := model.NewPdfSignature() lines := []*annotator.SignatureLine{ annotator.NewSignatureLine("Digitally signed by:", "John Doe"), annotator.NewSignatureLine("Date:", "2024-01-15"), } opts := annotator.NewSignatureFieldOpts() opts.FontSize = 12 opts.TextColor = model.NewPdfColorDeviceRGB(0, 0, 0) field, _ := annotator.NewSignatureField(signature, lines, opts) ``` -------------------------------- ### Map literal with pre-defined data Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Use a map literal to initialize a map with predefined key-value pairs. ```go commits := map[string]int{ "rsc": 3711, "r": 2138, "gri": 1908, "adg": 912, } ``` -------------------------------- ### creator.NewBlock(width, height) Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/creator.md Creates a new content block with specified dimensions for layout management. ```APIDOC ## func NewBlock(width, height float64) ### Description Creates a new content block with specified dimensions. ### Parameters - **width** (float64) - Block width in points - **height** (float64) - Block height in points ### Returns - ***Block** - New block container ### Example ```go block := creator.NewBlock(500, 300) block.Add(paragraph) ``` ``` -------------------------------- ### Logging Critical Image Loading Errors with Error Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Use the Error level for critical errors like image loading failures, and return the error. ```go // Load the image with default handler. img, err := model.ImageHandling.Read(imgReader) if err != nil { common.Log.Error("Error loading image: %s", err) return nil, err } ``` -------------------------------- ### Define SignatureFieldOpts structure Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/annotator.md Configures the appearance and behavior of signature fields. ```go type SignatureFieldOpts struct { Font *PdfFont FontSize float64 LineHeight float64 AutoSize bool TextColor Color BorderColor Color FillColor Color FillOpacity float64 Encoder StreamEncoder ImagePosition SignatureImagePosition } ``` -------------------------------- ### Work with PDF Forms Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/README.md Add interactive text fields to a PDF page and save the resulting document. ```go import ( "github.com/unidoc/unipdf/v4/annotator" "github.com/unidoc/unipdf/v4/model" ) page, _ := reader.GetPage(1) // Create text field opts := annotator.TextFieldOptions{Value: "Default"} field, _ := annotator.NewTextField(page, "username", []float64{100, 700, 300, 720}, opts) writer := model.NewWriter() writer.AddPage(page) writer.WriteToFile("form.pdf") ``` -------------------------------- ### Define CheckboxFieldOptions structure Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/annotator.md Configures properties for checkbox field creation. ```go type CheckboxFieldOptions struct { Checked bool Appearance FieldAppearance } ``` -------------------------------- ### Embed TrueType/OpenType Fonts in Go Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/configuration.md Load external font files from the filesystem for use in documents. Ensure the file path is accessible to the application. ```go import ( "github.com/unidoc/unipdf/v4/model" ) // Load external font file font, err := model.NewPdfFontFromTTFFile("/path/to/font.ttf") if err != nil { panic(err) } // Use in document style := creator.TextStyle{ Font: font, FontSize: 14, } ``` -------------------------------- ### Define Version structure Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/core.md Represents a PDF version number, such as 1.4 or 2.0. ```go type Version struct { Major int Minor int } ``` -------------------------------- ### Define FormResetActionOptions structure Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/annotator.md Configures the behavior of form reset actions. ```go type FormResetActionOptions struct { IsExclusionList bool Fields []string } ``` -------------------------------- ### Handle errors by passing them up the stack Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide When an error occurs, it should be logged in Debug mode and passed up the call stack. This is preferred for input file-related errors. ```go err := doStuff() if err != nil { common.Log.Debug("ERROR: doStuff failed: %v", err) return err } ``` -------------------------------- ### Prevent Nil Pointer Dereferences Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/errors.md Ensure objects and properties are initialized before access. ```go if page != nil && page.GetMediaBox() != nil { width := page.GetMediaBox().GetWidth() } ``` -------------------------------- ### Define TextStyle Type Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/creator.md Defines formatting properties for text elements. ```go type TextStyle struct { Font *pdf.PdfFont FontSize float64 Color Color Bold bool Italic bool } ``` -------------------------------- ### Extract Text Marks Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/extractor.md Retrieves text along with its position, size, and formatting metadata. ```go marks, _ := ex.ExtractTextMarks() for _, mark := range marks { printf("Text: %s at (%f, %f)\n", mark.Text, mark.X, mark.Y) } ``` -------------------------------- ### Define Creator Type Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/creator.md The main structure for building PDF documents. ```go type Creator struct { // PDF document creator } ``` -------------------------------- ### Declare empty slices using var Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide When declaring empty slices, prefer using `var` over an empty slice literal for clarity and consistency. ```go var t []string ``` -------------------------------- ### Extract Text from Page Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/extractor.md Extracts all text from a page as a single string. ```go ex, _ := extractor.New(page) text, _ := ex.ExtractText() println(text) ``` -------------------------------- ### Validate PDF structure with core parser Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/errors.md Attempt to parse a file to verify its integrity and retrieve version information. ```go import ( "os" "github.com/unidoc/unipdf/v4/core" ) file, err := os.Open("document.pdf") if err != nil { panic(err) } defer file.Close() // Attempt to parse as sanity check parser, err := core.NewParser(file) if err != nil { println("PDF is invalid:", err) return } major, minor, err := parser.GetVersion() if err == nil { printf("PDF version: %d.%d\n", major, minor) } ``` -------------------------------- ### Version Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/common.md Retrieves the current version string of the UniPDF library. ```APIDOC ## Version ### Description Constant representing the current UniPDF version string. ### Example ```go import ( "log" "github.com/unidoc/unipdf/v4/common" ) log.Printf("UniPDF version: %s", common.Version) ``` ``` -------------------------------- ### Avoid blank lines at the top of Go blocks Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Prefer code without leading blank lines within function blocks for better readability. ```go func x() { return } ``` ```go func x() { if 2 > 1 { return } } ``` -------------------------------- ### Define PdfObject interface Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/core.md The base interface for all PDF primitive objects. ```go type PdfObject interface { // Base interface for all PDF objects } ``` -------------------------------- ### NewParser Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/core.md Creates a new PDF parser instance from an io.ReadSeeker source. ```APIDOC ## func NewParser(rs io.ReadSeeker) (*PdfParser, error) ### Description Creates a new PDF parser from a reader. Returns a parser instance or an error if the PDF format is invalid or the reader is unseekable. ### Parameters - **rs** (io.ReadSeeker) - Required - Source for PDF file data ### Returns - **(*PdfParser, error)** - Parser instance, or error if invalid PDF ``` -------------------------------- ### Configure text extraction with missing fonts Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/errors.md Use extractor options to skip missing fonts during text extraction. ```go import ( "github.com/unidoc/unipdf/v4/extractor" ) opts := &extractor.Options{ SkipMissingFonts: true, // Skip text with missing fonts } ex, err := extractor.NewWithOptions(page, opts) ``` -------------------------------- ### Access PDF pages safely Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/errors.md Validate page retrieval and content stream access to skip corrupted or empty pages during processing. ```go import ( "github.com/unidoc/unipdf/v4/model" ) reader, err := model.NewReader(file) if err != nil { // PDF is invalid return err } pageCount := reader.GetPageCount() for i := 1; i <= pageCount; i++ { page, err := reader.GetPage(i) if err != nil { // Page is invalid, skip it continue } content, err := page.GetAllContentStreams() if err != nil { // No content on this page continue } // Process page } ``` -------------------------------- ### Table Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/creator.md Renders structured data in rows and columns. ```APIDOC ## Table ### Methods - `NewTable(rows, cols int) *Table`: Create table. - `SetCell(row, col int, cell *TableCell)`: Set cell content. - `SetColumnWidth(col int, width float64)`: Set column width. - `SetBorders(borders TableBorders)`: Configure borders. - `SetRowHeight(row int, height float64)`: Set row height. ``` -------------------------------- ### Construct Content Stream Operations Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/contentstream.md Programmatically adds PDF operators and their associated parameters to a ContentStreamOperations object. ```go ops := &contentstream.ContentStreamOperations{} ops.AddOperationWithParams("BT") ops.AddOperationWithParams("Tf", core.MakeName("F1"), core.MakeFloat(12)) ops.AddOperationWithParams("Td", core.MakeFloat(100), core.MakeFloat(700)) ops.AddOperationWithParams("Tj", core.MakeString("Hello")) ops.AddOperationWithParams("ET") ``` -------------------------------- ### Define PdfPageResources structure Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/model.md Manages all resources referenced by a page. ```go type PdfPageResources struct { // References to fonts, images, graphics state, etc. } ``` -------------------------------- ### Define ContentStreamOperations struct Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/contentstream.md Represents a collection of parsed PDF content stream commands. ```go type ContentStreamOperations struct { // Sequence of content stream operations } ``` -------------------------------- ### Logging PDF Incompatibility with Debug Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Use Debug level to log PDF incompatibilities that do not stop the program flow. ```go if len(*name) > 127 { common.Log.Debug("INCOMPATIBLE: Name too long (%s)", *name) } ``` -------------------------------- ### Validate font files Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/errors.md Check for errors when loading a font from a TTF file. ```go import ( "github.com/unidoc/unipdf/v4/model" ) font, err := model.NewPdfFontFromTTFFile("font.ttf") if err != nil { // Font file is invalid } ``` -------------------------------- ### Define AppearanceStyle structure Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/annotator.md Defines the visual styling properties for form fields. ```go type AppearanceStyle struct { FillColor Color BorderColor Color TextColor Color Font *PdfFont FontSize float64 BorderWidth float64 } ``` -------------------------------- ### Referencing PDF standard sections in code comments Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Include references to specific sections and page numbers of the PDF standard (e.g., PDF32000_2008) in code comments for clarity and traceability. ```go // PdfFontDescriptor specifies metrics and other attributes of a font and // can refer to a FontFile for embedded fonts. // 9.8 Font Descriptors (page 281) type PdfFontDescriptor struct { ... } ``` -------------------------------- ### Define PdfObjectDictionary structure Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/core.md Represents a PDF dictionary, which acts as the primary key-value container. ```go type PdfObjectDictionary struct { // PDF dictionary (name->object map) } ``` -------------------------------- ### Avoid blank lines at the bottom of Go blocks Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Do not include trailing blank lines within function blocks. Ensure code is tightly packed. ```go func negative(x float64) { return -x } ``` ```go func redundant() { if 3 < 4 { fmt.Printf("Great\n") } } ``` -------------------------------- ### NewConsoleLogger Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/common.md Creates a new logger instance that writes log messages to standard output. ```APIDOC ## NewConsoleLogger ### Description Creates a new logger that writes to standard output. ### Signature `func NewConsoleLogger(logLevel LogLevel) *ConsoleLogger` ### Parameters - **logLevel** (LogLevel) - Required - Minimum log level to output ### Returns - `*ConsoleLogger` - A new console logger ### Example ```go logger := common.NewConsoleLogger(common.LogLevelDebug) ``` ``` -------------------------------- ### Handle Duplicate Field Name Errors Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/errors.md Check for existing field name conflicts when creating new text fields. ```go import ( "github.com/unidoc/unipdf/v4/annotator" ) field, err := annotator.NewTextField(page, "fieldname", rect, opts) if err != nil && strings.Contains(err.Error(), "already exists") { // Field name is already used } ``` -------------------------------- ### Default float64 value with conditional modification Source: https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide Shows setting a default float64 value and conditionally modifying it based on a condition. The type is inferred. ```go tx := 2.0 // Default offset. if condition { tx += 1.0 } ``` -------------------------------- ### Core Helper Functions Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/types.md Functions for creating basic PDF object types. ```APIDOC ### Core Helper Functions - `MakeName(str string) PdfObjectName`: Create name object - `MakeString(str string) PdfObjectString`: Create string object - `MakeInteger(val int64) PdfObjectInteger`: Create integer object - `MakeFloat(val float64) PdfObjectFloat`: Create float object - `MakeBool(val bool) PdfObjectBool`: Create boolean object - `NewPdfObjectArray() *PdfObjectArray`: Create empty array - `NewPdfObjectDictionary() *PdfObjectDictionary`: Create empty dictionary ``` -------------------------------- ### New Source: https://github.com/unidoc/unipdf/blob/master/_autodocs/api-reference/extractor.md Creates a new extractor instance for a specified PDF page. ```APIDOC ## func New(page *model.PdfPage) (*Extractor, error) ### Description Creates a new extractor for the specified page. ### Parameters - **page** (*model.PdfPage) - Required - Page to extract from ### Returns - (*Extractor, error) - Extractor instance, or error ### Example ```go reader, _ := model.NewReader(file) page, _ := reader.GetPage(1) ex, _ := extractor.New(page) text, _ := ex.ExtractText() ``` ```