Saving PDF with no user prompt. system.file.wirteFile()

I am looking to save a PDF to a file location without a user prompt. When Adding .pdf to the end of file
error occurs. Is there a solution or way of changing so it saves the file as a pdf?

reportBytes =‘ReprotName’,project=‘ProjectName’,

To make PDF file.

I was able to do so using system.file.writeFile(filePath + fileNmae,reportBytes) then
I found that it was writing to a text file. When I added a file extension of .pdf it gave
me the below error. Without the PDF extension it has no error and creates the file.

IOError: File ‘\serv\folder1\folder2\filename.pdf’ doesn’t exist or isn’t a file.


Hi Brandon,

You need to make sure that the filepath is correct before running the writeFile() function. The following worked for me:

data = "test"
system.file.writeFile("C:\\Users\\obober\\Documents\\test.pdf", data)

Try printing your filepath to see if it matches the format above.

Thank you sir that was the issue had to modify the code to meet that format.

filePath = "\\\\\\serv\\\\dir1\\\\dir2\\\\"

Much appreciated.

If you prefix the string literal with r, you don’t need quite as much escaping (although Python won’t allow a string to end in backslashes without slight hurdles); that is, these two both create the exact same string:

a = "\\\\\\serv\\dir1\\dir2\\"
b = r'\\\serv\dir1\dir2' + '\\'
1 Like