Pliki HTML do PDF

Convert an entire HTML file into a pixel-perfect PDF with IronPDF for Python’s RenderHtmlFileAsPdf method.

Pierwsze kroki

To convert an HTML file to PDF, you can use the RenderHtmlFileAsPdf method. This method requires only the path to the local HTML file and returns a PdfDocument object. Ten obiekt zawiera treść z pliku HTML, wyświetlaną tak, jakby była przeglądana w przeglądarce internetowej. Upewnij się, że kod HTML zawiera poprawne znaczniki, aby uniknąć problemów z renderowaniem.

Oto prosty przykład wykorzystania tej metody:

Zrozumienie kodu

  • ChromePdfRenderer: Ten obiekt służy jako punkt interakcji z procesem renderowania. Umożliwia dostosowanie pliku PDF poprzez ustawienie właściwości, takich jak nagłówki, stopki i inne.

  • ChromePdfRenderer: This method takes a path to an HTML file and converts it into a PdfDocument. Wygenerowany plik PDF będzie ściśle odpowiadał plikowi HTML wyświetlanemu w przeglądarce internetowej.

  • save_as: This method saves the newly created PDF document to the specified path on your file system.

Dostosowywanie pliku PDF

ChromePdfRenderer comes with various options for customization, including setting headers, footers, margins, backgrounds, page numbers, etc. For more advanced features and customization, see this code example and learn how to customize PDF output.

Naucz się konwertować HTML na PDF dzięki temu samouczkowi!

Gotowy, aby rozpocząć?
Wersja: 2026.4 just released
Still Scrolling Icon

Wciąż przewijasz?

Czy chcesz szybko dowodu?
Uruchom przykład i zobacz, jak Twój kod HTML zamienia się w plik PDF.