-1

I am converting html to pdf using jspdf library. i am facing two problems.

  1. When i am using pagesplit: true ,it splits the page but the problem is half of data in li remains in first page and half comes in second page and so on. 2.in my image tag src link is not contains extension. It fetchs from url. For eg:"http://pics.redblue.de/doi/pixelboxx-mss-55590672/fee_786_587_png", but in pdf image not displaying. If i pass src link ends with extension it is displaying in pdf.But i am using not extension format. I searched much for both but didn't find any solution. Please help me ... Thanks in advance
MDS
  • 3
  • 3
  • Please add the code that you are experiencing problems with. As a new user, you may want to read the introductory [tour] some time. – Jongware Jan 20 '17 at 09:25

2 Answers2

1

For your 2nd question:

You can use base64 encoded images. It works with jspdf. To convert image into base64, check this: How to convert image into base64 string using javascript

Community
  • 1
  • 1
er-han
  • 1,859
  • 12
  • 20
  • Hi thanks... it is working fine. But it took too long time while fetching data from url and convert it into base64. The code is as follows... function replace_img_src($img_tag) { @$doc = new DOMDocument(); @$doc->loadHTML($img_tag); $tags = $doc->getElementsByTagName('img'); foreach ($tags as $tag) { $old_src = $tag->getAttribute('src'); $new_src_url = 'data:image/png;base64,'.base64_encode(file_get_contents($old_src)); $tag->setAttribute('src', $new_src_url); } return $doc->saveHTML(); } – MDS Jan 24 '17 at 06:30
  • Please help me for time efficiency. – MDS Jan 24 '17 at 06:32
  • @MDS i didn't recognize this syntax, what language is this? And could you create a jsfiddle? At least show us content of the functions you used, like "base64_encode(file_get_contents($ol‌​d_src))" – er-han Jan 24 '17 at 08:24
  • It is in php.. loadHTML($img_tag); $tags = $doc->getElementsByTagName('img'); foreach ($tags as $tag) { $old_src = $tag->getAttribute('src'); $new_src_url = 'data:image/png;base64,'.base64_encode(file_get_contents($old_src)); $tag->setAttribute('src', $new_src_url); } return $doc->saveHTML(); } and $img_tag is a html content – MDS Jan 25 '17 at 09:16
0

1 You need to check the pdf size and adjust it.

2 The base64 image renders in the jspdf. You can use this link for getting base64 code and paste it in img src value https://www.base64-image.de/

Shalini
  • 219
  • 1
  • 5
  • 16