All Projects → floppylab → Markdown2document

floppylab / Markdown2document

Licence: mit
turn markdown files to a PDF or HTML document

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Markdown2document

Minder
Mind-mapping application for Elementary OS
Stars: ✭ 306 (+1290.91%)
Mutual labels:  markdown, pdf
Markdown Resume Js
Turn a simple markdown document into a resume in HTML and PDF
Stars: ✭ 449 (+1940.91%)
Mutual labels:  markdown, pdf
Letter Boilerplate
Finest letter typesetting from the command line
Stars: ✭ 374 (+1600%)
Mutual labels:  markdown, pdf
Gotenberg
A Docker-powered stateless API for PDF files.
Stars: ✭ 3,272 (+14772.73%)
Mutual labels:  markdown, pdf
Md2pdf
Offline markdown to pdf, choose -> edit -> transform 🥂
Stars: ✭ 632 (+2772.73%)
Mutual labels:  markdown, pdf
Markdown Pdf
Convert markdown to pdf, png or jpeg on the fly in Atom
Stars: ✭ 250 (+1036.36%)
Mutual labels:  markdown, pdf
Crowbook
Converts books written in Markdown to HTML, LaTeX/PDF and EPUB
Stars: ✭ 399 (+1713.64%)
Mutual labels:  markdown, pdf
Markdownslides
MarkdownSlides is a Reveal.js and PDF slides generator from MARKDOWN files, that also generate HTML, EPUB and DOCX documents. The idea is that from a same MARKDOWN file we can get slides and books without worrying about style, just worrying about content.
Stars: ✭ 121 (+450%)
Mutual labels:  markdown, pdf
Vscode Markdown Pdf
Markdown converter for Visual Studio Code
Stars: ✭ 571 (+2495.45%)
Mutual labels:  markdown, pdf
Zettlr
A Markdown Editor for the 21st century.
Stars: ✭ 6,099 (+27622.73%)
Mutual labels:  markdown, pdf
Pandoc Book Template
A simple Pandoc template to build documents and ebooks.
Stars: ✭ 214 (+872.73%)
Mutual labels:  markdown, pdf
Recipes
Django application for managing recipes
Stars: ✭ 695 (+3059.09%)
Mutual labels:  markdown, pdf
Markdown Pdf
📄 Markdown to PDF converter
Stars: ✭ 2,365 (+10650%)
Mutual labels:  markdown, pdf
Pandoc Latex Template
A pandoc LaTeX template to convert markdown files to PDF or LaTeX.
Stars: ✭ 3,750 (+16945.45%)
Mutual labels:  markdown, pdf
Binb
Binb is not Beamer
Stars: ✭ 160 (+627.27%)
Mutual labels:  markdown, pdf
Md To Pdf
Hackable CLI tool for converting Markdown files to PDF using Node.js and headless Chrome.
Stars: ✭ 374 (+1600%)
Mutual labels:  markdown, pdf
Kramdown
kramdown is a fast, pure Ruby Markdown superset converter, using a strict syntax definition and supporting several common extensions.
Stars: ✭ 1,546 (+6927.27%)
Mutual labels:  markdown, pdf
React Antd Admin
后台前端管理系统,基于react、typescript、antd、dva及一些特别优秀的开源库实现
Stars: ✭ 117 (+431.82%)
Mutual labels:  markdown, pdf
Mdpdf
Markdown to PDF command line app with support for stylesheets
Stars: ✭ 512 (+2227.27%)
Mutual labels:  markdown, pdf
Backslide
💦 CLI tool for making HTML presentations with Remark.js using Markdown
Stars: ✭ 679 (+2986.36%)
Mutual labels:  markdown, pdf

Build Status License: MIT Dependabot Status

markdown2document

Turn markdown files to a PDF or HTML document with the help of this java library. You can also use CSS styles to format your documents.

1. How to use

1.1. As a library

First, you have to assemble a Document object. Then you use a Generator to generate you document.

There are currently two generators in the library:

  • PdfGenerator
  • HTMLGenerator

Both have a generate(Document document) method which returns an Output object.

Here is an example how to use is as a library:

ContentFactory contentFactory = ContentFactory.getInstance();

Document document = Document
        .builder()
        .markdownContents(Arrays.asList(
                contentFactory.create("# Sample header \n sample content "),
                contentFactory.create(new URL("https://floppylab.com/resources/markdown2document/sample.md"))
        ))
        .styles(Arrays.asList(
                contentFactory.create("body { font-family: sans-serif; color: #555; /* some comment*/ }"),
                new Link("https://floppylab.com/resources/markdown2document/sample.css")
        )).build();

PdfGenerator pdfGenerator = new PdfGenerator();
Output output = pdfGenerator.generate(document);
output.toFile("sample.pdf");

HtmlGenerator htmlGenerator = new HtmlGenerator();
output = htmlGenerator.generate(document);
output.toFile("sample.html");

1.1.1. Document

A document can consist of:

  • a list of markdown contents - List<Content> markdownContents
  • a list of style inputs - List<Input> styleInputs
  • base uri for relative links (images, links, etc) - String baseUri

1.1.2. Input

Input is an abstract class and there are two classes that extend it:

  • Content
  • Link
1.1.2.1. Content

A Content object can be constructed directly from:

  • String - as a text

But also can be constructed by ContentFactory from:

  • String - as a text
  • URL - url where the content can be found
  • Path - path to file with optional Charset
  • InputStream - stream with content
1.1.2.2. Link

A Link object can be constructed from:

  • String - link

1.1.3. Output

An Output object contains the contents of the generated document, and it has the following methods:

  • toString - returns the content as a String
  • toOutputStream - returns the content as an OutputStream
  • toFile(String name) - writes the content into a file with the given name (FileOutputStream is used)

1.2. As a command line tool

java -jar markdown2document-1.0.0.jar -h

java -jar markdown2document-1.0.0.jar -mc "# title","*italic text*" -pf "sample.pdf"

You can use it as a command line tool with the following options:

Markdown options

  • markdown contents

    • short: mc
    • long: markdown-contents
    • multiple values
  • markdown urls

    • short: mu
    • long: markdown-urls
    • multiple values
  • markdown file paths

    • short: mp
    • long: markdown-paths
    • multiple values

Styling options

  • style links

    • short: sl
    • long: style-links
    • multiple values
  • style contents

    • short: sc
    • long: style-contents
    • multiple values
  • style urls

    • short: su
    • long: style-urls
    • multiple values
  • style paths

    • short: sp
    • long: style-paths
    • multiple values

Base uri

  • base uri
    • short: bu
    • long: base-uri

Output options

  • to pdf file with filename

    • short: pf
    • long: to-pdf
  • to html file with filename

    • short: hf
    • long: to-html
  • to html string

    • short: hs
    • long: to-html-string

Help

  • help
    • short: h
    • long: help

2. Credits

This library is based on a few other libraries so credit goes to the contributors of these projects.

CommonMark

The library uses CommonMark to parse the markdown input contents.

Learn more about it here:

commonmark-java

commonmark-java is a Java library for parsing and rendering Markdown text according to the CommonMark specification by Atlassian.

Check the project on GitHub.

openhtmltopdf

openhtmltopdf is an HTML to PDF library for the JVM.

Check the project on GitHub.

3. Contribution

Please see CONTRIBUTING.md file for details.

4. Postcards

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our project(s) you are using.

Our address is: Gedőci utca 25., 3100 Salgótarján, Hungary.

We publish all received postcards on our website.

5. License

The MIT License (MIT). Please see LICENSE file for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].