Search code examples
pdfinputoutputfilenames

How do I save a pdf with a custom file name


Im new to python and can't figure out how to save my pdf file with a custom name.

What I want to do is something like:

Name = input('What is your name: ')

pdf.output('Name.pdf')

And as I expected the name of the pdf file created is now: Name

I tried searching for it but I think im using the wrong words for it since I can't find a solution for my problem. I might be explaning it badly. But if anyone got an answer for it it would be much appreciated :)


Solution

  • Sir, in your question:

    pdf.output('Name.pdf')
    

    Here you are passing Name.pdf as a string to the output function if you want to pass the Name variable you should not use ' quotes around the value you are passing you final code should look something like this:

    name = input("Enter your name: ") 
    name = name + ".pdf" //adds .pdf extension to the name entered
    pdf.output(name)  //see how there are no quotes around name variable