Commit b5cbec2c authored by Bogdan Vacaliuc's avatar Bogdan Vacaliuc
Browse files

Claude created a set of tools to work with pdf files for itself

parent 627954d5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
3.13

pdf-tools/README.md

0 → 100644
+0 −0

Empty file added.

pdf-tools/main.py

0 → 100644
+6 −0
Original line number Diff line number Diff line
def main():
    print("Hello from pdf-tools!")


if __name__ == "__main__":
    main()

pdf-tools/md2pdf.py

0 → 100644
+124 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
"""Convert a Markdown file to PDF using markdown2 + weasyprint."""

import sys
import markdown2
from weasyprint import HTML

CSS = """
@page {
    size: letter;
    margin: 1in 0.75in;
    @bottom-center {
        content: "Page " counter(page) " of " counter(pages);
        font-size: 9pt;
        color: #666;
    }
}
body {
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 11pt;
    line-height: 1.5;
    color: #222;
}
h1 {
    font-size: 18pt;
    border-bottom: 2px solid #333;
    padding-bottom: 6pt;
    margin-top: 0;
}
h2 {
    font-size: 14pt;
    border-bottom: 1px solid #999;
    padding-bottom: 4pt;
    margin-top: 20pt;
}
h3 {
    font-size: 12pt;
    margin-top: 16pt;
}
table {
    border-collapse: collapse;
    width: 100%;
    margin: 12pt 0;
    font-size: 10pt;
}
th, td {
    border: 1px solid #aaa;
    padding: 4pt 8pt;
    text-align: left;
}
th {
    background-color: #e8e8e8;
    font-weight: bold;
}
tr:nth-child(even) {
    background-color: #f6f6f6;
}
code {
    font-family: "Courier New", Courier, monospace;
    font-size: 9.5pt;
    background-color: #f0f0f0;
    padding: 1pt 3pt;
    border-radius: 2pt;
}
pre {
    background-color: #f0f0f0;
    padding: 8pt 12pt;
    border-radius: 4pt;
    border: 1px solid #ddd;
    overflow-x: auto;
    font-size: 9pt;
    line-height: 1.4;
}
pre code {
    background-color: transparent;
    padding: 0;
}
blockquote {
    border-left: 3pt solid #ccc;
    padding-left: 12pt;
    color: #555;
    margin-left: 0;
}
strong {
    color: #111;
}
hr {
    border: none;
    border-top: 1px solid #ccc;
    margin: 16pt 0;
}
"""


def main():
    if len(sys.argv) < 3:
        print(f"Usage: {sys.argv[0]} input.md output.pdf")
        sys.exit(1)

    md_path = sys.argv[1]
    pdf_path = sys.argv[2]

    with open(md_path, "r") as f:
        md_text = f.read()

    html_body = markdown2.markdown(
        md_text,
        extras=["tables", "fenced-code-blocks", "code-friendly", "header-ids"],
    )

    full_html = f"""<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<style>{CSS}</style>
</head><body>
{html_body}
</body></html>"""

    HTML(string=full_html).write_pdf(pdf_path)
    print(f"Written: {pdf_path}")


if __name__ == "__main__":
    main()
+11 −0
Original line number Diff line number Diff line
[project]
name = "pdf-tools"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
    "markdown2>=2.5.5",
    "pymupdf>=1.27.2.2",
    "weasyprint>=68.1",
]
Loading