Use a python DIY image conversion pdf tool and package it into an exe

Source: Internet
Author: User

Use a python DIY image conversion pdf tool and package it into an exe
Recently, because I want to watch cartoons, I have to download them in jpg format. The online converter is not easy to use yet, so I plan to use python to DIY it myself: Here I mainly use reportlab. I started to write a few lines at will, and the result was a long struggle for a number of pitfalls. So I thought about writing the Code better. The following functions are implemented: Save the images in the current folder to a pdf file, you can select the pdf size. If necessary, you can traverse all the folders below it. Simply put, it fully meets the requirement of converting comics into pdf format. Some problems have been encountered. Here we record: 1. Chinese path: This is really a little painful. In short, decode it all as much as possible. Then note that the path in win is \, and you need to convert it /. When traversing the path, pay attention to how to write the path. 2. It's easy to tell the truth with reportlab, because I didn't consider adding some text or something. c. drawImage (filelist [I], 0, 0, maxw, maxh). Note that various types of decode are required for file names. In short, there are about 30 lines of effective code with powerful python. Code address 3. The Packaging Problem of pyInstall begins with the intention to use py2exe results to get a simple gui (it is really very simple) at the beginning, I started to make all kinds of errors. I was asked to provide 64bit not support when I thought about converting it into an exe. Then switch to pyInstall, but it is far from so smooth, if version 2.1 is used, you will find another huge bug. The packaged exe cannot be placed in the Chinese path, then two solutions were found, one being a modified version (https://github.com/dkw72n/pyinstaller.git) and the other being a 2.0 version. This solution is much better than py2exe. It is strongly recommended! To put it simply, the installation process is as follows: the idea is moved to the pyInstall folder, and the installation is not required (of course you can install it too ...) Python pyinstaller. py-F c: \ scripts \ main. py. If you do not want a black box, add the-w parameter. Other parameters:-F, -- onefile Py code has only one file-D, -- onedir Py code is placed in a directory (this is the default)-K, -- tk contains TCL/TK-d, -- debug generates the exe file in debug mode-w, -- javaswed, -- noconsole form exe file (Windows Only)-c, -- now.wed, -- console exe file (Windows Only)-X, -- upx uses upx to compress the exe file-o DIR, -- out = DIR to set the directory output by the spec file, by default, the icon (Windows Only)-v FILE and -- version = FILE are added to the same directory of PyInstaller.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.