I have a report text file, which is created by my python script. I want to create pdf file from mentioned text file in python script. After searching, I came across reportlab library, but in tutorials of same library it shows creating pdf having manually written contents.However I want to convert my text file to pdf file.
Is there any other option, any script?
thank you in advance.
Related
I have a PDF file that was created from a Jupyter notebook, but the original .ipynb file is lost.
Is there some tool that would help to convert PDF to .ipynb?
that may not be possible since .ipynb file contains pieces of code that requires for it to execute in jupyter notebook ..so the best option is to try to copy the contents from the pdf on to new .ipynb file and execute it.
PDF to Python is straightforward, but it takes several steps. Essentially you must extract the code to text format and then parse and clean it up to get it back into an executable format.
Save the PDF as text file. Adobe Acrobat does this well, but there are several Python PDF libraries to extract text from any PDF.
parse the text to identify and capture the Python code (as text strings)
Convert the Python text strings to Python tokens.
Clean or lint the Python code to format it so that it will run without errors due to indentation. You can use the Python "black" module or PEP8 linter to clean up indentation.
There are numerous examples of parsing Python in HTML format to Jupyter Notebook format. Spyder and VSCode linters work well to fix indentation.
Not possible to convert pdf into ipynd. But you can use google lens it will help you in copy pasting.
Python3: How do I import an excel spreadsheet into python project? (I'm using repl.it website for learning python3). I want to automate the entering of data into several connected spreadsheets. I'm trying to automate my work so that I don't have to do it manually anymore.
You can process Excel files directly if you use a local install of Python and a library like OpenPyXL or others.
However, as a workaround, in Excel save the file as a .csv (comma separated values). Open that .csv in a text editor. Copy the contents. In repl.it, click the new file button and create a new file called something like input.csv and paste in the contents.
Repl.it does have the csv library since that's a native library. Details are at https://docs.python.org/3.6/library/csv.html. That should let you read in the data fairly easily.
Since you are dealing with several connected spreadsheets, you may have to do this step with each one and create a new .csv file as your result which you can then open in Excel and save as an Excel file. However, you really are pushing the bounds of what can be done in an online repl.
If you are dealing with large files or want to skip the "save as csv" step, you'll need a local installation of Python.
I need to convert .doc and .docx files to .pdf using python . I have seen some answers already available but that are using comtypes and opening WordApplication. I can not do that.
What I seek is a way of doing it using some python libraries that preserves font , tables , heading size and images etc , without opening MS Word or LibreOffice or anything like that
Converting .doc and .docx files to some intermediate format(and later converting that format to pdf) would be fine too , if needed . Please help me with the code or guided instructions(I am not a pro in python) I should follow.
I have been in the similar problem earlier,
My suggestion:
sorry there is no such direct python library to handle Microsoft office formats specially (.doc)
So try to use LibreOffice as a service in Ubuntu its "libreoffice"
if windows its "soffice.exe" use this in command line to convert the document to .PDF without opening LibreOffice
and its easy and fast too and more over gives almost perfect conversion of the file.
A sample:
For Windows:
C:\Program Files (x86)\LibreOffice 4\program\soffice.exe" --headless --convert-to pdf "input_file_path" --outdir "output_dir_path"
This will convert the input file into pdf in the given output directory without opening the LibreOffice ans just using it as a service.
To run this command from python you can use "subprocess" like libraries.
I am facing a strange problem
Whenever my python scripts are creating any csv file, it is making them "Archive".
I mean in properties, Archive check box is checked.
Because of which it can't be read in later part of same script .
How can i create a csv file not archive?
Please help me resolve this problem.
Are you running a Windows OS? If yes, then this is not a problem with the Python CSV library. As about the error encountered while reading the CSV; you may want to re-check your python code for any flaws.
The Archive checkbox is actually an attribute of the file on Windows systems that indicates that the file needs to be backed up. Right click on any other file and you should see "Archive" checked.
Here are a couple of links that would give you more information
MSDN Technet discussion on File Attributes
Wikipedia article on Archive bit
This may be a confusing question. After writing a text file I would like to execute a command in Python which can open the text file created in a text viewing application, such as the default text editor supplied with Mac OSX. I was wondering how this could be done within the script...? I'd like to specify which program to open it in because the extension won't be automatically recognised.