Generate High-Quality PDF Reports from HTML with UniHTML in Go In today’s highly data-driven society the importance of effective communication is paramount and reports play an integral role in communicating complicated information. Be it marketing information such as sales figures or updates on projects, well-written reports are crucial for clear communications.

The creation of these reports was traditionally the tedious task of manually moving information from websites to documents. It was not only tedious but also susceptible to mistakes. The result was often reports that were visually unappealing as well as inaccurate.

Enter UniHTML, the revolutionary technology that is designed specifically for Go developers. This powerful application for UniPDF converts web-based information into well-qualified PDF documents effortlessly straight from the HTML sources. UniHTML streamlines all the process allowing you to create polished, precise PDF documents in a short time.

In this blog, we will walk you through the benefits of with UniHTML to create PDF reports. We also offer the complete step-by-step instruction. Ideal for experts Go developers as well as newcomers This guide will benefit improve your capabilities in reporting and impress your clients with quality PDF files.

Why UniHTML Stands Out for PDF Report Generation:

  • Unmatched Accuracy: UniHTML meticulously preserves the original formatting and layout of your HTML, ensuring your generated PDFs perfectly mirror the web pages they represent. No more unexpected inconsistencies or formatting issues.
  • Streamlined Development: UniHTML’s intuitive API simplifies integration, allowing you to effortlessly incorporate PDF report generation capabilities into your Go applications. Focus on building your core functionalities without complex setups.
  • Exceptional Scalability: UniHTML effortlessly handles high-volume workloads, making it ideal for even the most demanding projects. Generate large batches of PDF reports with confidence and efficiency.
  • No Headless Chrome Reliance: Unlike many other solutions, UniHTML eliminates the need for a headless Chrome browser, saving you time and resources by avoiding this additional dependency.

Getting Started with UniHTML: A Step-by-Step Guide

Even if you’re new to UniHTML, getting started is straightforward:

1. Prerequisites:

2. Obtain a UniPDF License:

  • Visit the UniDoc website and purchase a UniPDF licence that includes the UniHTML plugin.

3. Pull the UniHTML Docker Image:

Open a terminal window and run the following command:

docker pull unidoccloud/unihtml

4. Start the UniHTML Server:

Run the following command, replacing <your_metered_api_key> with your actual UniDoc metered API key (obtained during license purchase):

docker run -p 8080:8080 -e UNIDOC_METERED_API_KEY=your-api-key-here unidoccloud/unihtml

This will start the UniHTML server on port 8080.

5. Generate a PDF from HTML:

Using the Go Client:

The UniHTML documentation provides a Go client library for programmatic PDF generation. Here’s a basic example:

/*
 * This file is subject to the terms and conditions defined in
 * file 'LICENSE.md', which is part of this source code package.
 */

package main

import (
    "fmt"
    "os"

    "github.com/unidoc/unihtml"
    "github.com/unidoc/unipdf/v3/common/license"
    "github.com/unidoc/unipdf/v3/creator"
)

func init() {
    // Make sure to load your metered License API key prior to using the library.
    // If you need a key, you can sign up and create a free one at https://cloud.unidoc.io
    err := license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))
    if err != nil {
        panic(err)
    }
}

func main() {
    if len(os.Args) != 2 {
        fmt.Println("Err: provided invalid arguments. No UniHTML server path provided")
        os.Exit(1)
    }

    // Establish connection with the UniHTML Server.
    if err := unihtml.Connect(os.Args[1]); err != nil {
        fmt.Printf("Err:  Connect failed: %v\n", err)
        os.Exit(1)
    }

    htmlContent := `
        <!DOCTYPE html>
        <html>
            <head>
                <style>
                    body {
                        background-color: #6E85F7;
                        font-size-adjust: initial;
                    }
                </style>
            </head>
            <body>
                <h1>Oh Hi...</h1>
                <p>It works!</p>

            </body>
        </html>
    `

    // Get new PDF Creator.
    c := creator.New()

    // Convert the HTML content to UniHTML document.
    htmlDocument, err := unihtml.NewDocumentFromString(htmlContent)
    if err != nil {
        fmt.Printf("Err: NewDocument failed: %v\n", err)
        os.Exit(1)
    }

    // Draw the html document file in the context of the creator.
    if err = c.Draw(htmlDocument); err != nil {
        fmt.Printf("Err: Draw failed: %v\n", err)
        os.Exit(1)
    }

    // Write the result file to PDF.
    if err = c.WriteToFile("simple-from-text.pdf"); err != nil {
        fmt.Printf("Err: %v\n", err)
        os.Exit(1)
    }
}

Additional Tips:

  • Explore the comprehensive examples and tutorials in the UniHTML documentation for a deeper understanding of various use cases.
  • Consider using a code editor with syntax highlighting for Go to improve code readability.
  • If you encounter any issues, consult the UniHTML documentation or seek help on the UniDoc community forums.

By leveraging UniHTML, you can streamline the creation of high-quality PDF reports in your Go projects, enhancing the overall quality and professionalism of your deliverables. This blog post offers a comprehensive guide, making it an accessible resource for both beginners and experienced Go developers.

Conclusion:

At long last, UniHTML has made it so you don’t have to lug around generating PDFs that look like they were done by pros from your HTML content. With its accuracy features, scalability, and ease of use - no matter what level of experience you’re at (beginner or advanced) this could be a great asset for Golang developers.

We wish this guide on UniHTML could give you some insight. You now possess the means to start creating beautiful PDFs - let them lighten your task load and amaze your clients as well! This will involve setting up your environment, using the Go client library or web service among other things.

Are you tired yet of making reports manually? If not, then let UniHTML work for you efficiently instead. Get going today and watch how much time it saves on all of your projects written in Go programming language!