-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix font handling #5
Comments
Your snippet is almost correct, just pass The python implementation uses C dependencies to handle fonts. This module uses a pure Go implementation which uses an on-disk cache to store font information. We have chosen to expose the path to the font cache. I'm working towards enabling go-text as a replacement for the text engine, so that the |
I don't have the fontmapCache file present so I can't get this example to work currently.
panic: runtime error: invalid memory address or nil pointer dereference goroutine 1 [running]: |
See the file pdf/draw_test.go and the snippet : // this command has to run once
fmt.Println("Scanning fonts...")
_, err := fc.ScanAndCache(fontmapCache)
if err != nil {
log.Fatal(err)
}
fs, err := fc.LoadFontsetFile(fontmapCache)
if err != nil {
log.Fatal(err)
}
fontconfig = text.NewFontConfigurationPango(fcfonts.NewFontMap(fc.Standard.Copy(), fs)) |
Ye this font stuff is just really not working for me. Perhaps I just wait for the replacement of these parts ;p |
The error message is just a warning, it shouldn't fatal. |
Full example
|
Thank you for the full example.There is something strange though : only one fatal log should happen (since |
That was with empty html string, this link has a sample page in it.
|
Could you add the exact Go sample you use ? It still don't get why the program does not exit at the first log.Fatal. |
package main
import (
"fmt"
"os"
goweasyprint "github.com/benoitkugler/go-weasyprint"
fc "github.com/benoitkugler/textprocessing/fontconfig"
"github.com/benoitkugler/textprocessing/pango/fcfonts"
"github.com/benoitkugler/webrender/text"
"github.com/benoitkugler/webrender/utils"
)
func main() {
html := `<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>My Website</title>
</head>
<body>
<main>
<h1>Welcome to My Website</h1>
</main>
</body>
</html>
`
var fontconfig text.FontConfiguration
const fontmapCache = "pdf/test/cache.fc"
fmt.Println("Scanning fonts...")
_, err := fc.ScanAndCache(fontmapCache)
if err != nil {
fmt.Println(err.Error())
}
fs, err := fc.LoadFontsetFile(fontmapCache)
if err != nil {
fmt.Println(err.Error())
}
fontconfig = text.NewFontConfigurationPango(fcfonts.NewFontMap(fc.Standard.Copy(), fs))
err = goweasyprint.HtmlToPdf(os.Stdout, utils.InputString(html), fontconfig)
if err != nil {
fmt.Println(err.Error())
}
} |
The issue is here : _, err := fc.ScanAndCache(fontmapCache)
if err != nil {
fmt.Println(err.Error())
} I think you don't have the proper directories to match the font cache file defined as Could you adjust this constant to something like |
|
Alrighty it wrote my file, but didn't process the inline css inside the string like wkhtml does. // weasyprint
var fontconfig text.FontConfiguration
const fontmapCache = "cache.fc"
fmt.Println("Scanning fonts...")
_, err = fc.ScanAndCache(fontmapCache)
if err != nil {
return err
}
fs, err := fc.LoadFontsetFile(fontmapCache)
if err != nil {
return err
}
fontconfig = text.NewFontConfigurationPango(fcfonts.NewFontMap(fc.Standard.Copy(), fs))
file, err := os.Create(filename)
if err != nil {
return err
}
err = goweasyprint.HtmlToPdf(file, utils.InputString(buf.String()), fontconfig)
if err != nil {
return err
}
// wkhtml
pdfg, err := wkhtmltopdf.NewPDFGenerator()
if err != nil {
log.Fatal(err)
}
pdfg.AddPage(wkhtmltopdf.NewPageReader(strings.NewReader(buf.String())))
err = pdfg.Create()
if err != nil {
log.Fatal(err)
}
err = pdfg.WriteFile(filename)
if err != nil {
log.Fatal(err)
} |
Can you post the exact html string you use ? I didn't grasp which CSS you are refering to. |
|
Thank you. |
PDF result: Wkhtml from same string generates correct coloring on each cell, and content. it just doesn't load properly for some reason. |
I never used to have to deal with fonts in python, so not sure why I'm being forced to define all this stuff I don't want to deal with here.
fs, err := fc.LoadFontsetFile(fontmapCache)
fontconfig := text.NewFontConfigurationPango(fcfonts.NewFontMap(fc.Standard.Copy(), fs))
All I want is a simple html to pdf here from string to file.
err := pdf.HtmlToPdf(os.Stdout, utils.InputString(html), fs)
The text was updated successfully, but these errors were encountered: