打印预览不显示文件

时间:2013-08-10 17:30:02

标签: vb.net

我正在处理菜单条Print Preview事件。我制定了以下过程来查看与我的工作簿位于同一路径的pdf文件。

    Private WithEvents docPrint As New PrintDocument()
' Declare a string to hold the entire document contents. 
Private documentContents As String

' Declare a variable to hold the portion of the document that 
' is not printed. 
Private stringToPrint As String

Private Sub ReadDocument()

    Dim xlWBPath As String = Globals.ThisWorkbook.Application.ActiveWorkbook.Path
    Dim docName As String = xlWBPath & "\" & "CustomRanges.pdf"

    docPrint.DocumentName = docName

    Dim stream As New FileStream(docName, FileMode.Open)
    Try
        Dim reader As New StreamReader(stream)
        Try
            documentContents = reader.ReadToEnd()
        Finally
            reader.Dispose()
        End Try
    Finally
        stream.Dispose()
    End Try
    stringToPrint = documentContents

End Sub

Private Sub prnPrvStripCustomRange_Click(sender As Object, e As EventArgs) Handles prnPrvStripCustomRanges.Click


    ReadDocument()
    prnPrvCustomRanges.Document = docPrint
    prnPrvCustomRanges.ShowDialog()


End Sub

单击时弹出对话框,但我的文档页面为空白。我有另一个打印事件,那个打印相同的文档。所以我不明白我在预览中做错了什么。

这是我的打印程序:

Private Sub prnCustonPages_Click(sender As Object, e As EventArgs) Handles prnCustonPages.Click

Dim xlWBPath As String = Globals.ThisWorkbook.Application.ActiveWorkbook.Path
Dim docName As String = xlWBPath & "\" & "CustomRanges.pdf"


docPrint.DocumentName = docName

prnPrtCustomRanges.Document = docPrint
prnPrtCustomRanges.PrinterSettings = docPrint.PrinterSettings
prnPrtCustomRanges.AllowSomePages = True

If prnPrtCustomRanges.ShowDialog = DialogResult.OK Then
    docPrint.PrinterSettings = prnPrtCustomRanges.PrinterSettings
    docPrint.Print()


End If

End Sub

0 个答案:

没有答案