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

PDF generation not working with inkscape 1.0 #8

Open
LoryPack opened this issue Oct 5, 2020 · 1 comment
Open

PDF generation not working with inkscape 1.0 #8

LoryPack opened this issue Oct 5, 2020 · 1 comment

Comments

@LoryPack
Copy link

LoryPack commented Oct 5, 2020

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
Copy link
Author

LoryPack commented Oct 5, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant