Covert
Covert

Reputation: 491

Why doesn't itext convert my page to pdf?

I am using this to convert the html to pdf but it does nothing. No error or exception. I debugged and it has the html content and even shows on page but not downloading. I am loading HTML content into hidden field from database and assigning to literal control from backend and i checked it shows the value.

Code:

private MemoryStream Export(string html="")
    {
        ltr.Text = hdnDescription.Value;
        html = ltr.Text;

        MemoryStream msOutput = new MemoryStream();
        TextReader reader = new StringReader(html);

        // step 1: creation of a document-object
        Document document = new Document(PageSize.A4, 30, 30, 30, 30);

        // step 2:
        // we create a writer that listens to the document
        // and directs a XML-stream to a file
        PdfWriter writer = PdfWriter.GetInstance(document, msOutput);

        // step 3: we create a worker parse the document
        HTMLWorker worker = new HTMLWorker(document);

        // step 4: we open document and start the worker on the document
        document.Open();
        worker.StartDocument();

        // step 5: parse the html into the document
        worker.Parse(reader);

        // step 6: close the document and the worker
        worker.EndDocument();
        worker.Close();
        document.Close();

        return msOutput;
    }

.aspx:

<%@ Page Title="Print Tender" EnableEventValidation="false" Language="C#"
    MasterPageFile="~/Default.master" AutoEventWireup="true" CodeFile="printTender.aspx.cs"
    Inherits="forms_general_printTender" %>

<%--<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>--%>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">

        <asp:HiddenField ID="hdnDescription" runat="server" />
    <asp:Literal ID="ltr" runat="server"></asp:Literal>

    <rsweb:ReportViewer ID="ReportViewer1" AsyncRendering="false" runat="server" Width="100%" Height="50%" Font-Names="Verdana" SizeToReportContent="false" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentScript" runat="Server">
</asp:Content>

Upvotes: 0

Views: 49

Answers (1)

Joris Schellekens
Joris Schellekens

Reputation: 9022

First, HTMLWorker was superseded by XMLWorker, which has just been superseded by pdfHTML. Being behind this many versions will not help your document - workflow.

Second, iText only converts static HTML. ASP pages are not considered static content.

Upvotes: 1

Related Questions