Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6074549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:23:40+00:00 2026-05-23T10:23:40+00:00

I am trying to create an app that converts html to a pdf doc

  • 0

I am trying to create an app that converts html to a pdf doc then emails it as an attachment.

I am getting this error The underlying connection was closed: The connection was closed unexpectedly.

Tried Googling but didn’t have much luck; any hints to why this might be coming up?

Edit:
The error occurs at line 28: html2pdf.Run(Convert);

<%@ Import Namespace="System.Web.Mail" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Pdfizer" %>
<script language="c#" runat="server">        
    protected override void OnLoad(EventArgs e)
    {    
        sendApplication();    
    }

    private void sendApplication()
    {    
        string template = "X:\\path\\to\\file\\temp.htm"; //HTML Form to send    
        Stream steam = new FileStream("X:\\path\\to\\file\\app.pdf", FileMode.Create, FileAccess.Write, FileShare.Write); //Stream to write to file.
        string fileToSend = "X:\\path\\to\\file\\app.pdf"; //PDF to send(after creation)

        string smtpServer = "spamfilter1.com";
        string sendFrom = "test@test.com";
        string sendTo = "test@test.com";

        //Read template
        StreamReader templateFile = new StreamReader(template);
        string Convert = templateFile.ReadToEnd();
        templateFile.Close();

        //Convert to PDF
        HtmlToPdfConverter html2pdf = new HtmlToPdfConverter();
        html2pdf.Open(steam);
        html2pdf.AddChapter(@"_");
        html2pdf.Run(Convert);
        html2pdf.Close();

        //Send email and attachment
        MailMessage msg = new MailMessage();
        msg.To = sendTo;
        msg.From = sendFrom;
        msg.Subject = "New Application";
        msg.Body = Convert;
        MailAttachment attach = new MailAttachment(fileToSend);
        msg.Attachments.Add(attach);
        SmtpMail.SmtpServer = smtpServer;
        SmtpMail.Send(msg);
        lblStatus.Text = "Application Submitted.";
    }    
</script>   

Here is the entire Trace

Server Error in '/WebSite1' Application.
The underlying connection was closed: The connection was closed unexpectedly.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly.

Source Error:

Line 26:         html2pdf.Open(steam);
Line 27:         html2pdf.AddChapter(@"_");
Line 28:         html2pdf.Run(Convert);
Line 29:         html2pdf.Close();
Line 30:         


Source File: c:\Users\Jeff\Documents\Visual Studio 2010\WebSites\WebSite1\sstnS.aspx    Line: 28

Stack Trace:

[WebException: The underlying connection was closed: The connection was closed unexpectedly.]
   System.Net.HttpWebRequest.GetResponse() +6111059
   System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy) +107
   System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy) +4012381
   System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +69
   System.Xml.XmlTextReaderImpl.OpenAndPush(Uri uri) +171
   System.Xml.XmlTextReaderImpl.PushExternalEntityOrSubset(String publicId, String systemId, String baseUriStr, Uri& baseUri, String entityName) +252
   System.Xml.XmlTextReaderImpl.DtdParserProxy_PushExternalSubset(String systemId, String publicId) +46
   System.Xml.DtdParserProxy.System.Xml.IDtdParserAdapter.PushExternalSubset(String systemId, String publicId) +16
   System.Xml.DtdParser.ParseExternalSubset() +21
   System.Xml.DtdParser.ParseInDocumentDtd(Boolean saveInternalSubset) +4133593
   System.Xml.DtdParser.Parse(Boolean saveInternalSubset) +54
   System.Xml.DtdParser.System.Xml.IDtdParser.ParseInternalDtd(IDtdParserAdapter adapter, Boolean saveInternalSubset) +31
   System.Xml.XmlTextReaderImpl.ParseDtd() +72
   System.Xml.XmlTextReaderImpl.ParseDoctypeDecl() +219
   System.Xml.XmlTextReaderImpl.ParseDocumentContent() +453
   System.Xml.XmlTextReaderImpl.Read() +145
   System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) +114
   System.Xml.XmlDocument.Load(XmlReader reader) +114
   System.Xml.XmlDocument.LoadXml(String xml) +168
   Pdfizer.HtmlToPdfConverter.Run(String html) +134
   ASP.sstns_aspx.sendApplication() in c:\Users\Jeff\Documents\Visual Studio 2010\WebSites\WebSite1\sstnS.aspx:28
   ASP.sstns_aspx.OnLoad(EventArgs e) in c:\Users\Jeff\Documents\Visual Studio 2010\WebSites\WebSite1\sstnS.aspx:9
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 

I should also say the Email sending and attachment works properly(already tested).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:23:41+00:00Added an answer on May 23, 2026 at 10:23 am

    It looks like you’re expecting the Run() method to put the data into the “steam” location, but it’s instead trying to open a URI. Either the Open() method isn’t telling it “here’s where to save the data”, or the Run() method isn’t properly saving to that location. I would start by combing through the documentation for the library, since I’m not familiar with it myself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this error in rails whenever i am trying to create an
Trying to create an app that does some socket communication (Writing only). I can
I'm trying to create an Android app that searches for a certain type of
I'm trying to create a bulk edit page for an app that I'm working
I am trying to create an app that can "Purposely" consume RAM as much
I am trying to create an app that allows the user to draw a
I am playing around with xCode and was trying to create a small app
I'm new to flex and actionscript. I'm trying to create a small flex app
I am trying to create an app where, when you search for a particular
Im trying to create a RSS feed reader for a project that I working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.