Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am attempting to create a print preview of a document when the user selects the document from a listview. I know I need to create a print document and pass it to the printpreviewcontrol, but I don't know how to "assign" a file to the printdocument (I know my example below simply gives it a name). Is this possible? All examples I have found in forums and MSDN deal with basic textfiles. For example, how to printpreview office docs, pdf, etc.?
Imports System.Windows.Forms
Imports System.Drawing.Printing.PrintDocument
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PrintDocument1.DocumentName = "C:\Documents and Settings\Practice.xlsx"
PrintPreviewControl1.Document = PrintDocument1
End Sub
End Class
Any help would be appreciated. I feel like I am missing something simple. Thanks!
The PrintDocument object, despite its name, is not a document "reader." The only thing it does is manage the printing process for whatever thing it is that you want to print. The "thing" you want to print can be anything, and the way you print it is by making GDI+ graphics calls, like "draw a line from here to here" and "put this text here at this size." In other words, you create the printed document by calling methods on a System.Drawing.Graphics.Graphics
object.
So, in order to load a PDF, Word Doc, or any other "document" format, you will need to find a library that allows you to render the document using GDI+. A quick Google search turned up PDFRasterizer.Net for PDF files, for example.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.