Part of my job is to print several hundred labels per day with a Dymo labelwriter. We use macOS for everything, and installing Windows is out of the question as it would break tons of workflow. We have a template file that I can modify using Python's xml.etree module. How would I print the labels to our labelwriter using solely Python? I've read up on using os.system to send the data straight to the printer, but I'm not sure how that would work with an XML file and a labelwriter, which seems incredibly proprietary. I don't mind using other languages or APIs as long as they're easy to explain to the non-technical people in the office. Also open to using AppleScript.
Related
Is it possible to convert Dwg to pdf file using Python?
I have multiple Dwg files that need to convert to pdf.
I am experimenting to create an app to convert but can not find any solution?
Please, if you have any idea help.
Vector Express is a free API you may able to use. (requires a network connection, though)
https://github.com/smidyo/vectorexpress-api
Of course it is possible to write a code in Python to publish DWG file as PDF.
However, DWG is a proprietary file format from AutoCAD, therefore there are a lot of legal issues to distribute the code (beyond your private usage), unless you get a written consent from AutoCAD...
You'll find several application that would already do the job.
Maybe check Open Design Alliance as a starting point.
Using QCAD Command Line Tools (Open Source)
According to qcad.org "QCAD is a free, open source application for computer aided drafting (CAD) in two dimensions (2D). With QCAD you can create technical drawings such as plans for buildings, interiors, mechanical parts or schematics and diagrams. QCAD works on Windows, macOS and Linux. The source code of QCAD is released under the GPL version 3 (GPLv3), a popular Open Source license."
Supported Command Line Conversions
dwginfo
dwg2csv
dwg2bmp
dwg2svg
dwg2pdf
dwgmapconvert
dwg2maptiles
dwg2dwg / pdf2dwg
dwghatch
dwghatcharea
dwgexplode
merge
bbox
dwgnest (QCAD/CAM)
The above commands are very self-explanatory for further information please refer to the above embedded url at qcad.org
Usage in Python
Though I believe that this might not be best practice but a os.system command as follows, might be enough for most use cases
I'm new to programming and recently started getting into Python a lot more seriously. However, I've done some projects that required programming in my company, so I have some background on how it works (or how to scour the internet! lol).
Recently however, we have had a client that sends us invoices in PDF formats and we would like to automate all the invoices to compile into one .csv file.
I've been picking up a few OCR codes (I ran my first image-to-text output recently), however I don't think I'm 100% capable of creating such automation yet since I'm still very fresh in programming. It would require at least a few weeks, and I'm not sure if it's worth it if we could just ask the client to set up a more accurate excel spreadsheet to send over every time.
That's why I'm turning to an already available OCR tool. I recently found this gem: https://www.pdftoexcel.com/ however it is a very manual process and not as automated as we could like. If there is a way to program a script to upload an available PDF file from a certain folder in order to upload it to the website and export it into an Excel file every time we receive an invoice, would it be possible to share?
It would also be a big plus if there would be a way to upload a batch of invoices and identify different charges, providing a summary across the scanned invoices, particularly in the categories
I hope what I'm asking for makes sense. Let me know if you'd require more clarification.
Cheers
There's lots of stuff available for Python, if you have a quick search on Google or StackOverflow. I believe I used Tesseract OCR in the past.
My experience is that you will get serviceable OCR with some of the popular Python libraries, but the excellent stuff will come with a price tag.
Try some tests with your PDF invoices, but if you are getting even slightly questionable results, you may have to consider more expensive alternatives (or even standalone machinery!).
If the client is sending you clear, nicely formatted PDFs with a good font, I don't see why free Python libraries wouldn't be sufficient.
First of all, I agree that this might sound like a question which has already been asked many times in the past. However I couldn't find any answer that was relevant to me in the similar questions so I'll try to be more specific.
I would need to transform PPTX/DOCX files into PDF using Python but I don't have any experience in file format conversion. I have been looking in many places/forums/websites, read a lot of documentation and came across some useful libraries (python-pptx and pyPdf mainly), but I still don't know where to start.
When looking on the Internet, I can see many websites that offer file format conversions as a paying service, even with advanced API's: submit a file via POST and get the transformed PDF file in return. This could work for me, but I am really interested in writing myself the code that does the conversion work from OOXML to PDF.
How would you start doing this? Or is it just impossible on my own?
Thanks for your help!
After some research and with the help of python-pptx's creator, I was able to write to the PowerPoint COM interface using a Virtual Machine.
In case someone reads this thread, this is how I managed to get this done:
- Setup a VM with Microsoft Windows/Office installed on it ;
- Install Python, Django and win32com libraries on the VM.
The files are sent locally from the original Django project to the virtual machine (which are on the same network) through a simple POST request. The file is converted on the VM using win32com.client (which is just a simple call to the win32com.client library) and then sent back as a response to the original Django view, which in turn processes the response.
Note: it took me some time to realize I needed to use the #csrf_exempt decorator for this setup to work.
I'm building a web application which will include functionality that takes MS Word (and possibly input from a web-based rich text editor) documents, substitutes values into the formfield placeholders in those documents, and generates a PCL document as output.
I'm developing in python and django on windows, but this whole solution will need to be deployed to a web host (yet to be chosen), which in practice means that the solution will need to run on linux.
I'm open to linux-only solutions if that's the only way. I'm open to solutions that involve talking to a server written in another language. I am able to write C++ or java if necessary to get this done. The final output does have to be in PCL format.
My question is: what is a good tool chain for generating PCL from word documents using python?
I am considering using some kind of interface to openoffice to open the word documents, do the substitutions, and send the output to some kind of printer driver. Does anyone have experience with this? What libraries would you recommend?
Options for interfacing that I have identified include the following; any other suggestions would be greatly welcomed:
Ulif.openoffice: http://pypi.python.org/pypi/ulif.openoffice/0.4
Py3o.renderserver: https://bitbucket.org/faide/py3o.renderserver
OpenOffice-python: http://openoffice-python.origo.ethz.ch/
A second approach would be to use something like paradocx ( https://bitbucket.org/yougov/paradocx/wiki/Home ) to open the word files, do the substitutions using that in python, then somehow interface with something that can output PCL. Again, any experience or comments on this approach would be appreciated.
I will very much appreciate any comments on tools and toolchains, and ideas or recipes that you may have.
This question covers similar ground to, but is not the same as: How to Create PCL file from MS word
Ghostscript can read PS (Postscript) or PDF and create PCL. You can use python libraries or just subprocess....
OK, so my final solution involved creating a java webservice to perform my transcoding.
Docx4j provides a class org.docx4j.convert.out.pdf.viaXSLFO.Conversion which hooks into apache FOP to convert Docx to PDF; that can be easily hacked to convert to PCL (because FOP outputs PCL)
Spark is a lightweight java web framework which allowed me to wrap my transcoder in a web service
Because I also manipulate the document, I need to have some metadata, so the perfect thing is a multipart form. I decode that using Apache Fileupload
In almost all cases, I had to upgrade to the development versions of libraries to get this to work.
On the python side I use:
requests to communicate with the web service
poster to prepare the multi-part request
On an Ubuntu server, I want to create pdfs which include other static pdfs. I have tried using ReportLab with pyPdf. Ideally I would use ReportLab to do the whole thing, but in order to import the pdfs requires their PageCatcher which has a large recurring fee.
So I use pyPdf to merge a page created with ReportLab and my other pdfs. The problem is that even though this looks fine in Acrobat and Foxit, part of one of the pages prints garbled on a Xerox 7400 color printer. I can't figure out the issue, but would be willing to buy a more integrated solution if it existed and was reasonably priced. I thought PDF Creator Pilot was it until I saw that it was Windows only.
So is there a reasonably priced ($1K or less) solution or a different suggestion?
I have had a lot of success with the Java library iText. They have a great library of samples for pretty much anything you could think of doing with PDF files. This example is for concatenating PDF files and sounds like it would do what you need: http://itextpdf.com/examples/index.php?page=example&id=123. There is also PDFBox which is another great Java based PDF manipulation library.
I realize that you are looking for a Python based solution but there may not be many other options. If you are using the Jython interpreter instead of CPython, integrating in iText should be trivial. If not, then you could consider calling out to it as a separate process. I realize that may not be idea for your situation but I figured I would mention it as an option.
Another non-Python answer. If you are just merging pages, then pdftk does that well (along with a lot of other things).