Free Support Forum - aspose.com

Problem of body background binary image when converting html string to pdf

Hi,

When I convert html string to pdf, binary image of body background is not added to document. Can you help me?

sample code:

using (var streamProvider = new MemoryStreamProvider())
{
using (var document = new Aspose.Html.HTMLDocument(statementHtml, “.”))
{
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.PdfSaveOptions(), streamProvider);

            var memory = streamProvider.Streams.First();
            memory.Seek(0, System.IO.SeekOrigin.Begin);

            var arr = memory.ToArray();

            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();
            Response.Charset = "UTF-8";
            Response.AddHeader("content-length", arr.Length.ToString());
            Response.AddHeader("content-disposition", String.Format("attachment;filename=TestDocument.pdf", "FileName"));
            Response.ContentType = "application/pdf";
            Response.Buffer = true;
            Response.BinaryWrite(arr);
            Response.Flush();
            Response.End();
        }
    }

@hoyri7

Could you please provide your sample HTML string to us? You can share it in a text file by adding it to .zip format. We will test the scenario in our environment and address it accordingly.

aspose.zip (291.0 KB)

I attached the zip file. Thank for reply.

@hoyri7

We saved your file as .html and viewed it in different web browsers. We could not find the background image in it. Would you kindly share a screenshot of the rendered HTML with background image along with the browser information in which it is displaying. We will further proceed to assist you accordingly.

I see images when I create html file and write in code like this “Response.Write(statementHtml);”

@hoyri7

We have logged an issue as HTMLNET-2831 in our issue management system for the sake of further investigation. We will look into ticket details and keep you informed about its resolution status. Please be patient and give us some time.

We are sorry for the inconvenience.

I wonder, is background image a general problem when converting html string to pdf?

@hoyri7

We need to investigate the scenario in details in order to determine the reasons behind it. As soon as the investigation is done, we will be able to further comment over this problem. We will share updates with you for sure as soon as we have some after analysis. Please give us some time.