Inkscape.org
Beyond the Basics CLI: PDF import combined with actions
  1. #1
    jcwinkler jcwinkler @jcwinkler

    Hi,

    I would like to import a pdf snippet and convert it to a svg file. During this procedure it must be ensured that all strokes are converted to paths. The external poppler library with cairo backend is requried to ensure that mathematical symbols are imported correctly. (Related issue in the TexText extension)

    I know how to do this in two command line calls which convert a file called tmp.pdf into tmp.svg:

    inkscape --pdf-poppler --pdf-page=1 --export-type=svg --export-text-to-path --export-area-drawing --export-filename tmp2.svg tmp.pdf
    inkscape -g --batch-process --actions="EditSelectAll;StrokeToPath;export-filename:tmp.svg;export-do;FileClose" tmp2.svg

    Is there any possibilty to do this in one call?

    Using

    inkscape -g --batch-process --pdf-poppler --pdf-page=1 --actions="EditSelectAll;StrokeToPath;export-text-to-path;export-area-drawing;export-filename:tmp.svg;export-do;FileClose" tmp.pdf

    results in opening a dialog asking for the pdf importer (i.e., --pdf-poppler seemst to be ignored)

    Remark: In the extension I will use the inkex.command module instead of the direct inkscape call.

    Thanks!

  2. #2
    Patrick Storz Patrick Storz @Ede_123

    Unfortunately usage of -g / --with-gui currently will make the PDF import dialog appear.

    I currently don't see a way a around that without changing code.

  3. #3
    Patrick Storz Patrick Storz @Ede_123

    For reference: https://gitlab.com/inkscape/inkscape/-/blob/master/src/extension/internal/pdfinput/pdf-input.cpp#L704

  4. #4
    inklinea inklinea @inklinea⛰️

    You can convert that to a one liner, but the pdf import box will still popup.

    If you are using linux, there is an existing tiny program called pdf2svg which uses Cairo/Poppler to convert pdf to svg. It has an option to input a page number.

    It is very fast and the next line of a bash script could be your Inkscape command 

  5. #5
    jcwinkler jcwinkler @jcwinkler
    *

    @Ede_123 Thank you very much for the clarification. Two questions:

    1. Isn't it a little bit self-contradictory that although the option --pdf-poppler is passed the gui opens and asks the same thing again (i.e. the way how to import the pdf)? Is it worth to develop a patch circumventing this? I could try.
    2. Is there any other way for extension-writers to modify a svg snippet on the Python side such that strokes are converted to paths? (Meanwhile I will use the double inkscape call approach, see here)

    @inklinea I know pdf2svg. We used it in previous releases of our extension. But we want to go away from dependencies on third party programs which need to be installed by extensions users. Thanks anyway!

  6. #6
    Patrick Storz Patrick Storz @Ede_123

    Well certainly this would be a welcome patch. In general there's some divergence between GUI mode and CLI mode, which eventually should be resolved, but currently is usually not straightforward yet due to code design (i.e. it needs special-casing for each parameter, which long-term should not be reuqired - every parameter in the GUI should be settable from CLI and vice-versa).

Inkscape Inkscape.org Inkscape Forum Beyond the Basics CLI: PDF import combined with actions