Click here to Skip to main content
15,921,837 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

Is it possible to load a file from a local folder and display it using the Print Preview Dialog?

I have spent some time investigating ways to do this and tried various ways of coding but I have had no luck.

Is what I'm trying to do even possible or can the Print Preview Dialog only be used with a text file created within the code?

What I have tried:

various modifications of code samples found online and reading Microsoft documentation.
Updated 20-Mar-23 5:30am
Dave Kreskowiak 20-Mar-23 13:49pm    
If you're thinking the PrintPreviewDialog can render any document you try to throw at it in the form of a file, then NO, that will not work. It will only show what your code draws.

1 solution

The PrintPreviewDialog only works with a PrintDocument - it's there to show the user what his output might look like before he commits to paper.

As such, it can show data from anywhere - it's entirely up to you as the developer to write and draw onto the PrintDocument whatever you need to print or otherwise show, and where and how you draw the lines and text is completely under your control.

So if you want to display a file, you will need to read it, process it according to it's file type (Word files for example are very different from text files, and neither of those even vaguely resemble an image file or a PDF!) then draw on the PrintDocument using the Graphics context provided to you in the PrintPageEventArgs parameter of the PrintPage event handler.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900