Closed ErikXu closed 8 months ago
Internally, the image processing invokes ghostscript to interpret PostScript and PDF (that is the gs
call).
So you probably need to add that to your container.
Cool, I really appreciate your advice. After adding ghostscript, The pdf can be read now. The final Dockerfile is
FROM alpine:3.19
RUN apk add build-base
RUN apk add ghostscript
RUN apk add timg
But the resolution seems unacceptable, it might due to the quality of pdf, right? Or any command parameter to improve?
timg -W --auto-crop /workspace/test.pdf
Make sure you run timg in a terminal that can show high-resolution pictures (Maybe you need to tell it with -pi
or -pk
).
Having said that, the rendering of PostScript and PDF is still not optimal as the graphicsmagick library I am using for that only requests a limited resolution when converting the file. I plan to see if I can get better results by directly using the ghostscript API, but haven't had time for that yet.
Cool. Thanks!
I started adding a dedicated library to render PDFs (poppler
)
You can compile it yourself if you have libpoppler-glib-dev
installed and compile timg with -DWITH_POPPLER=On
It allows to upscale with -U
and -W
and provides a higher resolution as the standard rendering.
(still work in progress, e.g. --auto-crop
won't work yet).
The new release now contains the improved PDF rendering https://github.com/hzeller/timg/releases/tag/v1.6.0
Really appreciate for your effort, but it seems not so much improvement in my side.
Dockerfile (base image changed and version v1.6.0 was installed):
FROM alpine:edge
RUN apk add build-base
RUN apk add ghostscript
RUN apk add timg
Result:
I guess still the problem of the quality of pdf.
Is it possible to provide a good-looking pdf for testing?
Thanks!
what is the terminal you're using ? Is it one of the ones that can output high-resolution images (such as Konsole, wezterm, kitty...) ?
It looks like the output of -pq
('quarter' blocks, see timg --help
for explanations). That never can be good quality as the image is emitted as textblocks.
Can you run timg
with --title="%wx%h %D" --verbose
when looking at your example PDF so that we can see the original resolution and the image decoder it uses in the title (top of page), and other relevant information in the bottom of the output ?
I use MobaXterm
as the terminal.
And the result of adding --title="%wx%h %D" --verbose
is
docker run --rm -it \
> -v ${PWD}/:/workspace/ \
> timg:latest \
> timg --title="%wx%h %D" --verbose -W --auto-crop /workspace/Resume.pdf
414x651 pdf
-------- pdf content --------
Terminal cells: 133x38 cell-pixels: -1x-2
Note: Terminal does not return ws_xpixel and ws_ypixel in TIOCGWINSZ ioctl or "\033[16t" query.
->Aspect ratio might be off.
->File a feature request with the terminal emulator program you use
Active Geometry: 131x36
Effective pixelation: Using quarter block.
Background color for transparency 'auto'; effective RGB #000000
1 file (1 successful); 275.6 KiB written (4312.7 KiB/s) 2 frames
Environment variables
TIMG_PIXELATION (not set)
TIMG_DEFAULT_TITLE (not set)
TIMG_ALLOW_FRAME_SKIP (not set)
TIMG_USE_UPPER_BLOCK (not set)
TIMG_FONT_WIDTH_CORRECT (not set)
It only can do quarter block output there (see effective pixelation). Also looks like this terminal has other limitations such as not providing terminal pixel size information.
You can try giving -pi
or -ps
to the timg invocation to see if the terminal can do higher resolution.
I recommend using a modern terminal such as wezterm.
I am trying to read a pdf in alpine container. but I got a error message below:
Dockerfile:
Build command:
Read pdf command:
Whole output: