| 12345678910111213141516171819202122232425262728293031323334 |
- import os
- from markdown_pdf import MarkdownPdf, Section
- import fitz
- docs_dir = r"c:/Users/lanfr144/Documents/DOPRO1/Antigravity/Food/docs"
- md_file = os.path.join(docs_dir, "Installation_Guide.md")
- with open(md_file, "r", encoding="utf-8") as f:
- md_content = f.read()
- pdf = MarkdownPdf()
- section = Section(md_content, paper_size="A4", root=docs_dir)
- pdf.add_section(section)
- # Try saving WITH clean=True
- doc = pdf._make_doc()
- doc.save("scratch/test_clean_on.pdf", clean=True, garbage=3, deflate=True)
- doc.close()
- # Try saving WITHOUT clean=True (only garbage=3, deflate=True)
- doc2 = fitz.open("scratch/test_clean_on.pdf")
- print("WITH clean=True, Page 2 text length:", len(doc2[1].get_text()))
- doc2.close()
- pdf2 = MarkdownPdf()
- section2 = Section(md_content, paper_size="A4", root=docs_dir)
- pdf2.add_section(section2)
- doc3 = pdf2._make_doc()
- doc3.save("scratch/test_clean_off.pdf", clean=False, garbage=3, deflate=True)
- doc3.close()
- doc4 = fitz.open("scratch/test_clean_off.pdf")
- print("WITHOUT clean=True, Page 2 text length:", len(doc4[1].get_text()))
- doc4.close()
|