Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When I run a PrintDocument.Print() method and specify an Adobe PDF printer in the PrinterName attribute, I get an error. The exact error depends on which function I use. If I run a PrintPreview method, override the print button, then print using the PrintDocument.Print method I get an exception "The parameter is incorrect".

If I run a PrintDoc.Print method directly I get the exception:

An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: Illegal characters in path.

I only seem to get this error when I set a PrinterSettings object with a printer other than the Adobe PDF printer (i.e. the PC's default printer, display a PrintDialog and the user selects the Adobe Printer. Otherwise I don't have a problem. Any Ideas to why I am getting the exception?

Thank you
Posted
Comments
Sergey Alexandrovich Kryukov 6-Nov-14 18:37pm    
I have no idea why you have any illegal character in the path, because it's unclear where did you managed to make use of any path. How anyone could possibly find out anything, without having appropriate code sample?
Normally, it does no matter what printer you use, as soon as that printers works at all.
—SA
MBroder 6-Nov-14 18:43pm    
I apologize, if someone has seen the problem before, they would recognize it from the symptoms I have described. If you have seen the symptoms I have described, please comment on how you solved the problem. I will add a code snippet.
MBroder 6-Nov-14 18:46pm    
Here is the print method. It is in a base class that I generate derived classes from:

Public Function Print(ByVal ShowDialog As Boolean) As DialogResult
Dim rr As DialogResult = DialogResult.OK

Try
If ShowDialog = True Then
pDlg = New PrintDialog()
pDlg.PrinterSettings = pDoc.PrinterSettings
pDlg.Document = pDoc
rr = pDlg.ShowDialog
If rr <> DialogResult.OK Then
Return rr
End If
End If

pDoc.Print()
Catch ex As Exception
MessageBox.Show(ex.Message)
rr = DialogResult.Abort
End Try

Close()

Return rr
End Function
MBroder 6-Nov-14 18:48pm    
I should also point out that the exceptions occur between pDoc's BeginPrint and PrintPage events.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900