Hello readers of my blog. Today I will tell you about programs that will help you when converting a large number of drawings or photographs in jpg or bmp format to pdf file.
This method is very good in that it preserves the quality of images and allows you to convert and pack a huge number of files.
There are not so many similar programs on the Internet and, in general, they are paid.
An urgent need forced me to develop such a method. Since I often have to work with a large number of files that need to be structured while maintaining quality.
, .
, , .
python
.
jpg pdf. . .
os PIL
import os
import PIL.Image
def img2pdf(fname):
filename = fname
name = filename.split('.')[0]
im = PIL.Image.open(filename)
if not os.path.exists('im2pdf_output'):
os.makedirs('im2pdf_output')
newfilename = ''.join(['im2pdf_output/',name,'.pdf'])
PIL.Image.Image.save(im, newfilename, "PDF", resolution = 100.0)
print("processed successfully: {}".format(newfilename))
files = [f for f in os.listdir('./') if f.endswith('.jpg')]
for fname in files:
img2pdf(fname)
pdf pdf , , ...
PyPDF2
from PyPDF2 import PdfFileMerger
pdfs = []
t=1
for i in range(8):
f=str(t)+".pdf"
pdfs.append(f)
t=t+1
print(pdfs)
merger = PdfFileMerger()
for pdf in pdfs:
merger.append(pdf)
merger.write("result.pdf")
merger.close()
.
Here is a link to download files
DOWNLOAD