PrintTicket提供程序无法将PrintTicket转换为DEVMODE [英] PrintTicket provider failed to convert PrintTicket to DEVMODE

查看:1072
本文介绍了PrintTicket提供程序无法将PrintTicket转换为DEVMODE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好几年前,我写了一个WPF(基于Visual Basic 2012)的应用程序,其中包括"打印"。一些报告使用标准WPF printdialogs / paginators / features ....
$
从那以后(2011/2015),每个工作都很好,我没有更改该工作代码的一行...

现在我不得不改变一些东西(不是打印相关的)到那个项目,当然我也检查了打印功能......
现在
"打印"代码在使用时失败...实际上不是"paginator"代码,但访问PrintTicket / Que对象失败报告

"PrintTicket提供程序无法将PrintTicket转换为DEVMODE。 Win32错误:参数不正确。  " b $ b b $ b b b b b b b b b b b g g g it it it it it it it it it it it it it it it实例"PDF Creator"虚拟打印机,它无法写入/设置我的Que对象的某些属性而不是其他属性,而在其他打印机上使用不同的打印机失败...例如,
,PDF Creator虚拟打印机:

1)myQue.DefaultPrintTicket = myTicket = OK

2)myQue.CurrentJobSettings.Description =" some title" =某些打印机确定,FAILS使用不同的打印机但


但是2)仅在第一次设置时失败,我可以"解析" "循环"小时间睡了几次....再次,第二次或第三次成功...所以我写了一个丑陋的代码,如

hi all,
few years ago I wrote a WPF (Visual Basic 2012 based) app which included "printing" some report using standard WPF printdialogs/paginators/features....
everyting worked fine since then (2011/2015), and I did not change a line of that working code...
Now I had to change something (not printing related) to that project and of course I checked the printing features as well...
now the "printing" code fails when using it... actually is not the "paginator" code, but accessing the PrintTicket/Que objects fails reporting
"PrintTicket provider failed to convert PrintTicket to DEVMODE. Win32 error: The parameter is incorrect.  "

but it's weird as it does not always fail, and it fails differently with different printers...
using for instance "PDF Creator" virtual printer, it fails writing/settings some properties of my Que object and not others, while using a different printer fails on others...
for instance, PDF Creator virtual printer:
1) myQue.DefaultPrintTicket = myTicket = OK
2) myQue.CurrentJobSettings.Description = "some title" = OK with some printer, FAILS with a different printer

but 2) only fails the very first time it is set, and I can "resolve" "looping" a few times with a minor time sleep.... again, the second or third time it succeded... so I wrote an ugly code like

Dim myTicket As System.Printing.PrintTicket = New System.Printing.PrintTicket()
Dim myQue As System.Printing.PrintQueue = Nothing 

Dim dlg As New PrintDialog
'.....

myTicket = dlg.PrintTicket                
myQue = dlg.PrintQueue
....

' to check in a loop if the interesting 
' properties has been set
Dim ticketIsSet(1) As Boolean

For iLoop As Integer = 1 To 5
    'it can fail with DEVMODE = NULL
    Try
        If Not ticketIsSet(0) Then
            myQue.DefaultPrintTicket = myTicket
            ticketIsSet(0) = True
        End If

        If Not ticketIsSet(1) Then
            myQue.CurrentJobSettings.Description = Me.Title
            ticketIsSet(1) = True
        End If
    Catch ex As Exception
        Errors.Add(ex.Message)
        System.Threading.Thread.CurrentThread.Sleep(1000)
    End Try
    If ticketIsSet(0) AndAlso ticketIsSet(1) Then Exit For
Next
If Errors.Count Then
    ' it's still ok if title can't be set... :( 
    If ticketIsSet(0) Then Errors.Clear()
End If




到目前为止,"太好了"因为我完成了工作...但只是部分...因为我的Paginator已经习惯(成功)填充System.Windows.Controls.DocumentViewer ...这个备用文档查看器窗口可以在以后实际打印,如果请求...

再次,使用不同的打印机,它成功或失败,"PrintTicket提供程序无法将PrintTicket转换为DEVMODE。 Win32错误:参数不正确。  "例外...



与PDF Creator虚拟打印机一起成功,使用不同的物理打印机失败...



我尝试了与上面相同的循环技巧,例如


so far, "so good" as I get the job done... but only partially... as my Paginator is used to (succesfully) populate a System.Windows.Controls.DocumentViewer... this alternate documentviewer window can later actually print if requested...
and again, with different printers it succed or fail with "PrintTicket provider failed to convert PrintTicket to DEVMODE. Win32 error: The parameter is incorrect.  " exception...

with PDF Creator virtual printer it succed, with a different physical printer it fails...

I tried the very same looping trick as above, like

Dim Errors As New Specialized.StringCollection
Dim bDone As Boolean = False
For iLoop As Integer = 1 To 5
    Try
        Dim writer As System.Windows.Xps.XpsDocumentWriter = System.Printing.PrintQueue.CreateXpsDocumentWriter(m_printQueue)
        writer.Write(Me.docViewer.Document.DocumentPaginator, Me.m_printTicket)
        writer = Nothing
        bDone = True
    Catch ex As Exception
        Errors.Add(ex.Message)
        System.Threading.Thread.CurrentThread.Sleep(1000)
    End Try
    If bDone Then Exit For
Next
If bDone Then Errors.Clear()
If Errors.Count <> 0 Then BasShowErrors(Errors, Me, False)




这里它失败了(再次,在某些打印机上) 

writer.Write(Me.docViewer.Document.DocumentPaginator,Me.m_printTicket)

,其中"PrintTicket提供程序无法将PrintTicket转换为DEVMODE"。 Win32错误:参数不正确。 &NBSP;"例外...



显然打印机在世界,Excel等其他程序方面还可以,而且其他所有程序都可以(不是基于WPF的)项目...而且这只是"现在"发生,因为它在初始开发时就像一个魅力... ...


我当前的设置是:
$
Win7 Ultimate sp 1

SQL 2014 Dev Edition(不相关)

Visual Studio 2012 Ultimate Version 11.0.61219.00 Update 5

Microsoft .NET Framework版本4.6.01055



我甚至试过"修复"使用NetFramwork修复工具的.NET Framework(https://www.microsoft.com/en-us/download/details.aspx?id=30135)没有成功...



任何提示都非常赞赏:)

TIA

-  

asql



http://www.hotelsole.com/asql/index.php - DbaMgr2k - DbaMgr和更多SQL工具http://www.hotelsole.com/


and here it fails (again, on some printers) on 
writer.Write(Me.docViewer.Document.DocumentPaginator, Me.m_printTicket)
with "PrintTicket provider failed to convert PrintTicket to DEVMODE. Win32 error: The parameter is incorrect.  " exception...

obviously that printer is ok as regards other programs like World, Excel and the like, and it's ok as well with all other (NOT WPF based) projects... and again this only occur "NOW", as it worked like a charme at the time of the initial development...

my current settings are:
Win7 Ultimate sp 1
SQL 2014 Dev Edition (not relevant)
Visual Studio 2012 Ultimate Version 11.0.61219.00 Update 5
Microsoft .NET Framework version 4.6.01055

I even tried "repairing" the NET Framework with NetFramwork Repair Tool (https://www.microsoft.com/en-us/download/details.aspx?id=30135) with no success...

any hint is very appreciated :)
TIA
-- 
asql


http://www.hotelsole.com/asql/index.php - DbaMgr2k - DbaMgr and further SQL Tools http://www.hotelsole.com/

推荐答案



嗨  Andrea Montanari,


Hi  Andrea Montanari,

根据您的描述,可能是错误"PrintTicket提供程序无法将DEVMODE转换为PrintTicket。


  Win32错误:参数不正确"是因为打印机驱动程序已过期。

From your description, maybe the error "PrintTicket provider failed to convert DEVMODE to PrintTicket.
 Win32 error: The parameter is incorrect" is due to out of date printer drivers.

因此,您可以与计算机制造商或打印机制造商联系,以获取更新打印机驱动程序的帮助。

So, you can contact the computer manufacturer or printer manufacturer for assistance in updating the printer driver.

此外,您可以参考以下帖子的建议。

Also, you can refer the following post's suggestion.

WPF打印例外:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/a4d6d3ef -b7a5-4bd5-aae6-98c7efe95fc3 / wpf-printing-exception?forum = wpf

最后,如果你认为这是一个bug,我建议你报告你的Connect的问题:

https://connect.microsoft.com/

At last, If you think it is a bug, I suggest you can report your question at Connect:
https://connect.microsoft.com/

最诚挚的问候,

Yohann Lu

Yohann Lu


这篇关于PrintTicket提供程序无法将PrintTicket转换为DEVMODE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆