pdf

package
v0.0.0-...-6dd5abc Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "pdf [url] [filename]",
	Args:  cobra.ExactArgs(2),
	Short: "Opens a website and create a PDF file.",
	RunE: func(cmd *cobra.Command, args []string) error {
		options := Options{
			Url: args[0],
			Viewport: &Viewport{
				Width:  *width,
				Height: *height,
			},
			Insecure:   *insecure,
			JavaScript: *javascript,
			Wait:       *wait,
		}
		filename := args[1]

		log.Printf("options %v\n", options)
		log.Printf("viewport %v\n", options.Viewport)

		ctx, cancel := chromedp.NewContext(
			context.Background(),
		)
		defer cancel()

		var res []byte

		if err := chromedp.Run(ctx, MakePdf(options, &res)); err != nil {
			log.Fatal(err)
			return err
		}
		if err := os.WriteFile(filename, res, 0o644); err != nil {
			log.Fatal(err)
			return err
		}

		log.Printf("wrote %s as %s\n", options.Url, filename)
		return nil
	},
}

Functions

func MakePdf

func MakePdf(options Options, res *[]byte) chromedp.Tasks

Types

type Options

type Options struct {
	Url        string
	Viewport   *Viewport
	Insecure   bool
	JavaScript bool
	Wait       time.Duration
}

type Viewport

type Viewport struct {
	Width  int
	Height int
}

Jump to

Keyboard shortcuts

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