test_clean_save.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import os
  2. from markdown_pdf import MarkdownPdf, Section
  3. import fitz
  4. docs_dir = r"c:/Users/lanfr144/Documents/DOPRO1/Antigravity/Food/docs"
  5. md_file = os.path.join(docs_dir, "Installation_Guide.md")
  6. with open(md_file, "r", encoding="utf-8") as f:
  7. md_content = f.read()
  8. pdf = MarkdownPdf()
  9. section = Section(md_content, paper_size="A4", root=docs_dir)
  10. pdf.add_section(section)
  11. # Try saving WITH clean=True
  12. doc = pdf._make_doc()
  13. doc.save("scratch/test_clean_on.pdf", clean=True, garbage=3, deflate=True)
  14. doc.close()
  15. # Try saving WITHOUT clean=True (only garbage=3, deflate=True)
  16. doc2 = fitz.open("scratch/test_clean_on.pdf")
  17. print("WITH clean=True, Page 2 text length:", len(doc2[1].get_text()))
  18. doc2.close()
  19. pdf2 = MarkdownPdf()
  20. section2 = Section(md_content, paper_size="A4", root=docs_dir)
  21. pdf2.add_section(section2)
  22. doc3 = pdf2._make_doc()
  23. doc3.save("scratch/test_clean_off.pdf", clean=False, garbage=3, deflate=True)
  24. doc3.close()
  25. doc4 = fitz.open("scratch/test_clean_off.pdf")
  26. print("WITHOUT clean=True, Page 2 text length:", len(doc4[1].get_text()))
  27. doc4.close()