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] device.Render does not handle transparency #545

Closed
dillonkh opened this issue Feb 2, 2024 · 3 comments
Closed

[BUG] device.Render does not handle transparency #545

dillonkh opened this issue Feb 2, 2024 · 3 comments

Comments

@dillonkh
Copy link

dillonkh commented Feb 2, 2024

Description

Using device.Render to convert a page of a pdf to an image does so without transparency.

Expected Behavior

When the input PDF has transparency, the image rendered should have the same transparency.

Actual Behavior

Running the following PDF (or any PDF with transparency) through the device.Render gives me an image that does not respect the transparency of the original PDF.

Attachments

Here is my code for an example:

func pdfToImage(file io.ReadSeeker) error {
	// create a new reader
	pdfReader, err := pdf.NewPdfReader(file)
	if err != nil {
		return err
	}

	// get total number of pages
	numPages, err := pdfReader.GetNumPages()
	if err != nil {
		return err
	}

	// for each page
	for i := 1; i <= numPages; i++ {
		// get specific page by number
		page, err := pdfReader.GetPage(i)
		if err != nil {
			return err
		}

		// create device to render page onto
		device := render.NewImageDevice()

		// render image to path
		err = device.RenderToPath(page, "some/path.png")
		if err != nil {
			return err
		}
	}

	return nil
}

Original PDF:
transparent_watermark.pdf

Output image:
unidoc_page_to_img

Copy link

github-actions bot commented Feb 2, 2024

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/

@anovik
Copy link

anovik commented Apr 15, 2024

@dillonkh Hello, we have fixed this transparency issue and it will be included in the next release of UniPDF.

We will notify you when the next release will be available.

Thanks for reporting the issue.

@anovik
Copy link

anovik commented Apr 17, 2024

@dillonkh The UniPDF version 3.57 https://github.com/unidoc/unipdf/releases/tag/v3.57.0 is available and it fixes your issue.

Closing this ticket, feel free to re-open it or open a new one in case of any problems.

@anovik anovik closed this as completed Apr 17, 2024
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

2 participants