unidoc / unipdf

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

[BUG] Images are rendered with low quality #469

Closed zgordan-vv closed 2 years ago

zgordan-vv commented 2 years ago

Description

I am trying to render an image from the PDF document.

Expected Behavior

The image should look like the PDF document.

Actual Behavior

The image looks like a very pixelized/blurred version of the PDF document. Steps to reproduce the behavior:

  1. Copy the attached PDF file in the same directory with the attached code
  2. Run the code
  3. See error

Attachments

chart.pdf chart.png

package main

import (
    "os"
    "github.com/unidoc/unipdf/v3/model"
    "github.com/unidoc/unipdf/v3/render"
)

func main() {
    f, err := os.Open("chart.pdf")
    if err != nil {
        panic(err)
    }
    defer f.Close()

    reader, err := model.NewPdfReaderLazy(f)
    if err != nil {
        panic(err)
    }
    chartPage, err := reader.GetPage(1)
    if err != nil {
        panic(err)
    }

    if err = render.NewImageDevice().RenderToPath(chartPage, "chart.png"); err != nil {
        panic(err)
    }
}
gunnsth commented 2 years ago

Basically just need to set the returned (from render.NewImageDevice()) device.OutputWidth = width to the desired pixel output width.