I am using reportab to generate a pdf file.
The last sentences of my script are as follows:
doc.build(story)
os.system('xxxx.pdf') # show the pdf file.
Then leave the script and save the created pdf file where I like. But, I want to know how can I save the file without showing it.
doc.save('xxxx.pdf')
: *** AttributeError: 'SimpleDocTemplate' object has no attribute 'save'
What can I do to save the file automaticaly
The command
os.system('xxxx.pdf')
means that the PDF is already saved onto disk at 'xxxx.pdf'. Just remove the os.system command that launches your default PDF viewer, and you will see the PDF in the folder.
Related
I am trying to merge 2 pdfs and write to one pdf using pypdf2.
Below is the code to read the file content
output = PyPDF2.PdfFileWriter()
for pdffile in self.files:
input = PyPDF2.PdfFileReader(pdffile, strict=False)
where self.files is file objects
I am getting below error when trying to read one particular pdf file
TypeError: 'NumberObject' object has no attribute 'getitem'
When i ran ghostscript on the pdf file i found that the file is corrupted and the repaired one i am able to read without errors. I wanted to check if there is any way i can read the corrupted pdf file using pypdf2 only without errors?
Thanks in Advance.
Using this command, unfortunately it always creates that file for me, losing the previous data:
Account.save("Ex.xlsx")
The command: SaveCopyAs not work with a workbook
I would simply like to replicate the SaveCopyAs command on python to save my excel file after writing and updating it. Unfortunately with the save command, I delete all the previous content
When you execute Example=Workbook(), you are making a new file. That means when you execute Example.save("Jungle.xlsx"), you are overwriting the original file. Instead, you should use Example = load_workbook('Jungle.xlsx') to read the contents of the original so that Example.save("Jungle.xlsx") can act like an update.
See https://openpyxl.readthedocs.io/en/stable/tutorial.html#loading-from-a-file for more details.
I am using Jupyter notebook and learning to read and write files. Now I created this file
enter image description here
To add a line, I used the append mode and since append mode takes the cursor to the end of the txt file, I should use "\n" but I am able to add a new line without it. I don't understand why.
enter image description here
I have a file which is not .txt extension, but I can right click and open it using notepad, and it's a readable file.
However, if I try to open the file I cannot retrieve the text, or edit it.
Here's some code to make things clearer:
path=r"C:\Users\Alon\Desktop\RUN Low.spe"
f=open(path,'r+')
f.readlines()
Output:
[]
Again, if I try to open this file using Notepad - no problems. I can read and edit the text, but I wanna do it via Python. Is there a solution to this?
I am able to load an log file using the following command:
logFile = sc.textFile("/resources/jupyterlab/labs/BD0211EN/LabData/notebook.log")
But when I try to see the log file contents, I am not able to do. I checked dir(logFile), but I am not able to see the content inside. Now when I run the code in the Jupyter cell, I get the following:
/resources/jupyterlab/labs/BD0211EN/LabData/notebook.log MapPartitionsRDD[1] at textFile at NativeMethodAccessorImpl.java:0
Is it possible to see the contents of the log file?
Thanks
I guess what you need is the following:
logFile.collect()
This will show you the content's that are split line wise.