0

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

Let's Enkindle
  • 57
  • 2
  • 17

1 Answers1

0

I would simply convert the Docs and PDFs to images, such that you can display all the formats in the same way using the working code you have now. Here is a SO post for PDF->PNG and one for DOC->PNG.

Emil L.
  • 97
  • 10