Advertisement
nicuf

Convert all html pages into PDF

Jul 14th, 2023 (edited)
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. import os
  2. import pdfkit
  3.  
  4. # Calea către directorul cu fișierele HTML
  5. dir_path = 'j:/DE SCANAT/GATA - doar de scanat in txt/1/Forascu, Narcisa/Dificultati Gramaticale Ale Limbii Romane'
  6.  
  7. # Numele fișierului PDF de ieșire
  8. output_pdf = 'output.pdf'
  9.  
  10. # Găsește toate fișierele HTML din director
  11. html_files = [os.path.join(dir_path, f) for f in os.listdir(dir_path) if f.endswith(('.htm', '.html'))]
  12.  
  13. # Calea către executabilul .EXE wkhtmltopdf  INSTALL HERE:  https://wkhtmltopdf.org/downloads.html
  14. wkhtmltopdf_path = '/calea/catre/wkhtmltopdf'
  15.  
  16. # Creează o configurație cu calea către wkhtmltopdf
  17. config = pdfkit.configuration(wkhtmltopdf=wkhtmltopdf_path)
  18.  
  19. # Converteste fiecare fișier HTML în PDF și le unește
  20. pdfkit.from_file(html_files, output_pdf, configuration=config)
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement