Git Product home page Git Product logo

mdpdf's Introduction

MDPDF - Markdown to PDF converter

NPM version code style: prettier

A command line markdown to pdf converter with support for page headers, footers, and custom stylesheets. Mdpdf is incredibly configurable and has a JavaScript API for more extravogant usage.

For examples of how to use headers and footers, see the examples directory.

If you're using the Atom text editor, checkout the markdown-pdf plugin which uses mdpdf.

Sponsor this project

This project is actively maintained during evenings and weekends. If you or your company find it useful, please consider supporting the project through sponsorship.

Contributions

If you wish to report bugs or contribute fixes and features, please see the contributors guide

Installation

Install globally to use from the command line.

npm install mdpdf -g

Install locally to access the API.

npm install mdpdf --save

Example usage

  • mdpdf README.md - Simple convert using GitHub Markdown CSS and some additional basic stylings.
  • mdpdf README.md --style styles.css --header header.hbs --h-height 22 - Convert with custom styling with a header of height 22mm.

Options

  • --style=<filename> - A single css stylesheet you wish to apply to the PDF
  • --header=<filename> - A HTML (.html) file to inject into the header of the PDF
  • --h-height=<height> - The height of the header section
  • --footer=<filename> - A HTML (.html) file to inject into the footer of the PDF
  • --f-height=<height> - The height of the footer section
  • --border=<size> - Border value for all sides (top, left, bottom, right; default: 20mm)
  • --border-top=<size> - Top border (default: 20mm)
  • --border-left=<size> - Left border (default: 20mm)
  • --border-bottom=<size> - Bottom border (default: 20mm)
  • --border-right=<size> - Right border (default: 20mm)
  • --gh-style - Enable default gh-styles, when --style is used
  • --no-emoji - Disables emoji conversions
  • --debug - Save the generated html for debugging
  • --help - Display this menu
  • --version - Display the application version
  • --format=<format> - PDF size format: A3, A4, A5, Legal, Letter, Tabloid (Default: A4)
  • --orientation=<orientation> - PDF orientation: portrait or landscape (Default: portrait)

Length parameters (<height> and <size>) require a unit. Valid units are mm, cm, in and px.

Headers and footers

Mdpdf is powered by Puppeteer, the headless Chrome browser project by Google. Puppeteer provides a number of header and footer html classes which can be used to insert things such as page numbers.

Note: mdpdf pre-2.x made use of Phantom.js which had considerably better support for headers and footers, and including better styling support for them. Sadly Phantom.js is no longer supported and had a number of other rendering bugs meaning it was no longer possible to support it as a core component of mdpdf. If you previously relied on good header and footer support you may wish to stick with 1.x releases until Puppeteer prioritises better header and footer support. Currently headers and footers do work in 2.x+ releases, but their styles must be handled independently of the main markdown file via --styles options and a few css tags do not work correctly. Past this there shouldn't be any issues with 2.x+ headers and footers.

Environment variables

  • MDPDF_STYLES - The full path to a stylesheet you wish to use if --style is not specified when calling mdpdf from the command line.

Emoji support

In text emoji's are also supported, but there are a few instances of shorthand which do not work and require the longhand version, i.e. :+1: doesn't work but :thumbsup: will.

Programatic API

The API is very straight forward with a single function convert() which takes some options. The convert method uses a promise. For a full example see the bin/index.js!

Example API usage

const mdpdf = require('mdpdf');
const path = require('path');

let options = {
    source: path.join(__dirname, 'README.md'),
    destination: path.join(__dirname, 'output.pdf'),
    styles: path.join(__dirname, 'md-styles.css'),
    pdf: {
        format: 'A4',
        orientation: 'portrait'
    }
};

mdpdf.convert(options).then((pdfPath) => {
    console.log('PDF Path:', pdfPath);
}).catch((err) => {
    console.error(err);
});

Options

  • source (required) - Full path to the source markdown file.
  • destination (required) - Full path to the destination (pdf) file.
  • styles - Full path to a single css stylesheet which is applied last to the PDF.
  • ghStyle - Boolean value of whether or not to use the GitHub Markdown CSS, defaults to false.
  • defaultStyle - Boolean value of whether or not to use the additional default styles. These styles provide some things like a basic border and font size. Defaults to false.
  • header - Full path to a the Handlebars (.hbs) file which will be your header. If you set this, you must set the header height (see below).
  • debug - An optional path that can be set to cause the intermediate HTML to be saved to a the desired path.
  • pdf (required) - An object which contains some sub parameters to control the final PDF document
    • format (required) - Final document format, allowed values are "A3, A4, A5, Legal, Letter, Tabloid"
    • orientation - Final document size orientation, allowed values are "potrait, orientation"
    • header - A sub object which contains some header settings
      • height - Height of the documents header in mm (default 45mm). If you wish to use a header, then this must be set.
    • border - The document borders

Docker Usage

To build the Docker image for mdpdf, use the following command:

docker build -t mdpdf .

To run mdpdf within a Docker container, you can use the following command. This example mounts the current directory to the /app directory inside the container and converts example.md to example.pdf:

docker run --rm -v $(pwd):/app mdpdf example.md

This allows you to use mdpdf without needing to install Node.js or any dependencies on your host machine, only Docker is required.

mdpdf's People

Contributors

afgrant avatar bluehatbrit avatar csingewald avatar cuschk avatar dependabot[bot] avatar dosaki avatar elliotblackburn avatar jbeurel avatar jooola avatar kito-inv avatar martindelille avatar mrf345 avatar ncpenke avatar nopeless avatar nwtgck avatar peterdavehello avatar rodrigobdz avatar stoe avatar travs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mdpdf's Issues

Cannot read property 'top' of undefined

Hi @BlueHatbRit,

I'm just trying to generate a PDF from a markdown file but I'm facing the issue mentioned in the title. I would like to make this work in a Typescript Node.js project (maybe this has something to do with it).

The related section of my code is:

case 'pdf':

    const mdpdf = require('mdpdf');

    const options = {
        source : 'c:\\wamp64\\www\\sandbox\\guide\\output\\New Document.md',
        destination : 'c:\\wamp64\\www\\sandbox\\guide\\output\\New Document.pdf',
        // styles : 'c:\\wamp64\\www\\sandbox\\guide\\css\\pdf.css',
        debug : true,
        ghStyle : true,
        pdf : {
            format : 'A4',
            orientation : 'portrait'
        }
    }

    mdpdf.convert(options)
    .then(
        (path: string) => {
            resolve(path);
        }
    )
    .catch(
        (error: any) => {
            reject(error);
        }
    )
break;

With the debug option enabled I can see the temporary HTML file, but for some reason the PDF is not generated. The exact error message I get:

TypeError: Cannot read property 'top' of undefined
    at Object.getOptions (C:\wamp64\www\sandbox\guide\node_modules\mdpdf\src\puppeteer-helper.js:13:31)
    at writeFile.then.then.then.then (C:\wamp64\www\sandbox\guide\node_modules\mdpdf\src\index.js:190:45)
    at tryCatcher (C:\wamp64\www\sandbox\guide\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\wamp64\www\sandbox\guide\node_modules\bluebird\js\release\promise.js:512:31)
    at Promise._settlePromise (C:\wamp64\www\sandbox\guide\node_modules\bluebird\js\release\promise.js:569:18)
    at Promise._settlePromise0 (C:\wamp64\www\sandbox\guide\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (C:\wamp64\www\sandbox\guide\node_modules\bluebird\js\release\promise.js:694:18)
    at _drainQueueStep (C:\wamp64\www\sandbox\guide\node_modules\bluebird\js\release\async.js:138:12)
    at _drainQueue (C:\wamp64\www\sandbox\guide\node_modules\bluebird\js\release\async.js:131:9)
    at Async._drainQueues (C:\wamp64\www\sandbox\guide\node_modules\bluebird\js\release\async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\wamp64\www\sandbox\guide\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:120:23)

Can you take a look?

Thanks!

Tables truncated in weird way

Create a markdown with a wide-ish table. Convert to PDF. The PDF gets cut off at the sides of the page. There is a horizontal scroll bar visible in the PDF (which you cant use).

The "path" argument must be one of type string, Buffer, or URL. Received type boolean

Hi @BlueHatbRit,

I was trying to generate a PDF file with your module with the programmatic API and I would like to keep the generated temporary HTML file (passed the debug: true to the options object). When the program is executed I get the error message mentioned in the title. I was using the following code (this example code is from the README):

const mdpdf = require('mdpdf');
const path = require('path');

let options = {
    source: path.join(__dirname, 'README.md'),
    destination: path.join(__dirname, 'output.pdf'),
    debug: true,
    pdf: {
        border : {
            top: "20mm",
            left: "20mm",
            right: "20mm",
            bottom: "20mm"
        },
        format: 'A4',
        orientation: 'portrait'
    }
};

mdpdf.convert(options).then((pdfPath) => {
    console.log('PDF Path:', pdfPath);
}).catch((err) => {
    console.error(err);
});

This is the full output of the program:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type boolean
    at Object.open (fs.js:408:3)
    at WriteStream.open (internal/fs/streams.js:267:12)
    at new WriteStream (internal/fs/streams.js:254:10)
    at Object.createWriteStream (fs.js:1731:10)
    at writeFile.then.then.then.then.then.then (C:\wamp64\www\pdf\node_modules\mdpdf\src\index.js:199:51)
    at tryCatcher (C:\wamp64\www\pdf\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\wamp64\www\pdf\node_modules\bluebird\js\release\promise.js:512:31)
    at Promise._settlePromise (C:\wamp64\www\pdf\node_modules\bluebird\js\release\promise.js:569:18)
    at Promise._settlePromise0 (C:\wamp64\www\pdf\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (C:\wamp64\www\pdf\node_modules\bluebird\js\release\promise.js:694:18)
    at _drainQueueStep (C:\wamp64\www\pdf\node_modules\bluebird\js\release\async.js:138:12)
    at _drainQueue (C:\wamp64\www\pdf\node_modules\bluebird\js\release\async.js:131:9)
    at Async._drainQueues (C:\wamp64\www\pdf\node_modules\bluebird\js\release\async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\wamp64\www\pdf\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)

Despite of the error message, every file is generated (even the _temp.html)

Project Folder Screenshot

Can you take a look?

Thanks!

Incorrect conversion of numbered list

Tried converting the following file:
https://raw.githubusercontent.com/laboon/CS1530_Fall2017/master/reading-quizzes/quiz4.md

using the command line tool. The file has a numbered list

1. item one
2. item two
3. item three

but the converted pdf does not convert the list correctly. Instead it looks like:

1. item one
1. item two
1. item three

Attached an example. I'd be willing to look at it when I have a chance but wanted to document this behavior first. This behavior appeared in the debug html as well.

quiz4.pdf

Tests running too slow

It seems the integration tests are running way too slow. Even Travis isn't keeping up most of the time with the increased timeout.

We should think of a way to speed them up.

Find a way to test PDF content

It would be amazing if we could test the validity of an output PDF in our test suite. I don't know much about the PDF spec (though I'm learning more every day).

If anyone has any idea how we might compare a PDF to the markdown used to generate it, I'd be really interested to hear suggestions or see a sample in a PR. Even just testing the words of simple markdown file with no header or footer.

[Suggestion] Add a Dockerfile to the project

I have created a Docker image to avoid installing node and the dependencies:

FROM node:8.11.1
RUN npm i -g phantomjs-prebuilt --unsafe-perm --silent
RUN npm install mdpdf -g

To use it, I setup an alias like this one:
alias mdpdf="docker run --rm -it -w /data -v $(pwd):/data enric1994/mdpdf mdpdf"

Then, I run: mdpdf README.md

Hope it help,

Enric

Table of contents support

Hey!
First of all, thanks for this amazing tool, just what I've been needing for a very long time.
So question, is there any way to add an auto-generated Table of Contents e.g. the [TOC] markup/macro that's isn't really standard markdown but can be found supported in a few implementations.

00:00:00 rendered as 00[]00

Hey! I'm using ubuntu, so I imagine the [] is supposed to be an emoji, but it's still not the intended outcome. Any chance of giving an ignore emoji option? Cheers !!

By the way. This is the best md to pdf CLI software out there. Gets the job done, quickly and efficiently. Thank you for this :)

Support for styling of .MD structure?

Hello.

I like the way you add a header and footer in this style. I need my outputed .pdf to have a standardized feel to it so I can use it between multiple documents.

I would like however to have more control over the standard .MD structure styling.

For instance, in MD I have:

My header

My sub header

I would in the example above like to set both these headers to be color blue.
I would also like to set the sub header to be italic.
I would also like to change font maybe?

Is there any support for this kind of styling?

I don't want to put html div tags into the .md file. I want a nicely readable .md file at the same time as a more custom looking .pdf file

/usr/local/bin/mdpdf uses CRLF linebreaks

When installing mdpdf via:

# npm install mdpdf -g --unsafe-perm=true

on Ubuntu 18.04 LTS with NPM version 3.5.2 I receive the following error when I attempt to execute mdpdf:

$ mdpdf
/usr/bin/env: ‘node\r’: No such file or directory

As it turns out the script under /usr/local/bin/mdpdf uses CRLF linebreaks. Changing it to LF in an editor, such as Atom, fixes this issue.

Oddly, this issue does not occur when installing mdpdf from source.

cant install in debian stretch

running:
~$ sudo npm install mdpdf -g
outputs:

/usr/bin/mdpdf -> /usr/lib/node_modules/mdpdf/bin/index.js

> [email protected] install /usr/lib/node_modules/mdpdf/node_modules/puppeteer
> node install.js

ERROR: Failed to download Chromium r656675! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
{ Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/mdpdf/node_modules/puppeteer/.local-chromium'
  -- ASYNC --
    at BrowserFetcher.<anonymous> (/usr/lib/node_modules/mdpdf/node_modules/puppeteer/lib/helper.js:110:27)
    at Object.<anonymous> (/usr/lib/node_modules/mdpdf/node_modules/puppeteer/install.js:64:16)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path:
   '/usr/lib/node_modules/mdpdf/node_modules/puppeteer/.local-chromium' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-05-15T16_31_30_544Z-debug.log

HTML tags in the markdown source are closed in the generated HTML

If someone has an HTML tag in their markdown, like

   <span class=ContactListTable>
        something
        something else
    </span>

in the generated HTML the tag is weirdly and obviously incorrectly automatically closed !

   <p><span class="ContactListTable"></span></p>
        something   // class attributes not applied;;
        something   // class attributes not applied;;

and the correct is removed

In mdpdf, the showdown library is used to create the intermediate HTML. In the showdown library documentation https://github.com/showdownjs/showdown/wiki/Showdown's-Markdown-syntax#handling-html-in-markdown-documents it says

Showdown, in most cases, leaves HTML tags alone, leaving them untouched in the output document.

However, in the mdpdf output, tags have been moved and closed.

Note: tags are also closed if markdown=1 is added to the HTML tag in the markdown.

Why? Why oh why?

Messed-up Kerning on Windows

No matter which stylesheet or font I'm using, the PDF shows up with completely messed up kerning. Some letters are too far apart, some are too close together, and that regularly happens within a single word. The letter sequences closer together seem to be the same ones throughout the document. Explicitly setting letter-spacing: 0 has no effect.

"Failed to download Chromium r609904!" when installing

sudo npm install mdpdf -g
/usr/local/bin/mdpdf -> /usr/local/lib/node_modules/mdpdf/bin/index.js

> [email protected] install /usr/local/lib/node_modules/mdpdf/node_modules/puppeteer
> node install.js

ERROR: Failed to download Chromium r609904! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
{ [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/mdpdf/node_modules/puppeteer/.local-chromium']
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path:
   '/usr/local/lib/node_modules/mdpdf/node_modules/puppeteer/.local-chromium' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Add some base unit tests

We've got a collection of small functions which are used in the conversion pipeline. It would be useful to have some unit tests around these. Some good candidates to unit test first would be.

  • processSrc - Takes in any image source and spits out an absolute file path with a prepended protocol.
  • qualifyImgSources - Takes in some HTML, if there are any <img> tags, it runs them through processSrc to ensure the correct src formats.
  • parseMarkdownToHtml - Uses showdown to parse some markdown into HTML. Might be worth unit testing this to say what we want as valid markdown and what we want to ignore perhaps?
  • getCssAsHtml - Takes an array of file paths to CSS documents, reads the documents and puts each into <style> tags. Then returns one string containing them all. The order in which this processes the css is important to the final rendering. In our case we go from index 0 up.
  • getAllStyles - Returns an array of stylesheet file paths dependant on the options the user has passed in. Because this is passed into getCssAsHtml, it must have a specific order to the array as well as the first file (index 0) will be further up the cascading styles.

It might also be worth having a few integration tests to try and test the entire application. This would however require some thought as to how we check the final PDF. Perhaps we start simple first and just make sure it outputs a PDF?

Migrate away from Phantom based rendering to Puppeteer

Chrome's Puppeteer project finally accepts the full parameters we need to support headers and footers in pdfs. This means we should be able to make the move over to puppeteer at last.

This will require creating a shim for Puppeteer and ensuring we can accept all the current parameters without breaking the API too much.

This should also fix many of the rendering issues we've seen but not had control over. We still won't have much control over them, but Chrome is much more reliable with it's PDF rendering.

Issues this should address:
#38, #36, and potentially may open the door for #12 and #31.

handlebars (subsititutions) does not work at all

If test.md is: test.md

# This is Heading 1 (one)

This is the body

and test_header.hbs is test_header.hbs

  blah {{h1}} {{.markdown-body h1}} {{body}} foo 

and then someone runs

   mdpdf test.md --header=test_header.hbs  --h-height=40px --debug

The resultant pdf is test.pdf. The handlebars subsitutions are not working at all.

Handlebars is installed and checked.

Paragraph Breaking

Using version 1.7

mdpdf is treating separate lines in the markdown input as separate paragraphs. Lines of text that are not separated by a blank line should be treated as forming part of the same paragraph, according to the spec. New paragraphs should start after a blank line.

Phantom.js missing

Hi,

I had to install the phantomjs-prebuilt package manually. Probably i'ts missing in the dependencies.

Bye

Styles seem to not be applied when using js API

Styles are applied when using the cli, as in mdpdf sample.md --style=sample.css, but seem not to be applied when doing the same via the js API.

Sample:

await mdpdf.convert({source: './sample.md', destination: './sample.pdf', styles: './sample.css'})

sample.md

sample.css

Actual output pdf

Expected output pdf

High chance it is me doing something wrong, since I looked at your code and not sure where this could happen.

Discovered when investigating this

custom CSS on top of default CSS

It is possible to use your own CSS.
Current situation: custom CSS replaces default CSS, see #13
Would be great if there can be an option to use the custom CSS on top of the default CSS.

Until then I use the workaround: dowload the default CSS file and modify it.

Make first argument source by default

I don't know how easy this is (I guess it depends on how the arguments are parsed) but I think it would be convenient to have the first argument always be the .md file to be converted.

So something like:

mdpdf --source thing.md <other options>

Would become:

mdpdf thing.md <other options>

I'd be happy to investigate, develop it and make a pull request if this idea were welcomed.

Problems with linked images in resulting pdf file

I was testing with images like described here https://docs.gitlab.com/ee/user/markdown.html#images

I have an md file with an img/markdown_logo.png

md file:
![alt text](img/markdown_logo.png)
Opening md file in Typora looks perfect.

resulting html file:
<img src="file://C:\test\img\markdown_logo.png" alt="alt text">
Opening html file in Chrome - it lost it's centering of the image (but that can be fixed via .css)

PDF file however loses the image and instead just displays "alt text".

Would like the html-to-pdf conversion to embed images. Possible?

Specifying highlight.js theme?

Hi there! Just stumbled across this and I really dig what mdpdf can do so far.

Is there a way to modify the default highlight.js styles?

I've played around with manually overriding CSS (aka, .markdown-body .highlight pre) which works fine, but I'd love to be able to switch hljs themes without manual CSS.

I didn't see anything in the documentation though I do see some closed issues around highlighting, but nothing regarding switching styles.

Single --border option?

Maybe a single --border=<size> flag would be useful for situations where you just want an equal border without having to specify all 4 options?

Also, maybe have shorter options like -b in this case for example…

Resolving images from API and from command working differently.

@BlueHatbRit Hello, I found another issue, that's related to images resolving.
If I run mdpfd from command line, converting completes successfully, but if I call from API "mdpdf.convert(options)" . I'm getting an exception "TypeError: Path must be a string. Received undefined" on resolving image path to URL. Can you try figure out whats wrong?

Error rendering pictures to the PDF

After running mdpdf README.md, the pictures appear as interrogation signs.
I am using this syntax in the Markdown file: ![Alt text](/reports/figures/demo.png)

Any advice?

Thanks!

Option --no-emoji not working

Hi,

I have the issue that in the code section of a document there are several :x: which are converted to emojis.

For one thing, I was surprised that emoji-conversion takes place in pre-formatted text ... I would not expect that. Anyway, when I tried to switch off the conversion with '--no-emoji', the conversion still happens.

Any idea on how to disable the conversion?

Thanks a lot,
Josef

Not all emojis are displayed correctly

Hey! I'm currently working on some markdown that contains emojis and some of them are not displayed in the resulting pdf. Here's a case to reproduce it.

I take this markdown:

:thumbsup:
:ledger:

Convert it width mdpdf test.md --debug.

And as a result the thumbsup emoji is displayed, but the ledger is not.

Here's how the debug html looks like:

        <p><img src="https://github.global.ssl.fastly.net/images/icons/emoji/thumbsup.png?v5" alt=":thumbsup:" title=":thumbsup:" class="emoji-img emoji"><br>
&#x1F4D2;</p>

Am I missing something here? I've briefly looked in your code and found that you're using a library to convert emojis to images, but for some reason this does not happen for the 📒 emoji.

Words with 'w' in the middle add extra spaces

I'm running into an issue where converting a file to PDF is adding spaces next to all of my lowercase w's in the middle of words. It seems to generally be only within the main text. It just looks pretty bad when I want to share this with others at work. I'm running this on a Windows 10 machine.

Also, I'm using Markdown-to-PDF in Atom. There is already a bug reported there for this, but it looks like the problem is in the conversion.

test.pdf

What it should look like:

here is my file with some w's in places

What? where? how? how now brown cow?

wa wb wc wd we wf wg wh wi wj wk wl wm wn wo wp
wq wr ws wt wu wv wx wy wz w!!!w!


Here's the text inside it (added monospacing to preserve all characters)

# here is my file with some w's in places

What? where? how? how now brown cow?

wa wb wc wd we wf wg wh wi wj wk wl wm wn wo wp
wq wr ws wt wu wv wx wy wz w!!!w!

Header images not resolving

@Stranger-Ok has reported that header images are not being resolved correctly. It seems the image resolving code is running before the header and footers are being injected into the layout.

Support for custom page numbers

I'm trying to generate a PDF with the intro pages numbered i ... iv, and the 5th page starting at 1.

In the README it's stated that Puppeteer has considerably less support for header and footer styling, and I can't find anything that would indicate control over manipulating the page numbers directly. This thread seems to point to arbitrary Javascript being executed within the context of the header file, but I can't get it to run and I'm not sure how I'd leverage the page content to indicate which page number to display.

Is this a no go until Puppeteer introduces better header support? Or have others found a workaround for this issue?

Error creating PDF's on Windows

Issue

When creating a PDF on windows, we get the following error:

Error: html-pdf: Evaluation - ReferenceError: Can't find variable: hljs
Stack:
  at undefined

    at ChildProcess.<anonymous> (E:\code\mdpdf\node_modules\html-pdf\lib\pdf.js:121:17)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)

Hypothesis

This seems to be due to the code on lines 8 and 9 in layout.hbs. According to the PhantomJS docs, evaluate() runs in a Sandbox which means it runs the main highlightJs script on line 8, and then for line 9 it has no reference to the variable hljs. This means we can't get syntax highlighting in our PDFs on Windows.

I've tried moving this snippet of code into the main highlightJs file and it seems fine on the HTML output but the PhantomJS isn't rendering any colouring. I'm not really sure what's going on here but it seems to be to do with PhantomJS so I'm going to begin narrowing it down and trying to remove mdpdf and html-pdf from the equation to see if the issue persists. If it is in PhantomJS then it would be good to try and patch it for them, we should at least submit a bug report.

The odd thing is this only happens on Windows, on OSX it seems fine. I don't have access to Linux to test it right now but I'll try it on a VM as soon as I can get to my laptop.

Next steps

A proper test to see if it's PhantomJS would be to create a small file HTML file with two script tags, the second one should make use of a declared variable from the first. This should then be pushed into PhantomJS and saved out as a PDF to see if it errors out on us.

Styles are not applied

Hi,

First of all, thank you for your amazing tool. I recently started using it and I noticed that whatever the CSS style sheet provided, the styles are not applied.

I am using a MacBook Pro and I installed mdpdf globally using the npm command line.

Best

How to create a footer with pagination

Hello,

Sorry if this question is obvious but I can't find how to create a footer (for example with an html files), that will contains the current page and the total page number, something like this:

Page {{pageNumber}} / {{totalPages}}

For example

Page 1/5

If I write this inside my html footer, it is rendered, in the PDF, as is...

Thanks by advance

Bold sections are not rendered as bold

Using node.js 9.11.2 on a MacBook Pro (MacOS Mojave), the following file does not render bold as bold.

This issue persists whether we use raw styles, github styles or even custom styles.

We have also tested with bold and bold and in each case the font remains normal.

font-size not respected in generated PDF

I'm using mdpdf to generate documents with a custom CSS stylesheet. In my CSS, I have

body {
    ...
    font-size: 20pt;
    ...
}

and I invoke mdpdf as follows:

$ mdpdf document.md --style styles.css

No matter what I do, the font-size in the rendered PDF stays the same (looks like 8pt or something). The body has the only font-size declaration so nothing is overriding it as far as I can tell. Is there any way to debug the process between .md import and .pdf export?

My mdpdf version is 2.0.2 and I am running Linux Ubuntu 18.04.

I need to check the rendering on my home computer, because it worked OK the last time I used it there.

Let me know if there is anything you want to know.

ReferenceError: path is not defined

Trying to run on Ubuntu 16:

ReferenceError: path is not defined
    at processSrc (/usr/local/lib/node_modules/mdpdf/src/utils.js:51:23)
    at Object.$.each (/usr/local/lib/node_modules/mdpdf/src/utils.js:59:23)
    at initialize.exports.each (/usr/local/lib/node_modules/mdpdf/node_modules/cheerio/lib/api/traversing.js:300:24)
    at Object.qualifyImgSources (/usr/local/lib/node_modules/mdpdf/src/utils.js:58:12)
    at prepareHeader.then.then.then.then.mdDoc (/usr/local/lib/node_modules/mdpdf/src/index.js:116:23)
    at tryCatcher (/usr/local/lib/node_modules/mdpdf/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/mdpdf/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/usr/local/lib/node_modules/mdpdf/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/usr/local/lib/node_modules/mdpdf/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/usr/local/lib/node_modules/mdpdf/node_modules/bluebird/js/release/promise.js:694:18)
    at Promise._fulfill (/usr/local/lib/node_modules/mdpdf/node_modules/bluebird/js/release/promise.js:638:18)
    at /usr/local/lib/node_modules/mdpdf/node_modules/bluebird/js/release/nodeback.js:42:21
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:54:3)

with node v11.8.0, npm 6.5.0

Create a substitution CLI / JS interface using Handlebars

As discussed in #55, it would be great to offer some sort of substitution interface since we already use Handlebars. This should be a sort of pre-process across the various input files (header, footer, and main md file).

Opening the floor to suggestions for the interface and implementation!

Command line support for GH style + custom styling

When using the command line, I'd like to be able to just add a small stylesheet to adjust the few things I want to correct from the default styling. Is there any support for this? I'm not seeing the right steps.

Syntax highlighting on windows

Referring back to #7, we ended up disabling syntax highlighting on Windows. This was a bi-product of correcting some exceptions.

It's still not clear why syntax highlighting is no longer working on Windows. If someone could track it down, it would be great!

How syntax highlighting works

We use hljs (highlight.js) which we include in all the code which is pushed into PhantomJS (headless browser). This should action syntax highlighting and it does in the debug HTML output, however for some reason under PhantomJS it's not rendering out the highlights in the final PDF save.

PhantomJS is a headless browser wrapped into a node module, it's used within the html-pdf package we use. It enables us to kick up a browser, push in the html, and get a PDF out afterwards as well as having some header and footer support we make use of.

Links always converted as external

I'm trying create table of contents (TOC) in md file. After conversion to pdf links are recognized as external links (link opened in web browser). What I need to do to make this link internal(just move to item that I specified)? I tried to create different types of links md and html, but all of them converted to external in pdf.
By the way in Chrome works properly, but Acrobat Reader and IE didn't works.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.