Last active
January 6, 2020 22:30
-
-
Save MrSaints/0dcf12ddebebdbdca9353dc1b12160fb to your computer and use it in GitHub Desktop.
A basic HTML to PDF converter in Golang using Qt WebEngine 5.7. For a more production-ready converter, see: http://www.athenapdf.com/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"github.com/therecipe/qt/core" | |
"github.com/therecipe/qt/gui" | |
"github.com/therecipe/qt/webengine" | |
"github.com/therecipe/qt/widgets" | |
"os" | |
"time" | |
) | |
func main() { | |
in := flag.String("uri", "https://www.fyianlai.com/", "a URI to convert to PDF") | |
out := flag.String("out", "output.pdf", "a file path for the generated PDF output") | |
flag.Parse() | |
start := time.Now() | |
app := widgets.NewQApplication(len(os.Args), os.Args) | |
view := webengine.NewQWebEngineView(nil) | |
page := view.Page() | |
view.ConnectLoadStarted(func() { | |
fmt.Printf("loading : %q\n", *in) | |
}) | |
view.ConnectLoadFinished(func(ok bool) { | |
defer fmt.Printf("PDF generated : %q (%s)\n", *out, time.Since(start)) | |
fmt.Printf("load finished : %t\n", ok)q | |
layout := gui.NewQPageLayout2(gui.NewQPageSize2(0), 0, core.NewQMarginsF2(0.0, 0.0, 0.0, 0.0), 0, core.NewQMarginsF2(0.0, 0.0, 0.0, 0.0)) | |
page.PrintToPdf(*out, layout) | |
// app.Exit(0) | |
}) | |
view.Load(core.NewQUrl3(*in, 0)) | |
app.Exec() | |
} |
It does not work well.
Try for this url: https://www.vikashverma.com/resume.html
A much simpler alternative using Puppeteer https://github.com/Courtsite/shuttlepdf (does not require a display server).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it working?
If yes, what is the prerequisites to run it?