Skip to content

Instantly share code, notes, and snippets.

@shivangipokhriyal
Last active July 16, 2025 15:05
Show Gist options
  • Save shivangipokhriyal/709bcaf6a16e2573bf41df3a3163caa7 to your computer and use it in GitHub Desktop.
Save shivangipokhriyal/709bcaf6a16e2573bf41df3a3163caa7 to your computer and use it in GitHub Desktop.
Python File Structure
annotations=[
dict(
text="Note: Deviation calculated as (PDS - SilverCnf) / PDS",
showarrow=False,
xref='paper', yref='paper',
x=0, y=-0.2, # Position below chart
xanchor='left',
font=dict(size=10, color="gray")
)
]
@shivangipokhriyal
Copy link
Author

import mammoth
import pdfkit

def docx_to_pdf(input_docx, output_pdf):
# Convert DOCX to HTML string
with open(input_docx, "rb") as docx_file:
result = mammoth.convert_to_html(docx_file)
html = result.value # The generated HTML

# Convert HTML string to PDF
pdfkit.from_string(html, output_pdf)

Example usage:

docx_to_pdf("example.docx", "output.pdf")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment