| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 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()
- # Current CSS
- user_css = """
- * {
- color: #1a1a1a !important;
- }
- body {
- font-family: 'Helvetica', 'Arial', sans-serif !important;
- color: #1a1a1a !important;
- background-color: #ffffff !important;
- }
- h1, h2, h3, h4, h5, h6, h1 *, h2 *, h3 *, h4 *, h5 *, h6 * {
- color: #000000 !important;
- margin-top: 18px !important;
- margin-bottom: 8px !important;
- }
- pre {
- background-color: #f8f9fa !important;
- border: 1px solid #e9ecef !important;
- padding: 2px !important;
- margin-top: 8px !important;
- margin-bottom: 16px !important;
- border-radius: 3px !important;
- font-family: 'Courier New', 'Courier', monospace !important;
- font-size: 10pt !important;
- white-space: pre-wrap !important;
- word-break: break-all !important;
- }
- pre code, pre * {
- font-family: 'Courier New', 'Courier', monospace !important;
- font-size: 10pt !important;
- color: #212529 !important;
- background-color: #f8f9fa !important;
- white-space: pre-wrap !important;
- word-break: break-all !important;
- }
- code {
- font-family: 'Courier New', 'Courier', monospace !important;
- font-size: 10pt !important;
- color: #b02a37 !important;
- background-color: #f8f9fa !important;
- padding: 2px 4px !important;
- border-radius: 3px !important;
- white-space: pre-wrap !important;
- word-break: break-all !important;
- }
- a, a * {
- color: #0d6efd !important;
- }
- blockquote, blockquote * {
- color: #555555 !important;
- border-left: 4px solid #ccc !important;
- padding-left: 10px !important;
- }
- table, tr, td, th, table * {
- color: #1a1a1a !important;
- border-color: #cccccc !important;
- }
- th {
- background-color: #f2f2f2 !important;
- }
- ul, li {
- list-style-type: disc !important;
- }
- """
- pdf = MarkdownPdf()
- section = Section(md_content, paper_size="A4", root=docs_dir)
- pdf.add_section(section, user_css=user_css)
- pdf.save("scratch/test_css_on.pdf")
- doc = fitz.open("scratch/test_css_on.pdf")
- print("Total pages:", len(doc))
- for i in range(len(doc)):
- txt = doc[i].get_text()
- print(f"Page {i+1} text length: {len(txt)}")
- if i == 1:
- print("--- PAGE 2 TEXT CONTENT ---")
- print(txt.replace("\ufb01", "fi"))
- doc.close()
|