【发布时间】:2019-03-07 14:22:18
【问题描述】:
我正在尝试使用wkhtmltopdf 将 HTML 代码制作成 PDF。在 C# 中,我使用 Process 来执行所有操作。我需要通过 JavaScript 从我的 HTML 页面获取特定的<div>,并将所有这些内容发送到我的 Asp。当前尝试将此字符串作为参数传递到 URL,但它太长了。有没有其他方法可以使用 JS 获取大的 HTML 字符串,并将其发送到 .NET Core,并将其内容制作成 PDF?
function getDBData(src)
{
let script = document.createElement("SCRIPT");
script.src = backend + src;
document.getElementsByTagName("head")[0].appendChild(script);
}
function tableToPdf()
{
// Add in htmlContent heade
let htmlContent = "<head><link rel=\"stylesheet\" href=\"table-
style.css\" media=\"all\"/></head>";
// Get all tables
let tables = document.querySelectorAll("#tableWrapper .col-lg-12");
for(let i = 0; i < tables.length; i++)
{
// Get header of table
let tableHeader = tables[i].querySelector(".tableHeader").outerHTML;
// Get table content
let tableContent = tables[i].querySelectorAll(".wrapper-table-section-library")[1].outerHTML;
htmlContent += tableHeader
htmlContent += tableContent;
}
// Get width ant height of tableWrapper
let height = document.querySelector("#tableWrapper").offsetHeight;
let width = document.querySelector("#tableWrapper").offsetWidth;
getDBData("getTablePdf?width=" + width + "&height=" + height +"&htmlContent=" + htmlContent + "&outputFileName=tables");
}
【问题讨论】:
-
不要使用查询参数发送大量数据,您会受到 URL 中字符数的限制。相反,
POST消息正文中的数据。 -
你能提供一个链接吗?
-
没有链接,事情就是这样。
-
你是通过
script标签做ajax请求吗?哦,我的
标签: javascript c# asp.net-core