我正在使用 wnvhtmconvert 将我的 html 转换为 pdf。我需要在我的 pdf 中添加展开/折叠书签功能。谁能帮帮我。谢谢。
1 回答
0
解决方法是执行this.bookmarkRoot.open=true; 打开文档时的 AcroJS 脚本。您可以在Execute Acrobat JavaScript Code when Document is Opened demo中找到一个完整示例,其中包含在查看器中打开 PDF 文档时执行 AcroJS 代码的源代码。从该演示复制的相关代码是:
protected void convertToPdfButton_Click(object sender, EventArgs e)
{
// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();
Document pdfDocument = null;
try
{
// Convert a HTML page to a PDF document object
pdfDocument = htmlToPdfConverter.ConvertUrlToPdfDocumentObject(urlTextBox.Text);
string javaScript = null;
if (alertMessageRadioButton.Checked)
{
// JavaScript to display an alert mesage
javaScript = "this.bookmarkRoot.open=true;";
}
else if (printDialogRadioButton.Checked)
{
// JavaScript to open the print dialog
javaScript = "print()";
}
else if (zoomLevelRadioButton.Checked)
{
// JavaScript to set an initial zoom level
javaScript = String.Format("zoom={0}", int.Parse(zoomLevelTextBox.Text));
}
// Set the JavaScript action
pdfDocument.OpenAction.Action = new PdfActionJavaScript(javaScript);
// Save the PDF document in a memory buffer
byte[] outPdfBuffer = pdfDocument.Save();
// Send the PDF as response to browser
// Set response content type
Response.AddHeader("Content-Type", "application/pdf");
// Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Execute_Acrobat_JavaScript.pdf; size={0}", outPdfBuffer.Length.ToString()));
// Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer);
// End the HTTP response and stop the current page processing
Response.End();
}
finally
{
// Close the PDF document
if (pdfDocument != null)
pdfDocument.Close();
}
}
于 2014-08-15T11:38:25.947 回答