Make a picture-to-pdf tool with Python

Source: Internet
Author: User
Recently because you want to read comics, but download the comic is JPG format, the online converter has not a good use, and then intends to do DIY with Python:
The main use of reportlab here. began to write a few lines, the results for a number of pits tangled for a long time, so think about simply write the code well.

Several of the following features are implemented:
Saves the picture under the current folder to a PDF, supports selection of PDF size, etc.
If you need to, you can traverse all the folders underneath it.
In a nutshell, it's completely satisfying my need to turn comics into PDF format.

There are some problems that are recorded here:
One, Chinese path:

This is really a little egg ache, in short, try to decode it all over again. Then notice that the path under win is \, to convert it to/. The path is then traversed to note how the path is written.

Second, the use of Reportlab

It's easy to tell the truth, because you don't have to consider adding text or something.

Copy the Code code as follows:


C.drawimage (Filelist[i], 0,0,maxw,maxh)

Note The file name also want various decode AH.
All in all, with powerful Python code, it's about 30 rows, code addresses.

Three, pyinstall of packaging problems

The beginning is intended to use the Py2exe result is intended to take a simple GUI (really is very simple) start with me all kinds of mistakes, change almost want to complete an EXE when there is a 64bit not support. Then he turned to Pyinstall, but things were far from smooth. If you use the 2.1 version, you will find another huge bug--packed EXE incredibly can not be placed in the Chinese path, so various find solutions, and then found two ways to solve, one is a modified version (https://github.com/dkw72n/ Pyinstaller.git), the other option is version 2.0. After this solution feel this is much better than Py2exe, highly recommended!
Simply say the use process:
The first is the installation:
1. Download and install Pywin32;
2. Download pyInstall2.0 version (I think this is the best)
3. Download UPX and then move the Upx.exe in the folder to the Pyinstall folder
This is done, even if the installation is not necessary (of course, you can install the line ...) )
Using the words is

Copy the Code code as follows:


Python pyinstaller.py-f c:\scripts\main.py

If you do not want the black box, then add a-w parameter is good. Other parameters:

-F,--onefile PY Code has only one file
-D,--onedir py code in a directory (this is the default)
-K,--TK contains TCL/TK
-D,--debug generate EXE file for debug mode
-W,--windowed,--noconsole form exe file (Windows only)
-C,--nowindowed,--console console exe file (Windows only)
-X,--upx use UPX to compress exe files
-O DIR,--out=dir set spec file output directory, default in Pyinstaller directory
--icon= Join icon (Windows only)
-V file,--version=file join version information files
Finally pyqt an ugly shrinking interface (OK. I admit I'm not very good at writing.

Packing size 9M is acceptable.
Running effect (not bad):

The above is the whole content of this article, I hope the small partners like.

  • Related Article

    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.