Printing Password protected file
Hi, I can open a password protected file, but when i try to print it the file cannot be printed, Even if the file is visible it cannot be printed. Ask the password again.
Any Solution?
Thanks a lot
Hi Andrea De Luca,
Thank you for contacting us.
To investigate the issue, where a password‑protected PDF opens correctly but cannot be printed and prompts for the password again, could you please provide us with a few additional details?
- Which Syncfusion PDF Viewer platform are you using?
- Product version of the PDF Viewer control you are currently using?
- A simple replication sample (if possible) that demonstrates the issue.
- Any specific steps you follow before the issue appears.
These details will help us analyze the scenario accurately and provide the appropriate solution.
We look forward to your response.
Regards,
Bharathi S
Hi, the plartform is WinUI. the version of pdf viewer is 32.2462.3.0.
The code:
Private Function PrintPDF(ByVal FilePDF As String, Optional PassDoc As String = "") As Integer Dim dialog As New PrintDialog(), docPdf As New PdfDocumentView(), NumPagine As Integer Using docPdf With dialog Try Dim a As New PdfLoadedDocument(FilePDF, PassDoc) If a.Security.UserPassword = String.Empty Then docPdf.Load(FilePDF, PassDoc) Else Dim PswDoc As String = InputBox("Type the Password to print the document", "") If PswDoc.Length > 0 Then StampaPDF(FilePDF, PswDoc) Else docPdf = Nothing End If End If Catch ex As Exception 'Syncfusion.Pdf.PdfDocumentException Dim PswDoc As String = InputBox("Type the Password to print the document","")
If PswDoc.Length > 0 Then
PrintPDF(FilePDF, PswDoc)
Else docPdf = Nothing End If End Try If docPdf IsNot Nothing Then .Document = docPdf.PrintDocument .Document.DocumentName = Path.GetFileName(FilePDF) .PrinterSettings.Collate = True docPdf.PrinterSettings.PageSize = PdfViewerPrintSize.Fit If ImpostazioniStampa Is Nothing Then .PrinterSettings.Duplex = Duplex.Simplex If ChkStampaFR.Checked Then .PrinterSettings.Duplex = Duplex.Horizontal If RBtnLatoLungo.Checked Then .PrinterSettings.Duplex = Duplex.Vertical End If docPdf.PrinterSettings.Copies = NumUD_NumCopie.Value Else .PrinterSettings = ImpostazioniStampa End If If RbtnIntervallo.Checked Then .PrinterSettings.FromPage = NudPagineDa.Value .PrinterSettings.ToPage = NudPagineA.Value ElseIf RbtnPaginaCorrente.Checked Then If TabControl1.Visible Then Dim PDF_Viewer As PdfViewerControl = TabControl1.SelectedTab.Controls(0) .PrinterSettings.FromPage = PDF_Viewer.CurrentPageIndex .PrinterSettings.ToPage = PDF_Viewer.CurrentPageIndex Else .PrinterSettings.FromPage = PdfViewerControl1.CurrentPageIndex .PrinterSettings.ToPage = PdfViewerControl1.CurrentPageIndex End If End If docPdf.PrinterSettings.Copies = NumUD_NumCopie.Value Else .PrinterSettings = ImpostazioniStampa End If ' .PrinterSettings.Collate = True docPdf.Print(StatLblNomeStampante.Text) NumPagine = docPdf.PageCount * NumUD_NumCopie.Value docPdf.Unload() End If End With dialog.Dispose() End Using Return NumPagine End Function
Hi Andrea,
Thank you for sharing the additional details and the code snippet.
We would like to clarify that Syncfusion
does not provide a direct PDF Viewer control for the WinUI platform. The
PDF Viewer can be used in a WinUI application only by embedding the .NET
MAUI PDF Viewer into a native WinUI application, as described in the
following KB article:
Integrate .NET MAUI PDF Viewer in native WinUI app | Syncfusion
The APIs used in your shared code snippet (such as Load, Unload, CurrentPageIndex, PrinterSettings, and related printing APIs) are not available in the .NET MAUI PDF Viewer.
Additionally, the version you mentioned (32.2462.3.0) is not available on NuGet.org for the .NET MAUI PDF Viewer. Could you please confirm:
- Whether you are using the .NET MAUI PDF Viewer embedded in a native WinUI application as per the above KB article, and
- In which platform NuGet the mentioned version (32.2462.3.0) available.
This information will help us accurately understand your implementation and guide you with the appropriate approach for your platform.
We appreciate your clarification and look forward to assisting you further.
Regards,
Bharathi S
Yes, it was my mistake. It' s a Windows forms application.
Hi Andrea De Luca,
We were unable to reproduce the reported issues with the information provided. For your reference, we've attached a sample we used to attempt to replicate the issue. If you continue to experience the problem, please modify the sample as needed and share it with us. This will help us conduct a more thorough investigation.
Regards,
Yaminisri M
Attachment: Password_issue_vb_(2)_65ebde54.zip
Printing a password-protected file requires first unlocking it by entering the correct password, since most printers and applications cannot process encrypted or restricted documents directly; once the password is entered, the file can be opened, previewed, and printed like any regular document, while ensuring that sensitive information remains secure, and for more guidance you can always visit site.
Wonderful!
It Works, it was easier then I thought.
Thank You very much indeed
Hi Arham Asif,
The password prompt appears only when opening an encrypted document, not when printing it. This is the default behavior of the WinForms PDF Viewer. The same behavior can be observed in both Adobe Acrobat Reader and the Microsoft Edge browser.
If you want to enforce password authentication during printing, this can be achieved by adding a custom button that prompts for a password and then implements the printing functionality using the Print() API. We have attached the UG link for your reference.
Printing PDF in WinForms PDF Viewer | Syncfusion®
Regards,
Lingeshwaran S
Yes, i Know, but in my SW I print the PDFs from a list and not directly from a PDFViewer control.
With one click a print more the one file at the same time.
At the end my code is this:
Private Function StampaPDF(ByVal FilePDF As String, Optional PassPdf As String = "") As Integer
Dim dialog As New PrintDialog(), docPdf As New PdfDocumentView(), NumPagine As Integer
Dim ProtectedPDF As Boolean = False
If PassPdf.Length = 0 Then
If Path.Combine(PdfViewerControl1.DocumentInformation.FilePath, PdfViewerControl1.DocumentInformation.FileName) = FilePDF Then
PdfViewerControl1.LoadedDocument.Security.UserPassword = String.Empty
docPdf.Load(PdfViewerControl1.LoadedDocument)
End If
If docPdf IsNot Nothing Then
Try
docPdf.Load(FilePDF)
Catch ex As Syncfusion.Pdf.PdfInvalidPasswordException
ProtectedPDF = True
End Try
End If
Else
Try
Dim loadedDoc As New PdfLoadedDocument(FilePDF, PassPdf)
loadedDoc.Security.UserPassword = String.Empty
docPdf.Load(FilePDF, PassPdf)
Catch ex As Syncfusion.Pdf.PdfInvalidPasswordException
MsgBox("The password for the file " & Path.GetFileName(FilePDF) & " is wrong", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "Stampa PDF")
docPdf = Nothing
End Try
End If
If DocProtetto Then
Dim Password As String = InputBox("The file " & Path.GetFileName(FilePDF) & " is password protected" & Environment.NewLine &
"Type the password")
If Password <> String.Empty Then
StampaPDF(FilePDF, Password)
Else
docPdf = Nothing
End If
End If
If docPdf IsNot Nothing Then
'Print the document
end if
End Function
Hi Andrea De Luca,
After reviewing the code, we recommend loading the PDF document as a stream instead of directly loading the PdfLoadedDocument from the PDF Viewer. Loading the PdfLoadedDocument directly from the viewer is not a recommended or best practice.
Additionally, to print the document, please make sure to use the Print() API. Using the appropriate printing API will ensure the document is printed correctly.
Regards,
Lingeshwaran S
- 11 Replies
- 5 Participants
-
AD Andrea De Luca
- Mar 23, 2026 05:16 PM UTC
- Apr 3, 2026 07:41 AM UTC