Support password-protected PDF #155 #765

QL will display a UI prompting for a password. Upon entering the correct password, the PDF file will be reopened.
This commit is contained in:
ema
2024-12-13 11:23:57 +08:00
parent d09e9c48d8
commit cb59a3d082
7 changed files with 225 additions and 13 deletions

View File

@@ -213,13 +213,13 @@ public partial class PdfViewerControl : UserControl, INotifyPropertyChanged, IDi
}
}
public static Size GetDesiredControlSizeByFirstPage(string path)
public static Size GetDesiredControlSizeByFirstPage(string path, string password = null)
{
Size size;
using (var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (var tempHandle = PdfDocument.Load(s))
using (var tempHandle = PdfDocument.Load(s, password))
{
size = new Size(0, 0);
tempHandle.PageSizes.Take(5).ForEach(p =>
@@ -236,10 +236,10 @@ public partial class PdfViewerControl : UserControl, INotifyPropertyChanged, IDi
return new Size(size.Width * 3, size.Height * 3);
}
public void LoadPdf(string path)
public void LoadPdf(string path, string password = null)
{
var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
PdfDocumentWrapper = new PdfDocumentWrapper(stream);
PdfDocumentWrapper = new PdfDocumentWrapper(stream, password);
_pdfLoaded = true;
if (PdfDocumentWrapper.PdfDocument.PageCount < 2)