Python yordamida rasmlarni pdf-ga aylantirish (Image->pdf) Annotatsiya
Download 30.58 Kb.
|
Python yordamida rasmlarni PDFga almashtirish
- Bu sahifa navigatsiya:
- Kalit so’zlar
- Python yordamida rasmlarni PDF-ga aylantirish uchun qadamlar ketma-ketligi: 1-qadam: PIL paketini ornatish.
- 3-qadam: Python yordamida rasmni PDF-ga aylantirish
- Rasmlarni PDF ga aylantirish uchun vosita
Python yordamida rasmlarni PDF-ga aylantirish (Image->PDF) Annotatsiya. Ushbu maqolada hozirgi kunda reytinggi baland bo’lgab Python dasturlash tilida rasmlarni PDFga almashtirish dasturlar yaratish texnologiyasi tasvirlangan. Yuqori tezlikdagi, yuqori darajali Python dasturlash tili, samaradorligi, dasturlash texnologiyalari, axborot-kommunikatsiya texnologiyalari asosida dasturlar yaratish qulayligi yuqori bo’lgan va dastur yechimi aniq va juda tez olinadigan dastrurlash kodi bo’lgan Python dasturlash tilini o’rgatish muhim ahamiyatga ega. Kalit so’zlar: Python, dasturlash tili, grafika, texnologiya, axborot, kompyuter, dasturiy ta'minot,dasturiy vosita, rasm. Uchbu maqola yordamida biz Python dasturlash tili yordamida rasmlarni PDFga aylantirishni to’liq ko’rib o’tamiz. Dastlab, Python yordamida “png” tasvirini (JPEG uchun "jpg" fayl kengaytmasidan foydalaniladi) PDF- ga aylantirish uchun foydalanishimiz mumkin bo'lgan dastur kodi(asosiy kod): from PIL import Image ima1 = Image.open(r'rasm saqlanadigan yo`l\fayl nomi.png') im1 = ima1.convert('RGB') im1.save(r'pdf saqlanadigan yo`l\fayl nomi.pdf') Python yordamida rasmlarni PDF-ga aylantirish uchun qadamlar ketma-ketligi: 1-qadam: PIL paketini o'rnatish. Birinchi bo’lib quyidagi buyruq yordamida PIL paketini o'rnatiladi: pip install Pillow (pip install qilingan bo’lishi kerak) 2-qadam: Tasvir saqlangan yo’lni olish. Keyin rasm saqlanadigan yo'l olinadi(agar rasm va python fayl bitta katalogda joylashgan bo’lsa yo’l shart emas. Masalan: Image.open(r'fayl nomi.png' ). Masalan: C:\Users\user\Desktop 3-qadam: Python yordamida rasmni PDF-ga aylantirish Yakuniy bosqichda tasvirni PDF-ga aylantirish uchun quyidagi dastur kodidan foydalanishimiz mumkin: from PIL import Image image1 = Image.open(r' C:\Users\user\Desktop\2.png') im1 = image1.convert('RGB') im1.save(r' C:\Users\user\Desktop\55.pdf') Demak, bizning dasturimizda rasm nomi 2.png va PDF faylizmiz nomi 55.pdf Dastur kodi ishga tushirilgach C:\Users\user\Desktop\55.pdf nomli PDF faylimiz hosil bo’ladi. Python yordamida rasmlar ro'yxatini PDF-ga aylantiringAgar sizda rasmlar ro'yxati bo'lsa va ularning barchasini bitta PDF faylida saqlamoqchi bo’lsangiz quydagi dastur kodi yordamida bajarish mumkin: image1 = Image.open(r'1.jpg') image2 = Image.open(r'2.jpg') image3 = Image.open(r'3.jpg') image4 = Image.open(r'4.jpg') Konvertatsiya qilinadi: im1 = image1.convert('RGB') im2 = image2.convert('RGB') im3 = image3.convert('RGB') im4 = image4.convert('RGB') Keyin yangi tasvirlar ro'yxati yaratiladi (birinchi rasmdan tashqari im1): imagelist99 = [im2,im3,im4] Dastur oxirida PDFga saqlash kodi yoziladi(im1ga e’tibor bering): im1.save(r'55.pdf',save_all=True, append_images=imagelist99) To’liq dastur kodi: from PIL import Image image1 = Image.open(r'1.jpg') image2 = Image.open(r'2.jpg') image3 = Image.open(r'3.jpg') image4 = Image.open(r'4.jpg') im1 = image1.convert('RGB') im2 = image2.convert('RGB') im3 = image3.convert('RGB') im4 = image4.convert('RGB') imagelist99 = [im2,im3,im4] im1.save(r'55.pdf',save_all=True, append_images=imagelist99) PDF faylimiz barcha rasmlarni o’z ichiga oladi. Rasmlarni PDF ga aylantirish uchun vosita Pytonning grafik interfeysi va tkinter paketiga asoslanib, rasmlarni PDFga almashtirish uchun vosita kodi: from PIL import Image import tkinter as tk from tkinter import filedialog from tkinter import messagebox root= tk.Tk() canvas1 = tk.Canvas(root, width = 300, height = 300, bg = 'lightsteelblue2', relief = 'raised') canvas1.pack() label1 = tk.Label(root, text='File Conversion Tool', bg = 'lightsteelblue2') label1.config(font=('helvetica', 20)) canvas1.create_window(150, 60, window=label1) def getFile (): global im1 import_file_path = filedialog.askopenfilename() image1 = Image.open(import_file_path) im1 = image1.convert('RGB') browseButton = tk.Button(text=" Select File ", command=getFile, bg='green', fg='white', font=('helvetica', 12, 'bold')) canvas1.create_window(150, 130, window=browseButton) def convertToPdf (): global im1 export_file_path = filedialog.asksaveasfilename(defaultextension='.pdf') im1.save(export_file_path) saveAsButton = tk.Button(text='Convert to PDF', command=convertToPdf, bg='green', fg='white', font=('helvetica', 12, 'bold')) canvas1.create_window(150, 180, window=saveAsButton) def exitApplication(): MsgBox = tk.messagebox.askquestion ('Exit Application','Are you sure you want to exit the application',icon = 'warning') if MsgBox == 'yes': root.destroy() exitButton = tk.Button (root, text='Exit Application',command=exitApplication, bg='brown', fg='white', font=('helvetica', 12, 'bold')) canvas1.create_window(150, 230, window=exitButton) root.mainloop() Download 30.58 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling