public FileResult Download()
{
var doc = new EO.Pdf.PdfDocument();
EO.Pdf.HtmlToPdf.ConvertUrl("http://www.google.com/", doc);
var ms = new MemoryStream();
doc.Save(ms);
ms.Position = 0;
return new FileStreamResult(ms, "application/pdf")
{
FileDownloadName = "download.pdf"
};
}
Can you please show if possible, how to extend the code above to be able to convert several web pages into one pdf document?
The tricky part is that we don’t know what pages a user is likely to attempt to convert.
So, hardcoding the webpages as the code above shows isn’t helping us.
Any help is greatly appreciated.
//Create a new PdfDocument object
var doc = new EO.Pdf.PdfDocument();
//Convert two ore more different pages into the same PdfDocument
EO.Pdf.HtmlToPdf.ConvertUrl("c:\\1.html", doc);
EO.Pdf.HtmlToPdf.ConvertUrl("c:\\2.html", doc);
Latest code:
public FileResult Download()
{
var doc = new EO.Pdf.PdfDocument();
foreach(var url in passedUrls)
{
EO.Pdf.HtmlToPdf.ConvertUrl(url, doc);
doc.Save(ms);
}
ms.Position = 0;
return new FileStreamResult(ms, "application/pdf")
{
FileDownloadName = "download.pdf"
};
}
Latest from Adam (thank you sir)
public FileResult Download()
{
var documents = new List<EO.Pdf.PdfDocument>();
foreach(var url in passedUrls)
{
var doc = new EO.Pdf.PdfDocument();
EO.Pdf.HtmlToPdf.ConvertUrl(url, doc);
documents.Add(doc);
}
EO.Pdf.PdfDocument mergedDocument = EO.Pdf.PdfDocument.Merge(documents.ToArray());
}
Hopefully, others find these codes useful.
Based on the Help documentation I would recommend the following: