Skip to content
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

[BUG]pdf to png font render error #486

Closed
YuiFn opened this issue Mar 28, 2022 · 6 comments
Closed

[BUG]pdf to png font render error #486

YuiFn opened this issue Mar 28, 2022 · 6 comments

Comments

@YuiFn
Copy link

YuiFn commented Mar 28, 2022

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.

@github-actions
Copy link

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/

@zacharysyoung
Copy link

zacharysyoung commented Jun 7, 2022

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

@0x-1
Copy link

0x-1 commented Jul 3, 2023

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

@sampila
Copy link
Collaborator

sampila commented Nov 11, 2023

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

@zacharysyoung
Copy link

zacharysyoung commented Nov 13, 2023

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

Cheers!

@YuiFn
Copy link
Author

YuiFn commented Nov 16, 2023

@sampila thank you. this work

@YuiFn YuiFn closed this as completed Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants