asciidoctor / asciidoctor-pdf

:page_with_curl: Asciidoctor PDF: A native PDF converter for AsciiDoc based on Asciidoctor and Prawn, written entirely in Ruby.
https://docs.asciidoctor.org/pdf-converter/latest/
MIT License
1.14k stars 501 forks source link

could not embed image when file path has chinese chars #2401

Closed iseri27 closed 1 year ago

iseri27 commented 1 year ago

my /home/user/测试/test.adoc content is:

image:./1.jpg[picture]

and there is a picture 1.jpg under /home/user/测试

when i try to generate pdf doc using asciidoctor-pdf, it tells me that "could not embed image":

asciidoctor-pdf -a allow-uri-read \
                -a scripts=cjk \
                -a pdf-theme=./theme/theme.yml \
                -a pdf-fontsdir=./fonts \
                -r asciidoctor-mathematical "./test.adoc"

asciidoctor: WARNING: could not embed image: /home/user/​测​试/1.jpg; No such file or directory @ rb_sysopen - /home/user/​测​试/1.jpg

but if i rename the dir name to /home/user/testdir, it can generate pdf correctly.

os: nixos output of asciidoctor-pdf -v:

Asciidoctor PDF 2.3.2 using Asciidoctor 2.0.18 [https://asciidoctor.org]
Runtime Environment (ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5) [x86_64-linux]) (lc:UTF-8 fs:UTF-8 in:UTF-8 ex:UTF-8)

theme file: theme.yml

mojavelinux commented 1 year ago

This is a system encoding problem. If Ruby can resolve the file path, then Asciidoctor PDF can read the file. If Ruby cannot read the file path, then there's nothing Asciidoctor PDF can do about it.

I have tested this exact same scenario on my Fedora machine and it works fine. I've even added a test to verify that a properly configured Ruby (and system) will work as expected. See https://github.com/asciidoctor/asciidoctor-pdf/blob/0b80ea6bff5cac6ec61594ee2f647b481d82de61/spec/image_spec.rb#L139-L145

I kindly ask that in the future you raise questions about usage in the project chat at https://chat.asciidoctor.org (as the issue template requested). The issue tracker is for reporting issues that have already been triaged. That helps us to better maintain the project.