gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:38:26 28 4
gpt4 key购买 nike

我想打印多页.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

变量的一些解释:

fileN: List of paths to my files
pc: pagecount/framecount of the current .tiff
currPage: index of the active frame in the current .tiff

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

最佳答案

由于以下帖子,我设法解决了问题:

Thank you very very much Tezzo

首先创建以下类变量

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 中,您将类变量(之前声明的)设置为第一个(如果存在)的统计信息

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

'然后在您的 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

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

关于vb.net - 使用一个 Printdocument 打印多个多页文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24818885/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com