unidoc / unipdf

Golang PDF library for creating and processing PDF files (pure go)
https://unidoc.io
Other
2.46k stars 250 forks source link

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

Closed dillonkh closed 2 months ago

dillonkh commented 5 months ago

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

github-actions[bot] commented 5 months ago

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 commented 2 months ago

@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 commented 2 months ago

@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.