Documentation
¶
Overview ¶
Package orcgen generates files from HTML - any static webpage can be informed, or even an HTML file. The file will be generated according the choosen extension.
Index ¶
Examples ¶
Constants ¶
const ( // PDF const. PDF = internal.PDF // PNG const. PNG = internal.PNG // JPEG const. JPEG = internal.JPEG )
Valid extension types constants.
Variables ¶
This section is empty.
Functions ¶
func ConvertHTML ¶
ConvertHTML converts the informed bytes to the ext format, and saves the file.
ext is the extension to be converted to (use the defined constants above). html is the html byte array (if it's a filepath, use os.ReadFile(filepath)). output is a filepath containing the extension.
The connection is automatically closed.
Example ¶
ExampleConvertHTML gives examples using the ConvertHTML function from
package main import ( "fmt" "os" "path/filepath" "runtime" "github.com/lazzytchik/orcgen" ) func main() { filename := "html.pdf" err := orcgen.ConvertHTML(orcgen.PDF, getHTML(), getName(filename)) if err == nil { fmt.Printf("%s generated succesfully\n", filename) } } func getHTML() []byte { file := filepath.Join(getBasepath(), "testdata/test.html") html, _ := os.ReadFile(file) return html } func getName(name string) string { return filepath.Join(getBasepath(), "testdata", name) } func getBasepath() string { _, b, _, _ := runtime.Caller(0) return filepath.Dir(b) }
Output: html.pdf generated succesfully
func ConvertWebpage ¶
ConvertWebpage converts the url to the ext format, and saves the file.
ext is the extension to be converted to (use the defined constants above). url is the url to convert. output is a filepath containing the extension.
The connection is automatically closed.
Example ¶
ExampleConvertWebpage gives examples using the ConvertWebpage function from
package main import ( "fmt" "path/filepath" "runtime" "github.com/lazzytchik/orcgen" ) func main() { filename := "github.pdf" err := orcgen.ConvertWebpage(orcgen.PDF, "https://www.github.com", getName(filename)) if err == nil { fmt.Printf("%s generated succesfully\n", filename) } } func getName(name string) string { return filepath.Join(getBasepath(), "testdata", name) } func getBasepath() string { _, b, _, _ := runtime.Caller(0) return filepath.Dir(b) }
Output: github.pdf generated succesfully
func New ¶
New starts a new Director - the Director contains the available methods for file conversion.
ext is the extension to be converted to (use the defined constants above).
Connect and Close are used for the Browser connection control. ConvertWebpage and ConvertHTML are used for page conversion.
There are a set of setters for specific config.
Example ¶
ExampleNew gives examples using the New function from orcgen.
package main import ( "fmt" "os" "path/filepath" "runtime" "time" "github.com/lazzytchik/orcgen" ) func main() { // starts the connection. gen := orcgen.New(orcgen.PDF) defer gen.Close() /* using for HTML conversion */ // this generates a pdf file with the HTML content. f, _ := gen.ConvertHTML(getHTML()) filename := "html.pdf" if err := f.Output(getName(filename)); err == nil { fmt.Printf("%s generated succesfully\n", filename) } // this generates a png file with the HTML content. // notice the SetFullPage use here. f, _ = gen.SetExt(orcgen.PNG). SetFullPage(true). ConvertHTML(getHTML()) filename = "html.png" if err := f.Output(getName(filename)); err == nil { fmt.Printf("%s generated succesfully\n", filename) } /* using for URL conversion */ // this generates a pdf file from www.google.com. f, _ = gen.SetExt(orcgen.PDF). ConvertWebpage("https://www.google.com") filename = "google.pdf" if err := f.Output(getName(filename)); err == nil { fmt.Printf("%s generated succesfully\n", filename) } // this generates a jpeg file from www.twitter.com. // full config example. f, _ = gen.SetExt(orcgen.JPEG). SetFullPage(true). SetLoadTimeout(5 * time.Second). SetPageIdleTime(3 * time.Second). ConvertWebpage("https://www.twitter.com") filename = "twitter.jpeg" if err := f.Output(getName(filename)); err == nil { fmt.Printf("%s generated succesfully\n", filename) } } func getHTML() []byte { file := filepath.Join(getBasepath(), "testdata/test.html") html, _ := os.ReadFile(file) return html } func getName(name string) string { return filepath.Join(getBasepath(), "testdata", name) } func getBasepath() string { _, b, _, _ := runtime.Caller(0) return filepath.Dir(b) }
Output: html.pdf generated succesfully html.png generated succesfully google.pdf generated succesfully twitter.jpeg generated succesfully
func NewCustom ¶ added in v1.0.2
New starts a new Director - the Director contains the available methods for file conversion.
ext is the extension to be converted to (use the defined constants above).
Connect and Close are used for the Browser connection control. ConvertWebpage and ConvertHTML are used for page conversion.
There are a set of setters for specific config.
Types ¶
This section is empty.
Directories
¶
Path | Synopsis |
---|---|
Package internal contains the builder implementation.
|
Package internal contains the builder implementation. |
generator
Package generator contains builders used for page conversion (example HTML to PDF).
|
Package generator contains builders used for page conversion (example HTML to PDF). |
generator/jpeg
Package jpeg implements the builder for JPEG files.
|
Package jpeg implements the builder for JPEG files. |
generator/pdf
Package pdf implements the builder for PDF files.
|
Package pdf implements the builder for PDF files. |
generator/png
Package png implements the builder for PNG files.
|
Package png implements the builder for PNG files. |
rod
Package rod contains go-rod implementation.
|
Package rod contains go-rod implementation. |
pkg
|
|
director
Package director provides functionality for generating files from HTML using the Rod package.
|
Package director provides functionality for generating files from HTML using the Rod package. |
fileinfo
Package fileinfo is used for file information control.
|
Package fileinfo is used for file information control. |