4

I'm using Google App Script and I want to convert the contents of a div in a pdf file. I'm trying:

function genPdf(html)
{
  var blob = Utilities.newBlob(html, "text/html", "text.html");
  var pdf = blob.getAs("application/pdf");
  DriveApp.createFile(pdf).setName("text.pdf"); 
}

The 'html' parameter of the function is passed with a

$('#container').html()

The problem is when I get the html of the div with the Jquery's html() function, it returns me the html without the CSS styles and/or images.

I need to generate a PDF with exactly the same content of the div.

Any suggestions?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Pavarine
  • 637
  • 3
  • 15
  • 30
  • 1
    This question isn't very clear, so you'll probably find it gets closed as a duplicate to [Generate pdf from HTML in div using Javascript](http://stackoverflow.com/questions/18191893), [Download a div in a HTML page as pdf using javascript](http://stackoverflow.com/questions/17293135) or something similar. It seems that you want to save a PDF to your Google Drive, with the complete contents of a div from a page served by Google Apps Script's HtmlService. – Mogsdad Jul 06 '15 at 12:39
  • 1
    try inline css inside the html – Zig Mandel Jul 06 '15 at 13:34
  • is it possible to convert pdf to html in the same way – sdx11 Dec 16 '21 at 15:02

1 Answers1

0

the inline css will work when html is retrieved from jquery but the html view cannot be same in the pdf also. I had problems with alignment of the tables in pdf format.

shabnam bharmal
  • 589
  • 5
  • 13