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

Including multipage pdf via imgconverter fails #6019

Closed
lindhor opened this issue Feb 4, 2019 · 11 comments
Closed

Including multipage pdf via imgconverter fails #6019

lindhor opened this issue Feb 4, 2019 · 11 comments

Comments

@lindhor
Copy link

lindhor commented Feb 4, 2019

Describe the bug
I use sphinx.ext.imgconverter in combination with ImageMagick to include existing PDFs via the .. image:: directive. This works well with single page PDFs but fails if the PDF contain more than one page.

Error:

WARNING: cannot copy image file 'D:\\fmn\\Examples\\RST\\_build\\doctrees\\images\\multipage.png': [Errno 2] No such file or directory: 'D:\\fmn\\Examples\\RST\\_build\\doctrees\\images\\multipage.png'

To Reproduce

  1. Create a RST document with a .. image:: multipage.pdf directive
  2. Save a multipage PDF with the filename multipage.pdf
  3. Run make html

Expected behavior
Expected that all pages would be included in the produced output.
Instead the _build/doctrees/images/ directory contain one png per page multipage-1.png, multipage-2.png etc. but these are not copied to the _build/html/_images/ directory and the generated html page references the file multipage.png rather than each mulipage-1.png, mulipage-2.png etc.

Your project
N/A

Screenshots
N/A

Environment info

  • OS: Win10

  • Python version: 3.7.0

  • Sphinx version: 1.7.9

  • Sphinx extensions:

    'sphinx.ext.todo',
    'sphinx.ext.ifconfig',
    'sphinx.ext.graphviz',
    'sphinx.ext.imgconverter',
    'sphinx.ext.intersphinx',
    'sphinxcontrib.mermaid',
    'sphinxcontrib.jinja',
    'sphinxcontrib.bibtex',
    'sphinxcontrib.needs',
    'sphinxcontrib.visio',
    'sphinxcontrib.exceltable',
    'sphinxcontrib.programoutput',
    'sphinxcontrib.plantuml',
    'sphinx_markdown_tables',
    'hieroglyph',
    'pptshape.directive'

  • Extra tools: ImageMagick 7.0.8-12

Additional context
N/A

@jfbu
Copy link
Contributor

jfbu commented Feb 5, 2019

Thus the images would be located one below the other in output html ?

@lindhor
Copy link
Author

lindhor commented Feb 5, 2019

Yes, I believe that’s the best we could do.

@tk0miya tk0miya added this to the 1.8.5 milestone Feb 5, 2019
@tk0miya
Copy link
Member

tk0miya commented Feb 5, 2019

-1 for putting all images in PDF. But +1 to avoid crash. It would not work fine on figure directive.

@lindhor
Copy link
Author

lindhor commented Feb 5, 2019

@tk0miya What are the issues you foresee with the figure directive? If it’s related to caption it might be possible to just repeat the caption, possibly with a sequence number added (x of y).

@tk0miya
Copy link
Member

tk0miya commented Feb 6, 2019

Yes, I'm worry about caption. And I feel strange to modify structure of document. Is it same as other formats? imgconverter is called only if output format does not support the image.
For example, LaTeX support PDF format directly. So the extension does not called for the format.

@lindhor
Copy link
Author

lindhor commented Feb 11, 2019

I finally got time to check how building a PDF via LaTeX handles multipage PDF:s included as images.

  • If no image converter is used it includes the first page (only) from the multipage PDF in the built PDF with its content visible.
  • If I configure sphinx to use ImageMagick as image_converter I get similar results when building pdf as when building html. It seems like the image_converter is called. ImageMagick creates one png for each page named pdfname-pagenumber.png (xxx-0.png etc.) in the doctrees/images/ directory. In the built PDF I only get a placeholder for a missing picture with the text pdfname.png inside. In the build/latex directory no png:s are copied. Looking in the generated .tex-file I see that it references the pdfname.png (i.e. not any of the pdfname-pagenumber.png files).

@tk0miya
Copy link
Member

tk0miya commented Feb 13, 2019

Thank you for investigation. I determined to pick up the first page of the PDF by imgconverter. #6071 would fix the error.

@lindhor
Copy link
Author

lindhor commented Feb 13, 2019

Thanks! Looks good as a first step, it should fix the error! I would like to ask you to continue consider implementing support for including all pages of included PDFs as an option. In our case it would be very useful and save a lot of manual labor. If implemented as an configurable option (preferably in the rst on the directive, rather than in conf.py) I think that the caption and any options could be repeated for each page/picture included.

tk0miya added a commit that referenced this issue Feb 16, 2019
Fix #6019: imgconverter: Including multipage PDF fails
@tk0miya
Copy link
Member

tk0miya commented Feb 16, 2019

Merged #6071 now.

I'm not interested in your idea. The semantics of image and figure directive of reStructuredText is inserting a single image to the document. So I'd not like to enhance it from Sphinx side.
But you can enhance Sphinx by your extension. How about to create custom extension to do that?

@lindhor
Copy link
Author

lindhor commented Feb 16, 2019

Ok, in that case we will look into a custom solution. Thanks for fixing the bug.

@tk0miya
Copy link
Member

tk0miya commented Feb 17, 2019

:-)

@tk0miya tk0miya closed this as completed Feb 17, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants