Hi There,
Hi Rushdeep,
Thanks for your inquiry and sharing code snippet.
I am afraid that you are using an old Aspose.Pdf.Generator approach to generate PDF from HTML. Whereas it is strongly recommended to use new Aspose.Pdf (DOM) approach as old Aspose.Pdf.Generator model is going to be obsolete soon. I have tested the scenario at my side using new approach and did not notice any issue as output file was generated just in 3 seconds. Please check following code snippet that I have used to perform the conversion.
Aspose.Pdf.MarginInfo marginInfo = new Aspose.Pdf.MarginInfo();
marginInfo.Top = 24;
marginInfo.Bottom = 24;
marginInfo.Left = 24;
marginInfo.Right = 24;
var html = @"this is html";
var pdfDocument = new Document();
var currentPage = pdfDocument.Pages.Add();
var htmlFragment = new HtmlFragment(html);
currentPage.Paragraphs.Add(htmlFragment);
pdfDocument.Save(dataDir + "HTMLToPDF1_out.pdf");
You may also find more information regarding HTML to PDF conversion by new DOM approach in our “Convert HTML to PDF” and “Add HTML String using DOM” articles of API documentation. Please try using above approach for conversion process and in a case if you still face any issue please share your sample HTML string so that we can try to test the scenario in our environment and respond you accordingly.
Best Regards,
Hi Asad,
Hi Rushdeep,
Thanks for sharing input HMTL file and more details with us. I have tested the whole scenario as per your requirement and did not notice any issue. I have added the HTML inside the document 15 times in a loop and it only took 30 seconds to save the document. I have used following code snippet to achieve the functionality.
string bodyContent = File.ReadAllText(dataDir + “ASPOSE.HTML”);
Aspose.Pdf.MarginInfo marginInfo = new Aspose.Pdf.MarginInfo();
marginInfo.Top = 24;
marginInfo.Bottom = 24;
marginInfo.Left = 24;
marginInfo.Right = 24;
var html = bodyContent;
var pdfDocument = new Document();
var currentPage = pdfDocument.Pages.Add();
currentPage.PageInfo.Margin = marginInfo;
for (int i = 0; i < 15; i++)
{
var htmlFragment = new HtmlFragment(html);
currentPage.Paragraphs.Add(htmlFragment);
}
pdfDocument.Save(dataDir + "HTMLToPDF1_out.pdf");
Please note that I have used Aspose.Pdf for .NET 17.3.0 to implement the functionality and also I have tested the scenario on Windows 10 X64 based system. I have attached an generated output by above code for your reference. I would also like to share that the performance of the API depends upon many factors to be noticed i.e. Structure and Complexity of input file, the version of API, the environment on which you are using API, the system configurations etc.
Please try using above code to add HTML inside PDF document and in case if you still face any issue please share your environment details with us so that we can try to reproduce the issue at our side.
Best Regards,
Hi Asad,
Hi Rushdeep,
rushdeep:
can you do your test with version 10 and see what the results are ?
rushdeep:
I am using Aspose dll version 10, when I download version 17.3.0, its not compatible with my license file