Using Python to make pictures to PDF tool _python

Source: Internet
Author: User

Recently because want to see comics, helpless download the comic is JPG format, the online converter has not a good use, and then intend to do with Python DIY:
Here the main use of Reportlab. Started to write a few lines, the result of a number of pits tangled up for a long time, so think about simply write the code better.

Several of the following features are implemented:
Saves the picture under the current folder to a PDF, supports selecting PDF size, etc.
If you need to, you can traverse all the folders underneath it
In simple terms, it completely satisfies the need for me to translate the comic into PDF format.

encountered some problems , here is recorded:
First, Chinese path:

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

Second, the use of Reportlab

This is very simple to tell the truth, because did not consider adding words or something in fact, a code

Copy Code code as follows:

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

Note that the filename also needs a variety of decode AH.
Anyway, with powerful python effective code, it's about 30 lines, the code address.

Third, the Pyinstall packing problem

The beginning is intended to use the results of Py2exe to get a simple GUI (really is very simple) started with me all kinds of wrong, changed almost want to whole into an exe when have to give me a 64bit not support. And then I turned to pyinstall, but things were not so smooth, If you use the 2.1 version, you will find that there is a huge bug--package out of the EXE can not be placed in the Chinese path, and then find a variety of solutions, and then found two solutions, one is a modified version (https://github.com/dkw72n/ Pyinstaller.git), the other is to choose version 2.0. After this solution feel this is much better than Py2exe, highly recommended!
Simple to use the process:
The first is to install:
1, download and install pywin32;
2, download the 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 the installation is not necessary (of course, you can install ...) )
Use words is

Copy 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, the--onedir py code is placed in a directory (this is the default)
-K,--TK contains TCL/TK
-D,--debug generates the debug mode EXE file
-W,--windowed,--noconsole form exe file (Windows only)
-C,--nowindowed,--console console exe file (Windows only)
-X,--UPX using UPX compressed EXE file
-O DIR,--out=dir set spec file output directory, default in Pyinstaller directory
--icon= Add icon (Windows only)
-V file,--version=file add version information file
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 entire content of this article, I hope that 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.