The following code correctly generated a PDF based on HTML in v4.x of aspose.pdf. In 8.x, highlighted method no longer accepts a textwriter. I’ve tried several different techniques but nothing seems to preserve the formatting. Can you assist?
protected override void Render(HtmlTextWriter writer)
{
//Save the file with the current
using (var memoryStream = new MemoryStream())
{
using (var streamWriter = new StreamWriter(memoryStream))
{
using (var htmlTextWriter = new HtmlTextWriter(streamWriter))
{
BufferedStream bf = new BufferedStream(memoryStream);
base.Render(htmlTextWriter);
htmlTextWriter.Flush();
memoryStream.Position = 0;
TextReader textReader = new StreamReader(memoryStream);
GenerateQualityReportDocument rd = new GenerateQualityReportDocument();
rd.ID_Case = ID_Case;
rd._qualityReport.BindHTML(textReader);
ApplyFormatting(rd._qualityReport);
rd.SaveFile();
}
}
}
string s = String.Format("/pages/general/cat.aspx?ID_Case={0}", ID_Case);
if (Convert.ToBoolean(Request.QueryString[“CaseClosed”]))
{
s += “&Closed=1”;
}
HttpContext.Current.Response.Redirect(s);
}
public void ApplyFormatting(Pdf qr)
{
TextInfo ti = new TextInfo();
ti.Alignment = AlignmentType.Justify;
qr.TextInfo = ti;
MarginInfo mi = new MarginInfo();
mi.Left =50;
mi.Right = 50;
qr.Sections[0].PageInfo.PageWidth = PageSize.A3Width;
qr.Sections[0].PageInfo.Margin = mi;
foreach (object para in qr.Sections[0].Paragraphs)
{
if (para is Aspose.Pdf.Table)
{
Aspose.Pdf.Table table = (Aspose.Pdf.Table)para;
Cells cls = table.Rows[0].Cells;
if (cls.Count == 4)
{
table.ColumnWidths = “100 150 200 200”;
}
else if (cls.Count == 3)
{
table.ColumnWidths = “217 217 217”;
}
}
}
}
Hi Scott,
Thanks for contacting support.
In earlier versions of Aspose.Pdf for .NET, the BindHTML method used to accept HTML file either by directly referencing it from file system or loading its contents through Stream object, but in recent releases of Aspose.Pdf for .NET, we have modified the BindHTML method and now it has two overloads i.e. One overload accepts String object containing HTML text, and the second overload accepts stream object holding HTML contents. However I would recommend you to please try using the latest Document Object Model (DOM) of Aspose.Pdf namespace which provides the capabilities to load HTML file and save the output in PDF format. When using following approach, either you can load the HTML file from system or load its contents from Stream object.
We are sorry for this inconvenience.
C#
// load source HTML
Document doc = new Document(@"C:\pdftest\html2PDF.htm",
new HtmlLoadOptions()
{ UseNewConversionEngine = true });
// save the output file
doc.Save(@"C:\pdftest\html2PDF.pdf");
Thank you for your reply. I attempted to modify the existing code in this way: How do I construct the document using a memory stream that will avoid this rule?Document d = new Document(memoryStream, new HtmlLoadOptions() { UseNewConversionEngine = true });
However, this throws the exception "At most 4 text fragments can be added in evaluation mode."
Hi Scott,
As indicated in message, only 4 objects can be added when using the component in evaluation mode. However, in order to avoid above stated issue, you need to use a valid product license. So you may either update your existing license subscription or request a 30 days temporary license. For further details, please visit Get a temporary license.
We are sorry for this inconvenience.