We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How do you print a document?

The following code was taken from an Aspose sample and then edited to use the variable naming conventions required by my company.

The code shows how to use the print dialog allowing the user to proceed or not with a printout of the document. Is there a sample that simply shows how to go directly to the printing of a document on a button click event?

Public Shared Sub PrintDocument(ByVal docDocument As Aspose.Words.Document)

'Instantiate Print Dialog

Dim prtdlgPrintDialog As New System.Windows.Forms.PrintDialog

'Initialize Print Dialog parameters

prtdlgPrintDialog.AllowSomePages = True

prtdlgPrintDialog.PrinterSettings.MinimumPage = 1

prtdlgPrintDialog.PrinterSettings.MaximumPage = docDocument.PageCount

prtdlgPrintDialog.PrinterSettings.FromPage = 1

prtdlgPrintDialog.PrinterSettings.ToPage = docDocument.PageCount

'Check if the user accepted the print settings and proceed to preview the document

If (Not prtdlgPrintDialog.ShowDialog().Equals(DialogResult.OK)) Then

Return 'User did not accept the Print Dialog print settings

End If

'Instantiate a special Aspose.Words implementation of the .NET PrintDocument Class

Dim pdPrintDocument As New AsposeWordsPrintDocument(docDocument)

'Pass the printer settings from the Print Dialog to the Print Document

pdPrintDocument.PrinterSettings = prtdlgPrintDialog.PrinterSettings

'Create an overridden version of the .NET Print Preview Dialog to preview the document

Dim ppdPrintPreviewDialog As New ActivePrintPreviewDialog()

'Pass the Aspose.Words Print Document to the Print Preview Dialog

ppdPrintPreviewDialog.Document = pdPrintDocument

'Specify additional parameters of the Print Preview dialog

ppdPrintPreviewDialog.ShowInTaskbar = True

ppdPrintPreviewDialog.MinimizeBox = True

ppdPrintPreviewDialog.PrintPreviewControl.Zoom = 1

ppdPrintPreviewDialog.Document.DocumentName = "TestName.doc"

ppdPrintPreviewDialog.WindowState = FormWindowState.Maximized

'Show the appropriately configured Print Preview Dialog

ppdPrintPreviewDialog.ShowDialog()

End Sub

End Class

Public Class ActivePrintPreviewDialog

Inherits PrintPreviewDialog

Protected Overrides Sub OnShown(ByVal e As EventArgs)

'Brings the Print Preview dialog on top when it is initially displayed

Activate()

MyBase.OnShown(e)

End Sub

End Class

Thank you.

Hello

Thanks for your request. Please see the following link to learn how to achieve what you need:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.document.print_overload_3.html

Best regards,

The code you suggested worked fine. Thank you.