so basically what my task is like below.
My application is able to print multiple files with a different format in single preview and print button, files can be an image, pdf or doc.
so for that, I put below logic for printing and showing print preview option.
List<string> elements = new List<string>();
private int ElementCounter;
private int page;
private void button1_Click(object sender, EventArgs e)
{
try
{
var Files = new DirectoryInfo(@"E:\Desktop\").GetFilesByExtensions(".png", ".pdf",".doc",".docx");
foreach (FileInfo file in Files)
{
elements.Add(file.FullName);
ElementCounter++;
}
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
try
{
e.Graphics.DrawImage(Image.FromFile(elements[page]),e.MarginBounds);
page++;
e.HasMorePages = page < elements.Count;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void printDocument1_BeginPrint(object sender, PrintEventArgs e)
{
page = 0;
}
but above code is working fine only for images I am not able to show a preview of pdf and doc files. so my question is how can I show a preview of all pdf files and doc files
Any help I will highly appreciate