Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 使用一个Printdocument打印多个多页文件_Vb.net_Printdocument - Fatal编程技术网

Vb.net 使用一个Printdocument打印多个多页文件

Vb.net 使用一个Printdocument打印多个多页文件,vb.net,printdocument,Vb.net,Printdocument,我想打印多页.tiff文件的列表。我遇到的问题是,我没有得到多页,只有第一页得到“打印”。有人能指出我到底做错了什么吗 Private Sub docPrintPage(sender As Object, e As PrintPageEventArgs) For Each filName As String In fileN Dim m_Image As Image = Image.FromFile(filName) Dim pc As Integer

我想打印
多页.tiff文件的列表
。我遇到的问题是,我没有得到多页,只有第一页得到“打印”。有人能指出我到底做错了什么吗

Private Sub docPrintPage(sender As Object, e As PrintPageEventArgs)

    For Each filName As String In fileN
        Dim m_Image As Image = Image.FromFile(filName)
        Dim pc As Integer = 0
        Dim currPage As Integer = 0

        pc = m_Image.GetFrameCount(FrameDimension.Page)

        While (currPage < pc)
            m_Image.SelectActiveFrame(FrameDimension.Page, currPage)
            e.Graphics.DrawImage(m_Image, e.PageBounds) 'Most likely the problem lies here

            currPage = currPage + 1
            e.HasMorePages = true

        End While
    Next
    e.HasMorePages = false
 End Sub

我的最终目标:在打印预览中显示一系列(列表)多帧.tiff。

您可以使用此伪代码(抱歉,我无法重新创建您的情况):

Dim intFileToPrint as Integer=0
Dim intPageToPrint作为整数=0
Dim INTPAGE打印为整数=0
私有子打印预览()
对于intFileToPrint=0到fileN.Count-1
intPageToPrint=Image.FromFile(fileN(intFileToPrint)).GetFrameCount(FrameDimension.Page)
intPagePrinted=0
AddHandler yourPrintDocument.PrintPage,打印文件的地址
yourPrintDocument.Print()
端接头
端接头
私有打印文件(ByVal sender作为对象,ByVal e作为PrintPageEventArgs)
将imgToPrint设置为Image=Image.FromFile(fileN(intFileToPrint))。选择活动框架(FrameDimension.Page,intpageprint)
e、 Graphics.DrawImage(imgToPrint,e.PageBounds)
intPagePrinted=intPagePrinted+1
如果intPagePrinted
多亏了下面的帖子,我成功地解决了这个问题:

首先创建以下类变量

Private fileCount As Integer = 0 // Index of the current file/Image
Private currPage As Integer = 0 // Current Page in the current file/Image
Private pCount As Integer = 0 // PageCount in the current file/Image
Private currImage As Image // My Current Image
创建新的PrintDocument(在某些函数中)并将其分配给PrintPreviewDialog

    Dim vPrintDoc As New PrintDocument
    vPrintDoc.DefaultPageSettings.Landscape = False

    AddHandler vPrintDoc.PrintPage, AddressOf docPrintPage
    AddHandler vPrintDoc.BeginPrint, AddressOf docBeginprint


    Dim i As PrintPreviewDialog = New PrintPreviewDialog
    i.Document = vPrintDoc
    i.ShowDialog()
在方法
docBeginPrint
中,您将类变量(之前声明的)设置为第一个(如果存在)的stats

'然后在docPrintPage中开始打印

Private Sub docPrintPage(sender As Object, e As PrintPageEventArgs)

    currImage.SelectActiveFrame(FrameDimension.Page, currPage) 'Set the Active Frame of your image to that of the following frame that needs to printed.

    Using st As MemoryStream = New MemoryStream() 'We use a memory stream to print Images in order to avoid a bug inside the e.graphics.

        currImage.Save(st, ImageFormat.Bmp)
        Dim bmp As Bitmap = CType(Image.FromStream(st), Bitmap)
        e.Graphics.DrawImage(bmp, 0, 0)
        bmp.Dispose()

    End Using

    currPage += 1 'Current page is printed, increase index with 1

    If currPage < pCount Then 'Are there any further pages in the current image?
        e.HasMorePages = True 'yes continue printing
    Else 'no 
        If fileCount = (fileN.Count - 1) Then 'Hase the list anymore files?
            e.HasMorePages = False 'No - stop printing all together
        Else 'yes
            currPage = 0 'Set your index for the current page back to first
            fileCount += 1 'Increase the index of the current file
            currImage = Image.FromFile(fileN.Item(fileCount)) 'Load the next image (Perhaps if-statements is desired to avoid Null-Reference)
            pCount = currImage.GetFrameCount(FrameDimension.Page) 'Load the pagecount of the current image

            e.HasMorePages = True 'continue printing
        End If
    End If
End Sub
Private Sub-docPrintPage(发送方作为对象,e作为PrintPageEventArgs)
currImage.选择活动框架(FrameDimension.Page,currPage)'将图像的活动框架设置为需要打印的下一个框架的活动框架。
使用st As MemoryStream=New MemoryStream()'我们使用内存流打印图像,以避免e.graphics中出现错误。
currImage.Save(st,ImageFormat.Bmp)
将bmp变暗为位图=CType(Image.FromStream(st),位图)
e、 Graphics.DrawImage(bmp,0,0)
bmp.Dispose()
终端使用
currPage+=1'打印当前页面,增加索引1
如果currPage

我希望这可能对其他人有用。

为什么设置
e.HasMorePages=false
从其他方面看,它一直使用docPrintPage方法添加页面。e、 HasMorePages最终必须设置为false。众多引用中的一个:Ref:您到底想要什么?在每个打印页面上打印一个tiff页面?因为PrintPage事件打印一个页面,但您正在尝试打印多个tiff页面,然后退出并指定HasMorePages=False,这是不正确的。实际上,我的最终目标是每页打印一个tiff。tiff内的每个框架都是A4大小。问题在于存在多个文件和多个帧,并在打印预览中显示。显示一个多帧。tiff不是问题,它显示的是一个列表删除代码和tryprety—这正是我搜索的内容!:)你的代码给了我一个很好的想法去尝试!是的!将立即发布我的调整代码:)
    Dim vPrintDoc As New PrintDocument
    vPrintDoc.DefaultPageSettings.Landscape = False

    AddHandler vPrintDoc.PrintPage, AddressOf docPrintPage
    AddHandler vPrintDoc.BeginPrint, AddressOf docBeginprint


    Dim i As PrintPreviewDialog = New PrintPreviewDialog
    i.Document = vPrintDoc
    i.ShowDialog()
Private Sub docBeginprint(sender As Object, e As PrintEventArgs)

    If fileN.Count > 0 Then
        currPage = 0
        currImage = Image.FromFile(fileN.Item(0))
        pCount = currImage.GetFrameCount(FrameDimension.Page)
    End If

End Sub
Private Sub docPrintPage(sender As Object, e As PrintPageEventArgs)

    currImage.SelectActiveFrame(FrameDimension.Page, currPage) 'Set the Active Frame of your image to that of the following frame that needs to printed.

    Using st As MemoryStream = New MemoryStream() 'We use a memory stream to print Images in order to avoid a bug inside the e.graphics.

        currImage.Save(st, ImageFormat.Bmp)
        Dim bmp As Bitmap = CType(Image.FromStream(st), Bitmap)
        e.Graphics.DrawImage(bmp, 0, 0)
        bmp.Dispose()

    End Using

    currPage += 1 'Current page is printed, increase index with 1

    If currPage < pCount Then 'Are there any further pages in the current image?
        e.HasMorePages = True 'yes continue printing
    Else 'no 
        If fileCount = (fileN.Count - 1) Then 'Hase the list anymore files?
            e.HasMorePages = False 'No - stop printing all together
        Else 'yes
            currPage = 0 'Set your index for the current page back to first
            fileCount += 1 'Increase the index of the current file
            currImage = Image.FromFile(fileN.Item(fileCount)) 'Load the next image (Perhaps if-statements is desired to avoid Null-Reference)
            pCount = currImage.GetFrameCount(FrameDimension.Page) 'Load the pagecount of the current image

            e.HasMorePages = True 'continue printing
        End If
    End If
End Sub