Most PDF's convert to images quickly.
The currently attached PDF takes a very long time (a few minutes per page). Is there anything that can be done?
Here is the code I'm using:
using (var doc = new PdfDocument())
{
doc.LoadFromStream(stream);
for (var pageCount = 0; pageCount < doc.Pages.Count; pageCount++)
{
using (var img = doc.SaveAsImage(pageCount, PdfImageType.Metafile, 150, 150))
{
using (var ms = new MemoryStream())
{
if (rpt.Watermark)
{
using (Graphics G = Graphics.FromImage(img))
{
G.DrawString(rpt.WatermarkText, footFont, new SolidBrush(Color.FromArgb(opacity, Color.Black)), 0, img.Height - 20);
img.Save(ms, ImageFormat.Png); //saving before Graphics is disposed
}
}
else
{
img.Save(ms, ImageFormat.Png);
}
}
}
}
}