首页 > 解决方案 > 确定具有云文件路径的 PDF 文件是否受密码保护(以 https:\\ 开头的路径)

问题描述

我正在使用DotNetZip(来自 NuGet 包)。这通常适用于具有 ("@C:) 的文件路径,但是如果使用像 (https:) 这样的云文件路径,它会给我IBM437 错误。我可以使用这个包,但需要引入一些编码,这是另一个问题。

我尝试使用SharpZipLib(另一个 NuGet 包),但在 Internet 上找不到与云文件路径相关的任何信息。(http:)。

我也尝试过Spire PDF,但它会为受密码保护的 PDF 引发File doesn't exist (Parameter 'fileName') 错误

NuGet 包的 URL - DotNetZip - https://www.nuget.org/packages/DotNetZip/ SharpZipLib- https://www.nuget.org/packages/SharpZipLib.NETStandard/

如果需要更多信息,请告诉我。

标签: c#.netazurenuget-packagecloud-storage

解决方案


您可以尝试将 .pdf 文件下载为本地临时文件,然后检查是否可以在没有密码的情况下打开它。只需尝试下面的 C# 控制台应用程序:

using Spire.Pdf;
using System;
using System.IO;
using System.Net;

namespace PDFtest
{
    class Program
    {
        static void Main(string[] args)
        {
            var passwordPDFURL = "https://stantest1016.blob.core.windows.net/static/testPass.pdf";
            var noPassWordPDFURL = "https://stantest1016.blob.core.windows.net/static/testNoPass.pdf";

            var tempFilePath = "d:/temp/temp.pdf";

            //download file as a temp pdf file
            WebClient webClient = new WebClient();
            webClient.DownloadFile(passwordPDFURL, tempFilePath);
            try
            {
                PdfDocument pdf = new PdfDocument(tempFilePath);
                Console.WriteLine("PDF has been opened successfully with no password");
            }
            catch (Exception e) {

                Console.WriteLine(e.Message);
            }
            //remove temp file
            File.Delete(tempFilePath);
            
        }
    }
}

测试密码保护 .pdf 结果:

在此处输入图像描述

测试无密码保护.pdf 结果: 在此处输入图像描述


推荐阅读