Skip to content

Latest commit

 

History

History
 
 

README.md

Orcgen

Orcgen is a Go package that enables an easy-to-use conversion of web pages and HTML content to various file formats like PDF, PNG, and JPEG. The underlying implementation uses the Rod library for the page conversion.

Functionalities and packages

Orcgen provides the following functionalities:

  • Conversion of web pages and HTML content to a static file (PNG, PDF...).

    • This can be done simply using the Generate function, but if you need prior configuration, you can access all the webdriver functionalities.
    • You can also use the other functions at orcgen.go, as specified in the examples page.

Package folder

  • FileInfo: A struct to standardize the returns and file saves. There's a Output function that writes the content to a output file.

  • Handlers: The implementations of the page file save functionality (PDF / Screenshots).

  • Webdriver: Simple wrapper over rod library.

Installation

To use Orcgen, you can install it via Go modules:

    go get github.com/luabagg/orcgen/v2

Then you can import it in your Go code:

    import "github.com/luabagg/orcgen/v2"

Usage Example

import "github.com/luabagg/orcgen/v2"

// Convert a URL to a screenshot
err := orcgen.GenerateURL(
    "https://www.github.com",
    orcgen.Screenshot(orcgen.ScreenshotConfig{
        Format: "webp",
    }).FullPage(true),
    "github.webp",
)

// Convert HTML bytes to a PDF
htmlBytes := []byte("<html><body>Hello World</body></html>")
err = orcgen.GenerateHTML(
    htmlBytes,
    orcgen.PDF(orcgen.PDFConfig{
        Landscape:         true,
        PrintBackground:   true,
        PreferCSSPageSize: true,
    }),
    "output.pdf",
)

// Advanced: Use ConvertHTML/ConvertURL for more control
fileInfo, err := orcgen.ConvertURL(
    orcgen.PDF(orcgen.PDFConfig{Landscape: true}),
    "https://example.com",
)
if err == nil {
    fileInfo.Output("custom.pdf")
}

The package comes with examples that demonstrate the usage of the various functions and features provided by Orcgen. It's the way-to-go if you're trying to use this package for the first time.

You can see more in examples_test.go page.

Contributors

This project is an open-source project, and contributions from other developers are welcome. If you encounter any issues or have suggestions for improvement, please submit them on the project's GitHub page.