相关疑难解决方法(0)

无效pdfexception未找到pdf标头签名

我有一些代码可以读取pdf文件.代码在该行失败:

iTextSharp.text.pdf.PRTokeniser.CheckPdfHeader() at
                                 iTextSharp.text.pdf.PdfReader.ReadPdf()
Run Code Online (Sandbox Code Playgroud)

我从其他条目中知道这个问题来自pdf中的一些无效格式.但是,我无法告诉我的用户重做他们的pdf.有没有其他方法来解决这个问题,即使出现这个问题,还是可以阅读pdf?

itextsharp

6
推荐指数
1
解决办法
1万
查看次数

C#检查上传文件的扩展名

我正在寻找一种简单的方法来检查上载文件的扩展名,如果它是PDF文件,请执行其他操作,否则将显示一条警告消息,指出其(错误的文件类型),但是我的代码存在问题,如果我选择了任何文件类型,而不是PDF,它会显示这个消息的错误页面:

   Server Error in '/' Application.
   PDF header signature not found.
   Exception Details: iTextSharp.text.exceptions.InvalidPdfException: PDF header signature not found.



        <asp:FileUpload runat="server" ID="file1" AllowMultiple="true" />


        string fileName = Path.GetFileName(file1.FileName);
        FileInfo fi = new FileInfo(fileName);
        string ext = fi.Extension;

        if (ext == ".pdf")
        {
        //do something
        }
        else
        Label1.Text = string.Format("wrong file type");
Run Code Online (Sandbox Code Playgroud)

c# pdf

0
推荐指数
1
解决办法
2617
查看次数

标签 统计

c# ×1

itextsharp ×1

pdf ×1