You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PDFSharp操作PDF在Edge 137/138版本中所有者密码验证异常问题求助

PDFSharp操作PDF在Edge 137/138版本中所有者密码验证异常问题求助

大家好,我用PDFSharp处理加密PDF的代码在大部分浏览器里都能正常运行,但在Edge 137和138版本遇到了奇怪的问题:这两个版本的Edge会反复要求输入所有者密码,而且我明明输入的是正确密码,系统却提示密码错误。

下面是我用来打开PDF并设置安全属性的代码:

string aiPolicyText = "你的AI政策文本"; // 假设变量已提前定义
string disclaimerText = "你的免责声明文本"; // 假设变量已提前定义

using (PdfDocument pdfDocument = PdfReader.Open(path, "passwor123", PdfDocumentOpenMode.Modify)) 
{ 
    XFont font = new XFont("HELVETICA", 6F); 
    XBrush brush = XBrushes.Black; 

    for (int i = 1; i < pdfDocument.Pages.Count; ++i) 
    { 
        PdfPage page = pdfDocument.Pages[i]; 
        float pageWidth = (float)page.Width; 
        float pageHeight = (float)page.Height; 

        float aiWidth = GetTextWidthInPoints(aiPolicyText); 
        float n2 = (pageWidth - aiWidth) / 2F; 
        float n3 = 10F; 
        XRect layoutRectangle = new XRect(n2, n3, aiWidth, 12); 
        using (XGraphics gfx = XGraphics.FromPdfPage(page)) 
        { 
            gfx.DrawString( 
                aiPolicyText, font, brush, layoutRectangle, XStringFormats.Center); 
        } 

        float disclaimerWidth = GetTextWidthInPoints(disclaimerText); 
        float n4 = (pageWidth - disclaimerWidth) / 2F; 
        float n5 = 16; 
        XRect layoutRectangle2 = new XRect(n4, n5, disclaimerWidth, 12); 
        using (XGraphics gfx = XGraphics.FromPdfPage(page)) 
        { 
            gfx.DrawString( 
                disclaimerText, font, brush, layoutRectangle2, XStringFormats.Center); 
        } 
    } 

    pdfDocument.SecuritySettings.OwnerPassword = "passwor123"; 
    pdfDocument.SecuritySettings.PermitExtractContent = false; 
    pdfDocument.SecuritySettings.PermitFormsFill = false; 
    pdfDocument.SecuritySettings.PermitModifyDocument = false; 
    pdfDocument.SecuritySettings.PermitExtractContent = true; // 这里我注意到先设为false又改回true,暂时不确定是否影响,提出来供参考
    pdfDocument.SecuritySettings.PermitPrint = true; 
    pdfDocument.SecuritySettings.PermitFullQualityPrint = true; 
    pdfDocument.SecurityHandler.SetEncryptionToV4UsingRC4(false); 

    using (MemoryStream stream = new MemoryStream()) 
    { 
        pdfDocument.Save(stream, false); 
        byte[] b = stream.ToArray(); 
    } 
}

我已经核对过代码里的密码一致性,打开PDF和设置所有者密码用的都是同一个"passwor123",而且Chrome、Firefox等其他浏览器都能正常识别密码,只有Edge 137和138版本会出现这个问题。有没有朋友遇到过类似的情况?或者对PDFSharp的安全设置和Edge的兼容性有了解的,能不能给我一些解决思路?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 07:23:01