markdown-pdf icon indicating copy to clipboard operation
markdown-pdf copied to clipboard

Images not being shown in the runnings at all

Open neurobashing opened this issue 10 years ago • 10 comments

A possible variation on #43. I have a script that uses a running script thus:

exports.header = {
  height: '1in',
  contents: function(pageNum, numPages) {
    return '<img src="logo.jpg" height="39px" width="77px"><hr>';
  }
};

It shows a blank image in the header. I've tried absolute paths as well (/path/to/logo.jpg) and altering the height, to no avail. Like #43 I then included the image in the text. No image appears, just a blank rectangle.

Any other HTML fragment in the running - text of various styles, even tables - works, but no images.

neurobashing avatar Feb 11 '15 19:02 neurobashing

I would also like any information regarding this issue. If anyone as a solution, a fix or a workaround, you're welcome to share =)

astik avatar Oct 02 '15 13:10 astik

+1 I can't get images to work either. Same blank rectangle regardless of what path I use.

jasonb-vbt avatar Nov 11 '15 18:11 jasonb-vbt

+1 on this issues, any update on this? #43 workaround doesn't seem working for me.

louis-pvs avatar Sep 26 '16 01:09 louis-pvs

any solution my runnings is not working at all , not even text is coming

lokeshjain20 avatar Oct 16 '16 17:10 lokeshjain20

If you are using ubuntu, I've just reported a bug with their phantomjs build https://bugs.launchpad.net/ubuntu/+source/phantomjs/+bug/1676518 Use the phantomjs binary provided by website to fix the header/footer problem : http://phantomjs.org/download.html

xxorax avatar Mar 27 '17 17:03 xxorax

Still experiencing the same problem. unable to get the image in header & footer when header.contents returning from runnings.js. Anyone having luck in solving this issue.

PradyumnaR avatar Jun 22 '17 21:06 PradyumnaR

Copy pasting the runnings.js example and using text only does allow to let the text pop up, but images are indeed not there.

commjoen avatar Oct 12 '18 20:10 commjoen

@xxorax I just tried your suggestion, running on Ubuntu Bionic. When running your samples with the Ubuntu standard phantomjs, I receive two error messages:

TypeError: Attempting to change the setter of an unconfigurable property.
TypeError: Attempting to change the setter of an unconfigurable property.

The resulting output file does not have a footer.

When running with the binary downloaded from phantomjs.org, I don't see any errors and the output file has a footer.

So this is interesting and supports your understanding that something is wrong with the Ubuntu build of phantomjs 2.1.1.

However, at the same time the "official" version of phantomjs doesn't make any difference at all to the behavior in conjunction with markdown-pdf. Using the standard Ubuntu version, I can render headers and footers using runnings.js, and I don't get images rendered correctly in headers or footers. This behavior does not change at all when I use the --phantom-path option with the "official" phantomjs build.

oliversturm avatar Oct 23 '18 15:10 oliversturm

Anyone achieve add some header of footer without img? I can't add nothing. I've tried everything and I have to run this by node.

So, if everyone have and example with node adding a header to provide to me?

julioflima avatar Sep 14 '20 13:09 julioflima

Hi, guys. I have pass through this by reading the phantomJS documentation. The PDF is assembledy asynchronously so you need to provide a preloaded image you could do that by adding a tag on the template file with the display set to none with the same address to the file that will by used at the runnings files.

At index.html file:

<img style='display: none' src='data:image/jpeg;base64.....' />

At runnings.js file:

exports.header = { height: '1cm' contents: function (pageNum, numPages) { return '<img src='data:image/jpeg;base64.....' />' } }

I also have some trouble with some formats of image so and could be solved parsing the image to the image64, but you will not have this problem with use an image from google images. If they have the problem with the image format could by solved using the link below to obtain the url. https://stackoverflow.com/questions/934012/get-image-data-url-in-javascript

MelisseCabral avatar Sep 17 '20 20:09 MelisseCabral