How to print a document using PrintDialog in C #

Here is my sample code. But its printing a blank page

            printDocument1.DocumentName = "C:\a.pbf";// PrintDocument printDocument1
            printDialog1.Document = printDocument1;
            printDialog1.AllowPrintToFile = true;
            printDialog1.AllowSelection = true;
            printDialog1.AllowSomePages = true;
            printDialog1.PrintToFile = true;
            if (printDialog1.ShowDialog() == DialogResult.OK)
                printDocument1.Print();

What is wrong with that? Please help me

+5
source share
1 answer

You need to handle the event PrintPageto actually provide the content; MSDN has a complete example . DocumentName- this is just something that can show the user - this is not the path to the file, which will be called magically.

To print an existing PDF, maybe see this question

+6
source

All Articles