PDF adding pages to existing file
-
Hello,
I'm currently using Drawbot to generate a character set of the current font. The problem is that when saves the PDF it doesn't generate a new file but it keeps adding pages to an existing PDF in the directory.
I'm not sure how much would help to have the whole script but for now I'm sharing the block of code that I think is causing this problem. I guess it is the way I'm saving the PDF.
# ----------------------------------------------------- # Accessing the directory of the file fDirectory = os.path.dirname(f.filepath) # Directory fName = os.path.basename(f.filepath) # Only the name fNameParts = os.path.splitext(fName) # Split parts fPath = f.filepath # ----------------------------------------------------- # Generating a file with the character set NewfName = fNameParts[0] + ' - Character set.pdf' # Change extension NewfPath = os.path.join(fDirectory, NewfName) # Saving the .pdf saveImage(NewfPath)
Thanks beforehand for any help!
-
hello @RicardGarcia,
from the problem description, it sounds like you’re saving the pdf inside a loop, for example after making each page. usually what you want to do instead is create pages with a loop, and then save the pdf at the end outside the loop.
(the snippet you posted is not related to the problem, I think)
hope this helps!
-
ps. see also this character set proof example using the DrawBot extension in RoboFont.
-
Thanks for the answer, @gferreira. I'm actually saving the pdf at the very end of the script outside the loop that creates the pages.
I'm using Drawbot inside Glyphs and, just to test it, I've run the script both using Drawbot as a module (which generates the problem) and running it with the UI inside Glyphs and it works fine.
I still don't fully get what's going on there, do you have any idea? I could share the code if you want.
Thanks again for your help and the link.
-
outside the app DrawBot, when using DrawBot as a module, you have to call
drawBot.newDrawing()
to reset the drawing stack.see https://www.drawbot.com/content/canvas/pages.html#drawBot.newDrawing
its also adviced to call
drawBot.endDrawing()
when you are done.see https://www.drawbot.com/content/canvas/pages.html#drawBot.endDrawing
-
Thanks @frederik! This was what I was missing and now it works just as I expected.
-
Hello again,
I'm again using DrawBot as a module to use it inside Glyphs and, while ths script works inside Drawbot's plugin in Glyphs, it doesn't generate the same output when I'm using it as a script.
I'm using
newDrawing()
andendDrawing()
but still it doesn't work.Any idea what it could be?
Thanks!