question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

it seems images aren’t included in the resulting PDF file.

I put some images into my MD document, using inline span syntax (http://daringfireball.net/projects/markdown/syntax#img)

![Alt text](/path/to/img.jpg)

the resulting image shows in html file, which is an intermediate in your code

function markdownToPdfTask (filePath, opts) {
    ....
    var html = marked(data) // I checked temporal html contains valid <IMG> tags converted from above markdown

however, they’re just blank in the resulting PDF.

markdown-pdf test.md # test.pdf has no images

if I save the intermediate html and load it in chrome, they render correctly.

is there any solution for this? markdown-pdf produces very beautiful pdf files, and I really want to use them in my report generation.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
nickcmaynardcommented, Nov 21, 2014

@strk, here’s a solution I’ve hacked together using Cheerio:

var markdownpdf = require("markdown-pdf")
  , split = require("split")
  , through = require("through")
  , duplexer = require("duplexer")
var through = require('through');
var cheerio = require('cheerio');

// This should be where your .md file lives
var imgBasePath = __dirname + "/markdown/";
var preProcessHtml = function() {

    return through(function(data) {
        var $ = cheerio.load(data);

        $('img[src]').each(function(i, elem) {
            var path = $(this).attr('src');
            path = imgBasePath + path;
            $(this).attr('src', path);
        });

        this.queue($.html());
    });
};

markdownpdf({preProcessHtml: preProcessHtml})
  .from("/path/to/document.md")
  .to("/path/to/document.pdf", function () { console.log("Done") })

It’s certainly not a cure-all - I’d like to see this in markdown-pdf natively - but it might get you out of a bind.

2reactions
pbattissoncommented, Oct 16, 2013

We have also had this same issue and the resolution is to put the full path to the image in the file not just to relative local path - e.g. /Users/Bob/docs/images/myImg.jpg not just images/myImg.jpg.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Images
Google Images. The most comprehensive image search on the web.
Read more >
Images - Google
Send feedback. AllImages · Sign in. Videos. Double-tap to search Google. REPORT THIS. CANCEL. OK. DELETE. Settings · Search settings · Advanced search....
Read more >
Unsplash: Beautiful Free Images & Pictures
Beautiful, free images and photos that you can download and use for any project. Better than any royalty free or stock photos.
Read more >
Image - Wikipedia
An image is a visual representation of something. It can be two-dimensional, three-dimensional, or somehow otherwise feed into the visual system to convey ......
Read more >
2.7 million+ Stunning Free Images to Use Anywhere - Pixabay ...
Find your perfect free image or video to download and use for anything. ✓ Free for commercial use ✓ No attribution required ✓...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found