Hi,
I am trying to convert HTML string to PDF byte array C# with Aspose.Words.Document and having problem with Table elements which width is defined as percent.
I have attached a text file with .txt extension that contains the source HTML string which needs to be replaced to .html and I am trying to convert it with this C# code snippet.
public static byte[] HtmlToPdf(string strFileName)
{
byte[] htmlDocument = strFileName;
byte[] downloadBytes = null;
using (MemoryStream readStream = new MemoryStream(htmlDocument))
{
using (MemoryStream writeStream = new MemoryStream())
{
Document doc = new Document(readStream);
foreach (Section sec in doc.Sections)
{
sec.PageSetup.PaperSize = PaperSize.A4;
sec.PageSetup.LeftMargin = 0;
sec.PageSetup.BottomMargin = 0;
sec.PageSetup.RightMargin = 0;
sec.PageSetup.TopMargin = 0;
}
// Save the document in PDF format.
doc.Save(writeStream, SaveFormat.Pdf);
downloadBytes = writeStream.ToArray();
}
}
return (downloadBytes);
}
Also, please find attached files for the source file and result file which have two tables.
Problems are:
- The first table has 100% width of its parent
div
, but in PDF it doesn’t look like 100% width. - The second table has 50% width of its parent
div
, but this is not aligned in a right position. Actually this table has gone out of its parentdiv
container. - Page number which is in
div
element with float to right is not floating to right hand side.
If I update table layout by using the doc.UpdateTableLayout();
method it actually adjust the table with into the percent of its page size, not its parent div
size.
Does anyone have a solution for this?
Thanks.