unipdf
unipdf copied to clipboard
[BUG]pdf to png font render error
Description
Font rendering error when rendering pdf with imageDevice
target := "taiwen.pdf"
now := time.Now()
reader, f, err := model.NewPdfReaderFromFile(target, nil)
if err != nil {
log.Fatalf("Could not create reader: %v\n", err)
}
defer f.Close()
numPages, err := reader.GetNumPages()
if err != nil {
log.Fatalf("Could not retrieve number of pages: %v\n", err)
}
basename := strings.TrimSuffix(filepath.Base(target), filepath.Ext(target))
device := render.NewImageDevice()
device.OutputWidth = 800
for i := 1; i <= numPages; i++ {
page, err := reader.GetPage(i)
if err != nil {
log.Fatalf("Could not retrieve page: %v\n", err)
}
outFilename := fmt.Sprintf("%s_%d.png", basename, i)
if err = device.RenderToPath(page, outFilename); err != nil {
log.Fatalf("Image rendering error: %v\n", err)
}
}
Expected Behavior
all rendering ok
Actual Behavior
use pdf_image_render, see output
Attachments
Include a
AL951611050249.pdf
taiwen.pdf
self-contained reproducible code snippet and PDF file that demonstrates the issue.
Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. If you need to get this done, consider buying a license which also enables you to use it in your commercial products. More information can be found on https://unidoc.io/
I'm seeing this too, but even worse in some cases.
I converted the following PDF to PNGs using the pdf_image_render.go example, and UniPDF v3.34.0:
go run pdf_image_render.go images ~/Downloads/Awesome_Form/ERAP_2_Template.pdf
go: downloading github.com/unidoc/unipdf/v3 v3.34.0
go: downloading github.com/unidoc/pkcs7 v0.1.1-0.20220329190817-dd59b9eba14c
go: downloading golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
go: downloading golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
Here's the PDF: ERAP_2_Template.pdf
Here's the image for page 1 where some fonts were missed (I'd say... ?):
Here's the image for page 14 with no issues:
same. seems to be a problem with the render. my blind guess would be fonts.
Hi @YuiFn, @zacharysyoung and @0x-1
We release new UniPDF version to improve font rendering https://github.com/unidoc/unipdf/releases/tag/v3.52.0,
You can try and would be good if you can confirm if the issue is resolved by latest version of UniPDF.
Thanks
@sampila, yes, 3.52.0 fixed it for me, thank you.
Cheers!
@sampila thank you. this work