unipdf icon indicating copy to clipboard operation
unipdf copied to clipboard

[BUG]pdf to png font render error

Open YuiFn opened this issue 2 years ago • 2 comments

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 AL951611050249_1 taiwen.pdf taiwen_1 self-contained reproducible code snippet and PDF file that demonstrates the issue.

YuiFn avatar Mar 28 '22 01:03 YuiFn

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/

github-actions[bot] avatar Mar 28 '22 01:03 github-actions[bot]

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... ?): ERAP_2_Template_1

Here's the image for page 14 with no issues: ERAP_2_Template_14

zacharysyoung avatar Jun 07 '22 17:06 zacharysyoung

same. seems to be a problem with the render. my blind guess would be fonts. image

0x-1 avatar Jul 03 '23 13:07 0x-1

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 avatar Nov 11 '23 18:11 sampila

@sampila, yes, 3.52.0 fixed it for me, thank you.

Cheers!

zacharysyoung avatar Nov 13 '23 02:11 zacharysyoung

@sampila thank you. this work

YuiFn avatar Nov 16 '23 04:11 YuiFn