我正在尝试通过 google-apps-script 从 HTML 页面创建 PDF,并将页面大小设置为“ Letter ”而不是“ A4 ”(8.26 X 11.69)。我检查了许多相关的帖子,实际上已经弄清楚了背景颜色、图像等...相关的从 PDF 中的 HTML 背景颜色创建 PDF,但我无法对页面大小进行任何更改。
function htmlToPDF() {
var html = "<h1>Hello world</h1>"
+ "<p>This is just a paragraph"
+ "<p style='color:red;'>I am red</p>"
+ "<p style='color:blue;'>I am blue</p>"
+ "<p style='font-size:50px;'>I am big</p>"
+ "<table style='border-collapse: collapse; width: 698px; height: 115px; background-color: #C5D9F1;' border='0' cellpadding='10'>"
+ "<tbody>"
+ "<tr>"
+ "<td style='padding: 5px;background-color:powderblue;' nowrap='nowrap'><strong>Bold with background-color:</strong></td>"
+ "</tr>"
+ "</tbody>"
+ "</table>";
var …
Run Code Online (Sandbox Code Playgroud) 我想动态创建PDF.这意味着我正在从Google云端硬盘获取文件,然后将它们放入HTML代码并尝试从中创建PDF.
一切都运行正常,除了图像没有显示.
我现在正在做的是:
我想也许需要一些时间来渲染图像,所以我增加了睡眠.
我们也欢迎其他建议/解决方案/代码.
这是我正在使用的代码::
function htmlToPDF() {
var file1="0BweO_SXcQGqgcEV3Mk9QYVRMczQ";
var file2="0BweO_SXcQGqgVU93ZU56WkRkN3c";
var file3="0BweO_SXcQGqgMkIxTlhKajk5MFk";
var html = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> <title>High Return Real Estate</title> <style> @charset 'utf-8'; /* CSS Document */ body,html{ font-family: 'Lato', sans-serif; background:#dfe7ea; margin-top: 0; margin-bottom:0; } .main_wrapper { width: 930px; margin: 0 auto; background: #fff; padding: 0 23px 0 23px; box-shadow: 1px 1px 8px -1px #bbbbbb; …
Run Code Online (Sandbox Code Playgroud)