In memory HTML to PDF causes document faults

Hi guys,


We want to convert an HTML string to a variety of formats. We’re using Words as we figure this is the best product for the job. However, it’s not working despite doing a bunch of googling. Here’s the code:


    MemoryStream fileStream = null;

    // Create a new file stream to store the file
    fileStream = new MemoryStream();

    // Use aspose to convert the html into a PDF
    document = new Document(new MemoryStream(Encoding.Default.GetBytes(attachmentHtml)), new LoadOptions() { LoadFormat = LoadFormat.Html });
    document.Save(fileStream, SaveFormat.Pdf);

    // Attach the PDF to the mail message
    //mailMsg.Attachments.Add(new Attachment(fileStream, "Attachment.pdf", MediaTypeNames.Application.Pdf));

When we get the attachment, the PDF is always corrupt. We tried Aspose PDF also - same result - so it seems to be something fundamental (and it's not the email program as we've sent other docs through just fine!)

Hi Steve,

Thanks for your inquiry. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v13.12.0) from here and let us know how it goes on your side. If the problem still remains, please attach your input html document here for testing. I will investigate the issue on my side and provide you more information.


Definitely latest version - downloaded it for the first time yesterday! The html being converted attached (zipped so it could be uploaded). Any help greatly appreciated.


Cheers,

Steve

Hi Steve,

Thanks for sharing the document.

I have tested the scenario and have not found the shared issue while using latest version of Aspose.Words for .NET 13.12.0. Please use the Aspose.Words for .NET 13.12.0. I have attached the output Pdf file with this post for your kind reference.

Thanks for that - appreciate you having a look.


Does my code look OK to you? It doesn’t work for me on 13.12.0 still and am not really sure why. I’m running Windows 8.1 on my development machine if you think that makes a difference.

Cheers,

Steve

Hi Steve,

Thanks for your inquiry. I have tested again the same scenario at my end and have not found the shared issue. Could you please save your Pdf document on disk instead of saving it into memory? Unfortunately, I am unable to download your output Pdf file shared in first post. Please save your Pdf on disk and share it with use for your reference.

It would be great if you please test the same scenario at some different machine and share your finding with us.