如何将winnovative html中的书签选项展开/折叠为pdf转换器

时间:2014-03-27 09:14:59

标签: asp.net pdf winnovative

我正在使用wnvhtmconvert将我的html转换为pdf。我需要在我的pdf中添加扩展/折叠书签功能。有人可以帮帮我。谢谢。

1 个答案:

答案 0 :(得分: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();
    }
}