normanlorrain / mdpdf Goto Github PK
View Code? Open in Web Editor NEWPython command line application to convert Markdown to PDF.
License: MIT License
Python command line application to convert Markdown to PDF.
License: MIT License
Is there a way to render md tables in the pdf?
Hey @normanlorrain,
Thanks for this great package!
I just realized that the meta data is hard coded.
Lines 7 to 15 in 234158c
One improvement could be to set the meta data in cli or leave it empty, as not everyone wants to have the tile "title goes here" ๐
The paper size is hard coded as well, which some might find useful to change.
Line 18 in 0cb8d30
If you don't have the time for it, I'll make a pull request but it might take quite a while before I find time to dive into your code.
Thank you for your script
i need little help about your script
can you help in script where i can change those setting
thank you
I'm trying to run a simple conversion and I get this error:
$ mdpdf Process-Book.md -o process-book.pdf
Traceback (most recent call last):
File "/home/ben/.local/bin/mdpdf", line 8, in <module>
sys.exit(cli())
File "/usr/lib/python3/dist-packages/click/core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python3/dist-packages/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/usr/lib/python3/dist-packages/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/home/ben/.local/lib/python3.10/site-packages/mdpdf/cli.py", line 110, in cli
converter.convert(globlist)
File "/home/ben/.local/lib/python3.10/site-packages/mdpdf/converter.py", line 18, in convert
self.renderer.render(ast, inputFile)
File "/home/ben/.local/lib/python3.10/site-packages/mdpdf/pdf_renderer.py", line 73, in render
getattr(self, node.t)(node, entering)
File "/home/ben/.local/lib/python3.10/site-packages/mdpdf/pdf_renderer.py", line 492, in document
self.currentPage = self.doc.newPage(-1, width, height)
AttributeError: 'Document' object has no attribute 'newPage'. Did you mean: '_newPage'?
Exception ignored in: <function PdfRenderer.__del__ at 0x7ff1b30a9fc0>
Traceback (most recent call last):
File "/home/ben/.local/lib/python3.10/site-packages/mdpdf/pdf_renderer.py", line 51, in __del__
if self.doc.pageCount:
AttributeError: 'Document' object has no attribute 'pageCount'
I'm using Python 3.10.6
It seems README only mentions cli usage, this should only be a complement not the main way of using it.
Something wrong when insert svg images into the pdf, cause svg images have no exactly height and width.
Any suggestion?
To support GitHub flavoured markdown (along with #1), it would be nice to allow for relative links within the document. As a temporary solution, currently I'm changing them in the md file to web URLs using regex, and then passing it to mdpdf. Using sed:
#!/bin/bash
sed -i -e -r "s/(#[^ ][^\)]*)\)/https:\/\/example.org\/dir\1\)/g" file.md &
mdpdf -o file.pdf file.md
which finds bits such as #example-relative-link)
and replaces them with https://example.org/dir#example-relative-link)
Hi Norman and thanks for this awesome tool!
I'm having problems with converting images im my MD-File. Baically as soon as i add my header image, the script fails without a clear error message and an empty PDF is generated. Since the package description states images are supported i was wondering if you could point me in the right direction. Do you have an idea how to fix it?
Python Script
import os
import mdpdf.cli as cli
from click.testing import CliRunner, Result
if os.path.exists("output.pdf"):
os.remove("output.pdf")
runner: CliRunner = CliRunner()
result: Result = runner.invoke(cli.cli, ["-o", "output.pdf", "output.md"])
MD File (utf-8)
Page Title
![](https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png)
# Subtitle H1
Some Text lorem ipsum
Log file
INFO: 2021-02-09 13:12:51,972: log.py: 20: Logging to C:\Users\[...]\mdpdf.log
DEBUG: 2021-02-09 13:12:51,972: cli.py: 72: output.md
INFO: 2021-02-09 13:12:51,972: converter.py: 16: output.md
DEBUG: 2021-02-09 13:12:51,972: pdf_renderer.py: 446: printSegment: Page Title
Examples:
.. image:: https://img.shields.io/pypi/v/mdpdf.svg
:target: https://pypi.python.org/pypi/mdpdf
.. image:: https://img.shields.io/travis/normanlorrain/mdpdf.svg
:target: https://travis-ci.org/normanlorrain/mdpdf
.. image:: https://readthedocs.org/projects/mdpdf/badge/?version=latest
:target: https://mdpdf.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
All Chinese chars turn into "."
Link text, if broken, only shows up as the first segment. See pdf_renderer.py, line 176: filename=node.first_child.literal,
A function should grab all the child text literals.
Hi, I am not sure if it is typeface problem (?) or somewhat deeper one, but some of Czech letters, to name "ฤฤ" are not rendered in resulting PDF (all default settings).. all encodings seems to be right in the source document. Thanks for any clue.
https://docs.python.org/3/library/imghdr.html (deprecated; good until Python 3.13)
filetype:
https://pypi.org/project/filetype/#supported-types
Rationale:
we need to determine the size of images.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.