Tôi đang cố gắng cải thiện PDF được tạo của mình được tạo bởi xhtml2pdf
với một số CSS style
trong
from xhtml2pdf import pisa # import python module # Define your data source_html = "0 của tôi.To PDF or not to PDF
" output_filename = "test.pdf" # Utility function def convert_html_to_pdf[source_html, output_filename]: # open output file for writing [truncated binary] result_file = open[output_filename, "w+b"] # convert HTML to PDF pisa_status = pisa.CreatePDF[ source_html, # the HTML to convert dest=result_file] # file handle to recieve result # close output file result_file.close[] # close output file # return False on success and True on errors return pisa_status.err # Main program if __name__ == "__main__": pisa.showLogging[] convert_html_to_pdf[source_html, output_filename]
Tôi muốn ví dụ như
from xhtml2pdf import pisa # import python module # Define your data source_html = "1, nhưng rõ ràng, nó không hoạt động và tôi không tìm thấy tại sao. Tôi đang đọc rất nhiều tài liệu về thư viện này, tôi đã viết một số tập lệnh CSS nhưng vẫn không có gì.To PDF or not to PDF
" output_filename = "test.pdf" # Utility function def convert_html_to_pdf[source_html, output_filename]: # open output file for writing [truncated binary] result_file = open[output_filename, "w+b"] # convert HTML to PDF pisa_status = pisa.CreatePDF[ source_html, # the HTML to convert dest=result_file] # file handle to recieve result # close output file result_file.close[] # close output file # return False on success and True on errors return pisa_status.err # Main program if __name__ == "__main__": pisa.showLogging[] convert_html_to_pdf[source_html, output_filename]
Đây là tệp HTML của tôi:
{% load staticfiles %}
p {text-align: justify;}