在 Google Apps Script 中从 HTML 创建 PDF 并包含图像 - 图像未显示 [英] Create PDF from HTML in Google Apps Script and include images - Images not showing up
问题描述
我想动态创建 PDF.这意味着我要从 Google Drive 获取文件,然后将它们放入 HTML 代码中并尝试从中创建 PDF.
一切正常,除了图像不显示.
我现在正在做的是:
- 从 HTML 字符串创建 HtmlOutput.
- 获取该 HTML 的 blob.
- 然后那个 blob getAs PDF
- 然后最终将该 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>高回报地产</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; } .top_header { background: #dfe9e9; display: inline-block; width: 100%; margin-bottom: 6px; } .left_top { display: inline-block; width: 70%; padding: 26px 0 26px50px; float: left; } p.contact_person.right_person { border-right: 0; padding-left: 25px; display: inline-block; } p.contact_person { width: 214px; display: inline-block; text-align:左; 右边框:1px 实心 #ccd4d3; } .left_top p span { 字体大小:13px;颜色:#000;显示:内联块;宽度:100%;边距顶部:2px;} .left_top p { 字体大小:20px;字体粗细:粗体;颜色:#ea9a5a;边距:0;} .right_top img { border-top: 7px solid #496bb3;边框底部:7px 实心 #496bb3;填充:16px 5px 13px 4px;} .right_top { 显示:内联块;位置:绝对;背景:#fff;} .galleryimage_main img { 宽度:100%;显示:内联块;} .property_address { } .property_address p { 字体大小:15px;文本转换:大写;颜色:#fff;底边距:0;边距顶部:4px;} .common_box_style { 填充:20px;背景:#496bb3;文本转换:大写;} .common_box_style h2 { margin-top: 2px;颜色:#54bb73;字体大小:20px;} .property_information { margin-left: 6px;} .property_information ul lip { 字体大小:15px;颜色:#fff;文本转换:大写;底边距:3px;边距顶部:0;} .property_information ul li { 列表样式:无;底边距:5px;} .property_information ul li span { font-size: 15px;颜色:#fff;文本转换:大写;底边距:3px;边距顶部:0;宽度:100px;显示:内联块;文本对齐:左;} .property_information ul { padding-left: 0;宽度:自动;显示:内联块;向左飘浮;右边距:15px;边距顶部:0;底边距:4px;} .property_information ul li span.value_field { 字体大小:13px;} ul.grpleft li span { 宽度:136px;} p.cash_prize { 文本对齐:居中;字体大小:18px;字体粗细:粗体;颜色:#fff;显示:内联块;宽度:100%;边距:0;} p.cash_prize span { padding-left: 10px;} .margintop{ margin-top: 6px;} .left_col { 宽度:34%;向左飘浮;} .right_col { 显示:内联块;宽度:66%;} .gallery_small_images { 显示:内联块;宽度:99%;左边距:6px;边距顶部:6px;高度:232px;溢出:隐藏;} .gallery_small_images img{ width:100%;} .gallery_small_image2 { 宽度:50%;向左飘浮;} .gallery_small_image3 { 宽度:49%;显示:内联块;向左飘浮;左边距:6px;} table.expense_info tr td.exp_info_disc { 字体大小:14px;颜色:#fff;文本转换:大写;文本对齐:左;} tr.total_exp td { padding-top: 13px;填充底部:30px;} .cashflow h2 { margin-bottom: 7px;} .roi input[type='text'] { font-size: 23px;文本对齐:居中;字体粗细:粗体;高度:33px;底边距:5px;} .roi h2 { margin-top: 24px;字体大小:22px;字体粗细:800;} tr.total_exp { 字体粗细:粗体;边距顶部:4px;/* 显示:表格;*/宽度:100%;} table.expense_info th { 字体大小:12px;字体粗细:粗体;颜色:#fff;文本转换:大写;} td { 字体大小:13px;颜色:#fff;文本对齐:居中;垂直对齐:中间;} .expense_info.common_box_style.margintop { 填充:20px 13px;} table.cashflow { 文本对齐:居中;边距:0 自动;颜色:#fff;文本转换:大写;} table.cashflow tr th { font-size: 19px;字体粗细:正常;} table.cashflow tr td { font-size: 17px;字体粗细:粗体;} .roi { 显示:内联块;背景:#2bb673;宽度:99%;文本对齐:居中;颜色:#000;填充:10px 0px 20px 0;左边距:6px;边距顶部:6px;} .discliamer_sec { 背景:#dfe9e9;显示:内联块;文本对齐:居中;字体大小:9px;宽度:100%;填充:10px 0;行高:18px;边距顶部:6px;} .discliamer_sec h2 { 颜色:#768293;} .footer_cright { 背景:#496bb3;文本对齐:居中;字体大小:8px;颜色:#fff;填充:1px 0;字体粗细:400;边距顶部:7px;显示:内联块;宽度:100%;} @media print { .common_box_style, .roi, .discliamer_sec, .footer_cright, .top_header { 背景:!important;-webkit-print-color-adjust:精确;} } </style><link href='https://fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet'>头部><身体><div class='main_wrapper'><div class='left_top'><p class='contact_person'>Xyz xyz<span>xyz@xyz.com</span></p><p class='contact_person right_person'>xyz xyz<span>xyz@xyz.com</span></p></div><div class='right_top'>";html +="<img src='images/logo.png'/></div> </div> <div class='galleryimage_main'> <img src='https://drive.google.com/uc?export=view&id="+file1+"' alt='Gallery Image Here' height='350' width='885'/> </div> <div class='left_col'> <div class='property_address common_box_style margintop'> <h2>PROPERTY ADDRESS</h2> <p id='address_line_1' class='address_line_1'>4043 N RAVENSWOOD AVE,</p><p id='address_line_2' class='address_line_2'>CSUITE 316, HICAGO,</p> </div> <div class='expense_info common_box_style margintop'> <h2>费用信息</h2> <table id='expense_information' class='expense_info' cellpadding='3' cellspacing='1'> <tr> <th></th> <th>%of Rent; <th>每月</th> <th>Yearly</th> </tr> <tr> <td class='exp_info_disc'>估计税费:</td> <td>-</td><td>345</td><td>777</td></tr><td class='exp_info_disc'>预估保险:</td><td>-</td><td>200</td><td>133</td></tr><tr><td class='exp_info_disc'>管理费:</td><td>4</td><td>344</td><td>5200</td></tr><tr><td class='exp_info_disc'>空缺调整:</td><td>2</td><td>555</td><td>50</td></tr><tr><td class='exp_info_disc'>维修&维护:</td><td>10</td><td>500</td><td>50</td></tr><tr></tr><tr></tr><tr></tr><td class='exp_info_disc'>总费用:</td><td></td><td>343</td><td>342</td></tr><tr></tr><tr></tr><tr></tr><div class='cashflow common_box_style margintop'><h2>现金流量估算</h2><table id='cashflow' class='cashflow' cellpadding='3' cellspacing='5'><tr><th>每月</th><th>每年</th></tr><tr><td>123</td><td>4533</td></tr>
<div id='property_information' class='property_information common_box_style margintop'><h2>房产信息</h2><ul><li><span>标价:</span><span class='value_field'>100</span></p></li><li><span>康复费用:</span><span class='value_field'>100</span></p></li><li><span>结构:</span><span class='value_field'>Single Family</span></li><li><span>当前租金:</span><span class='value_field'>29</span></li><li><span>卧室:</span><span class='value_field'>100</span></li><li><span>浴室:</span><span class='value_field'>100</span></p></li><li><span>方形素材:</span><span class='value_field'>100</span></p></li><li><span>当前状态:</span><span class='value_field'>租用和表演 </span></li>
<p class='cash_prize'>现金价格<span>300</span></p><div class='gallery_small_images'><div class='gallery_small_image2'><img src='https://drive.google.com/uc?export=view&id="+file2+"'/>
<div class='gallery_small_image3'><img src='https://drive.google.com/uc?export=view&id="+file3+"'/></div></div><div class='roi' id='cash_on_cash'><h2>CASH-ON-CASH ROI</h2><input type='text' value='1200' id='cash_roi_input'></input>
<div class='discliamer_sec'><h2>信息被认为是可靠的但没有保证.图片不按比例缩放.买方负责<br>对所提供的所有信息进行尽职调查,并应自行研究.</h2>
<div class='footer_cright'><h2>Copyright © High Return Real Estate LLC - 2017</h2>