c# - 确定具有云文件路径的 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/
如果需要更多信息,请告诉我。
解决方案
您可以尝试将 .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 结果:
推荐阅读
- c++ - 将结构数组从 C++ 传递到 GO
- git - Git从URI获取新分支而不将其添加为远程
- c# - 视图绑定给出了一条消息,但一切正常
- javascript - 如何让网页立即进入全屏
- android - 独特的协程 Kotlin
- google-cloud-run - 将 Cloud Run 实例连接到外部 RabbitMQ 实例 (CloudAMQP)
- google-sheets - 我可以根据位于同一文件中但在谷歌表格中的其他工作表上的单元格设置条件格式吗?
- html - 处理可能不足以容纳包装器宽度的图像
- java - 应该为 vscode 设置什么 java.testMethod 来运行 junit 测试
- c++ - QNetworkAccessManager 和 cookie