selectpdf / selectpdf-free-html-to-pdf-converter

Free Html To Pdf Converter for .NET. Asp.Net, C# sample.
13 stars 2 forks source link

Conversion failure. Data transfer error. Data transmission error 0 #18

Open RvdHout opened 3 years ago

RvdHout commented 3 years ago

Select.HtmlToPdf 20.2.0

Basically I am using a similar code as posted here: https://selectpdf.com/html-to-pdf/docs/html/ConvertAndEmail.htm to create PDF and attach it to a mail message

// create email message
MailMessage message = new MailMessage();
message.From = new MailAddress("support@selectpdf.com");
message.To.Add(new MailAddress(TxtEmail.Text));
message.Subject = "SelectPdf Sample - Convert and Email as Attachment";
message.Body = "This email should have attached the PDF document " + 
    "resulted from the conversion of the following url to pdf: " + 
    TxtUrl.Text;

HtmlToPdf converter = new HtmlToPdf();
try
{
    // set converter options
    converter.Options.CssMediaType = HtmlToPdfCssMediaType.Print;
    converter.Options.JavaScriptEnabled = false;
    converter.Options.PdfPageSize = PdfPageSize.A4;
    converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait;
    converter.Options.MarginBottom = 0;
    converter.Options.MarginRight = 0;
    converter.Options.MarginLeft = 0;
    converter.Options.MarginTop = 0;
    converter.Options.WebPageWidth = 794;
    converter.Options.WebPageHeight = 0;
    converter.Options.AutoFitWidth = HtmlToPdfPageFitMode.AutoFit;
    converter.Options.MinPageLoadTime = 1;

    // create a new pdf document converting an url
    PdfDocument doc = converter.ConvertUrl(TxtUrl.Text);

    // create memory stream to save PDF
    MemoryStream pdfStream = new MemoryStream();

    // save pdf document into a MemoryStream
    doc.Save(pdfStream);

    // reset stream position
    pdfStream.Position = 0;

    message.Attachments.Add(new Attachment(pdfStream, "Document.pdf")); 

    // close pdf document
    doc.Close();
}
catch (Exception ex)
{
    throw ex;
}

try
{
    using (SmtpClient client = new SmtpClient())
    {
        client.Send(message);
    }
}
catch (SmtpException se)
{
    throw se;
}
finally
{
    if (message != null)
    {
        if (message.Attachments.Count > 0)
        {
            message.Attachments.Dispose();
        }
        message.Dispose()
    }
}

Exception Message: Conversion failure. Data transfer error. Data transmission error 0

Remarkable is the fact this exception doesn't occur every time Anyone had a idea what Conversion failure. Data transfer error. Data transmission error 0 means? Or how i can solve this error?

selectpdf commented 3 years ago

Hi,

Error 0 is actually a crash of the html rendering engine. If that does not happen all the time, maybe you can implement some sort of retry mechanism.

Regards,

SelectPdf Support

https://selectpdf.com https://selectpdf.com

From: RvdH @.> Sent: Wednesday, September 22, 2021 1:13 PM To: selectpdf/selectpdf-free-html-to-pdf-converter @.> Cc: Subscribed @.***> Subject: [selectpdf/selectpdf-free-html-to-pdf-converter] Conversion failure. Data transfer error. Data transmission error 0 (#18)

Select.HtmlToPdf 20.2.0

Basically I am using a similar code as posted here: https://selectpdf.com/html-to-pdf/docs/html/ConvertAndEmail.htm to create PDF and attach it to a mail message

HtmlToPdf converter = new HtmlToPdf(); try { ... } catch (Exception ex) { throw ex; }

Exception Message: Conversion failure. Data transfer error. Data transmission error 0

Remarkable is the fact this exception doesn't occur every time Anyone had a idea what Conversion failure. Data transfer error. Data transmission error 0 means? Or how i can solve this error?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/selectpdf/selectpdf-free-html-to-pdf-converter/issues/18 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUTWYJSOTRUOY3NLKVFFY3UDGT37ANCNFSM5EQ6MRJQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub . https://github.com/notifications/beacon/ACUTWYJRTQRLDP6LK4JZOHTUDGT37A5CNFSM5EQ6MRJ2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4O6ZR76Q.gif