Hi
I’m generating a very small document with Aspose Trial version. And it turns out that pdf generation from html is taking 900 milliseconds.
Please review the code and html and let me know if i’m doing something wrong or this is the actual performance of ASPOSE library for given input and output.
The input html also include a picture for logo.
Code:
string dataDir = Path.GetFullPath(“HtmlTemplate.html”);
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();
StreamReader sr = File.OpenText(dataDir);
Aspose.Pdf.Generator.Text tempText = newAspose.Pdf.Generator.Text(section, sr.ReadToEnd());
tempText.IsHtmlTagSupported = true;
section.Paragraphs.Add(tempText);
pdf.Save(@“C:\NewGenerateFile.pdf”);
HTML Input template attached: 1.rar
Regards,
Deepak
Hi Deepak,
Thanks for your inquiry. Please note Aspose.Pdf does not create any temporary files during processing but uses memory. So processing time varies and depends upon the contents and system resources. Your shared sample HTML has some tabular data so taking some time, for plain text html it will be different.
Moreover, please note it is recommended to use new generator for
HTML to PDF conversion. It is more efficient and improved.
Please feel free to contact us for any further assistance.
Best Regards,
Thanks Tilal, for the information.
I am facing another problem with regard to Multithreading while using Aspose library.
I have below line of code running in multiple threads at the same time, that results in an exception.
Code:
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
pdf.BindHTML(content); //Exception occurred here while using Task (TPL)
Here, content is a HTML string.
Exception:
System.InvalidOperationException: Object is currently in use elsewhere.
at System.Drawing.Graphics.FromImage(Image image)
at Aspose.Pdf.Generator.Pdf.BindHTML(String html, String basePath)
at Aspose.Pdf.Generator.Pdf.BindHTML(String html)
To make it work, I used “Lock” to prevent parallel use for the same line of code.
Code:
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
lock (lockObject)
{
pdf.BindHTML(content);
This have solved the problem but use of lock suppresses the benefits of multithreading.
Can you suggest something, so that we can use the library in multithreading environment without using Locks.
Thanks.
Hi Deepak,
Thanks for your inquiry. As suggested above, please use new DOM approach for HTML to PDF conversion and latest release i.e. Aspose.Pdf for .NET 10.1.0. It will resolve the issue, as we have recently fixed some multi-threading issues in latest release.
Moreover, please note Aspose.Pdf is multi-thread safe as long as only one thread works on a document at a time. So different threads can safely work on different documents at the same time.
Best Regards,
Thanks, your suggestion worked but now I 'm having other problem. I want table and div to be shift to next page if they are splitting across pages.
Please suggest some work around for it.
Hi Deepak,
Thanks for your feedback. We will appropriate if you please share a sample HTML here, We will look into it and will guide you accordingly.
We are sorry for the inconvenience caused.
Best Regards,
Hi Tilal
Below is the sample code.
In my HTML content, I have a table which starts from the middle of first page and ends in second page.
What I want is that if the table is overlapping the first page it should shift entirely into the starting of second page. And my desire output from HTML is PDF and RTF.
public void CreateAndSavePDF(string fullPath, string scheduleDate)
{
string content = "
My HTML with a Table
The table started from middle of the first page and ends up in second page";
content =
content+ "
This table have many rows
";
var outStream = new MemoryStream();
Pdf pdf = new Pdf();
var xElement =
new XElement("Pdf",
new XElement("Section",
new XElement("Text", new XAttribute("IsHtmlTagSupported", true),
new XElement("Segment", content))));
var xmlDoc = ToXmlDocument(xElement);
pdf.BindXML(xmlDoc, null);
pdf.Save(outStream);
}
Regards,
Deepak
Hi Deepak,
Thanks for sharing the details.
I have tried testing the scenario but I am afraid the ToXmlDocument(...) method is not defined. Can you please share some sample project and resource HTML so that we can test the scenario in our environment?
C#
string content = "<h1>My HTML with a Table </h1> <strong>The table started from middle of the first page and ends up in second page</strong>";
content = content + "<table>This table have many rows</table>";
var outStream = new MemoryStream();
Pdf pdf = new Pdf();
var xElement = new System.Xml.Linq.XElement(
"Pdf",
new System.Xml.Linq.XElement(
"Section",
new System.Xml.Linq.XElement(
"Text",
new System.Xml.Linq.XAttribute("IsHtmlTagSupported", true),
new System.Xml.Linq.XElement("Segment", content)
)
)
);
var xmlDoc = ToXmlDocument(xElement);
pdf.BindXML(xmlDoc, null);
pdf.Save(outStream);
Hi,
The sample application is attached. We need that the html tables should not split in pages while converting to pdf. The entire table should be shifted to new page when there is not sufficient space left in the current page to hold the whole table. Please help!
Thanks and Regards
Rajat
Hi Rajat,
Thanks for sharing the source code. We are looking into it and will update you soon.
Best Regards,
Hi Rajat,
I have tested your scenario with your shared documents and code using Aspose.Pdf for .NET 10.2.0 and managed to observe the reported issue. For further investigation, I have logged an issue in our issue tracking system as PDFNEWNET-38463 and also linked your request to it. We will keep you updated via this thread regarding the issue status.
Please feel free to contact us for any further assistance.
Best Regards
Hi Tilal,
Is there any update on the issue PDFNEWNET-38463?
Regards
Rajat
Hi Rajat,
Thanks for your inquiry. I am afraid your reported issue is still not resolved. As we have noticed it recently and It is pending for investigation due to other issues already under investigation and resolution. We will notify you as soon as we made some significant progress towards issue resolution.
We are sorry for the inconvenience caused.
Best Regards,
Hi Tilal,
Thanks for the humble response and the update. We have purchased the “Aspose.Total for .NET
Site Small Business Licence” for $12495 for 10 Developers. We are in trouble due to this show stopper issue. Please consider our request on priority.
Thanks
Rajat
Hi Rajat,
Thanks for your feedback. I am afraid your issue is reported recently and it is pending for investigation in the queue with other issues already under investigation/resolution. However we have recorded your concern and shared with our Product team. We will keep you updated about the issue resolution progress.
We are sorry for the inconvenience caused.
Best Regards,
Hi Tilal,
Is there update on this issue? It has been a long time since this issue was raised.
We found an alternate solution by dividing out html into pages. The style=“page-break-after: always” works while converting HTML to PDF, but it needed a lot of effort and has processing overhead in generation such HTML. We have implemented it on the cost of performance.
We still need the fix.
Thanks
Rajat
Hi Rajat,
Thanks for your patience.
As we recently have been able to notice this issue, and until or unless we have investigated and have figured out the actual reasons of this problem, we might not be able to share any timelines by which this problem will be resolved. Furthermore, please note that as a normal rule of practice, the issues are resolved in first come and first serve basis; but the problems logged/reported under Enterprise or Priority support model, have high precedence in terms of resolution, as compare to issues under normal/free support model.
Nevertheless, as soon as we have made some significant progress towards the resolution of this issue, we would be more than happy to update you with the status of correction. Please be patient and spare us little time. Your patience and comprehension is greatly appreciated in this regard. Please be patient and spare us some time. Your patience and comprehension is greatly appreciated in this regard.
PS, for the time being, you may consider using the workaround which you have devised.
Hi Rajat,
Thanks for your feedback. We have passed your findings with the Product team. They will consider it while investigating the issue. We will notify you as soon as we made some significant progress towards issue resolution.
Thanks for your patience and cooperation.
Best Regards,