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

diagnostic output interferes with stdout redirection #464

Open
drew-parsons opened this issue Jan 20, 2020 · 4 comments
Open

diagnostic output interferes with stdout redirection #464

drew-parsons opened this issue Jan 20, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@drew-parsons
Copy link

xhtml2pdf allows for stdout redirection, so xhtml2pdf - - receives input from stdout and sends output to stdout rather than to file.

But it also generates diagnostic messages during processing so these also get sent to stdout, putting meaningless data into the pdf data stream.

e.g.

$ echo "test" | xhtml2pdf  - - >/tmp/test.pdf 2>/dev/null ; head -2 /tmp/test.pdf 
Converting - to -...
%PDF-1.3

So the generated pdf is prefixed with a line "Converting - to -...".
This line should probably be sent to stderr instead of stdout.

This bug was reported at Debian Bug#592500, https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=592500

@drew-parsons drew-parsons changed the title diagnostic output inteferes with stdout redirection diagnostic output interferes with stdout redirection Jan 20, 2020
@luisza
Copy link
Collaborator

luisza commented Jan 20, 2020

Could you test using quiet mode ?

echo "test" | xhtml2pdf -q - - >/tmp/test.pdf 2>/dev/null ; head -2 /tmp/test.pdf

@drew-parsons
Copy link
Author

-q eliminates all output to stdout, so the generated file (/tmp/test.pdf) is empty

$ ls -l /tmp/test.pdf
-rw-r--r-- 1 user user 0 Jan 21 08:53 /tmp/test.pdf

@drew-parsons
Copy link
Author

Hmm, perversely however, it's now also generating an empty file even without -q. Not sure what's happened overnight (apart from a reboot). Will report back when I can reproduce the original problem again.

@drew-parsons
Copy link
Author

I see what happened now. xhtml2pdf was the python2 version, but python-xhtml2pdf has just been removed from Debian, leaving only the python3-xhtml2pdf package with xhtml2pdf3 as the executable file.

The behaviour between the python3 and python3 versions seems quite different.
echo "test" | xhtml2pdf3 - - >/tmp/test.pdf 2>/dev/null ; head -2 /tmp/test.pdf does not create a pdf file at all in /tmp/test.pdf, the file simply contains the plain text "Converting - to -..." with no pdf data.

But the -q option for xhtml2pdf3 still generates an empty file. This must be because xhtml2pdf3 - - is no longer well-defined: without redirecting stderr to /dev/null, I get

$ echo "test" | xhtml2pdf3 - -
Converting - to -...
Traceback (most recent call last):
  File "/usr/bin/xhtml2pdf3", line 11, in <module>
    load_entry_point('xhtml2pdf==0.2.2', 'console_scripts', 'xhtml2pdf')()
  File "/usr/lib/python3/dist-packages/xhtml2pdf/pisa.py", line 167, in command
    execute()
  File "/usr/lib/python3/dist-packages/xhtml2pdf/pisa.py", line 392, in execute
    xml_output=xml_output
  File "/usr/lib/python3/dist-packages/xhtml2pdf/document.py", line 183, in pisaDocument
    context.dest.write(data)  # TODO: context.dest is a tempfile as well...
TypeError: write() argument must be str, not bytes

@luisza luisza self-assigned this Sep 24, 2020
@timobrembeck timobrembeck added the bug Something isn't working label Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants