inkslides icon indicating copy to clipboard operation
inkslides copied to clipboard

PDF generation not working with inkscape 1.0

Open LoryPack opened this issue 4 years ago • 1 comments

Hi,

thank you so much for coding this, it is helpful. I have installed everything as required (on Ubuntu 20.04) and tried running it on the provided example. However, the svg files with single slides were not converted to pdf, so that of course the merging failed. I realized the error is probably due to the fact that I have inkscape 1.0.1, which presumably changed a little bit the shell interface which is used in the run method in InkscapeWorker to generate the pdf from the single slides.

I have tried to fix it by changing run in the following way, as the same commands seem to work when used directly on the command line. However, that still did not work:

    def run(self):
        # this is our inkscape worker
        self.ink = subprocess.Popen(['inkscape', '--shell'],
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT)

        # first, wait for inkscape startup
        self.wait_for_inkscape()

        for svg_file, pdf_file_name, cached in iter(self.queue.get, None):

            # main working loop of the inkscape process
            # we need to wait for ">" to see whether inkscape is ready.
            # The variable ready keeps track of that.

            if not cached:
                command = "file-open:{0}".format(svg_file)
                command2 = "export-filename:{0}".format(pdf_file_name)
                command3 = "export-do"
                self.ink.stdin.write(command.encode("UTF-8"))
                self.ink.stdin.flush()
                self.wait_for_inkscape()
                self.ink.stdin.write(command2.encode("UTF-8"))
                self.ink.stdin.flush()
                self.wait_for_inkscape()
                self.ink.stdin.write(command3.encode("UTF-8"))
                self.ink.stdin.flush()
                self.wait_for_inkscape()

                print("  Converted {0}".format(pdf_file_name))
            else:
                print("  Skipping {0}".format(pdf_file_name))

Eventually, I fixed it by not using the subprocess module but instead directly calling a new instance of inkscape for each slide by using os. I realize that is not elegant and not efficient.

    def run(self):
        import os

        for svg_file, pdf_file_name, cached in iter(self.queue.get, None):

            # main working loop of the inkscape process
            # we need to wait for ">" to see whether inkscape is ready.
            # The variable ready keeps track of that.

            if not cached:
                os.system('inkscape -o "{1}" "{0}"\n'.format(svg_file, pdf_file_name))

                print("  Converted {0}".format(pdf_file_name))
            else:
                print("  Skipping {0}".format(pdf_file_name))

Do you think there is any way to solve this in a better way?

LoryPack avatar Oct 05 '20 11:10 LoryPack

I've actually just noticed some of the forks of this repo fix that issue in different ways. Check for instance:

https://github.com/janoliver/inkslides/tree/9f35281fc1b2ee5a9b83cc4f816114bd1712cf0e https://github.com/janoliver/inkslides/tree/a66f37034532be77ee10ad9a2056d6c5c9b398f8

LoryPack avatar Oct 05 '20 11:10 LoryPack