找不到PDF标题签名错误?

找不到PDF标题签名错误?,pdf,asp.net-mvc-2,Pdf,Asp.net Mvc 2,我正在用Azure开发Asp.NETMVC应用程序。当我将PDF文档上传到Azure blob存储时,它将通过使用以下代码完美上传 var filename = Document.FileName; var contenttype = Document.ContentType; int pdfocument = Request.ContentLength; //uploading document in to

我正在用Azure开发Asp.NETMVC应用程序。当我将PDF文档上传到Azure blob存储时,它将通过使用以下代码完美上传

           var filename = Document.FileName;
           var contenttype = Document.ContentType;

           int pdfocument = Request.ContentLength;

        //uploading document in to azure blob

         CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

           var storageAccount = CloudStorageAccount.DevelopmentStorageAccount(FromConfigurationSetting("Connection"));
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
           CloudBlobContainer container = blobClient.GetContainerReference("containername");
           container.CreateIfNotExists();
            var permissions = container.GetPermissions();
            permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
            container.SetPermissions(permissions);
            string uniqueBlobName = string.Format(filename );
            CloudBlockBlob blob = container.GetBlockBlobReference(uniqueBlobName);
            blob.Properties.ContentType = ;
            blob.UploadFromStream(Request.InputStream);
将文档上载到blob后,尝试读取pdf文档时出现错误“未找到pdf标头签名”。该erorr代码为

          byte[] pdf = new byte[pdfocument];
          HttpContext.Request.InputStream.Read(pdf, 0, pdfocument);               
          PdfReader pdfReader = new PdfReader(pdf);     //error getting here           

还有一件事我忘记了,即如果我们对上述代码(将文档上传到Azure blob中)进行注释,那么我不会收到该错误。

在您的组合用例中,您尝试读取Request.InputStream两次,一次是在上传过程中,一次是在稍后尝试将其读入您的
byte[]pdf
,当您第一次读取时,您一直读到它的结尾,所以第二次读取很可能根本没有得到任何数据

无论如何,当您打算将PDF读入内存时(前面提到的
byte[]PDF
),您可以在您的组合用例中

  • 首先将数据读入该数组

    int pdfocument = Request.ContentLength;
    byte[] pdf = new byte[pdfocument];
    HttpContext.Request.InputStream.Read(pdf, 0, pdfocument);
    
  • 然后使用


这样,您只需读取一次流,字节[]应该是可重用的…

Hi Andrew,现在我将字节数组上传到blob而不是流。现在我已退出pdf标题问题。非常感谢您提供的宝贵信息。我想问一件事。当我使用blob url在浏览器中打开pdf文档时,它将与一个弹出窗口一起打开。弹出窗口为“此文档在Adobe Reader中启用了扩展功能。文档自创建以来已被更改,扩展功能的使用不再可用。请与作者联系以获取此文档的原始版本。”在Adobe Reader 9.0版本中出现此错误,但在11.0版本中没有出现此错误。上传之前,同样的PDF也会出现这种情况?或者上传过程中是否发生了中断?如果您不确定,请在上传之前和之后提供PDF。这是在之后而不是之前发生的。当我在PDF打开之前上传时,通常情况下是这样的。没有获得pop up消息。@PCSCP请在检查前和检查后提供PDF。
var storageAccount = CloudStorageAccount.DevelopmentStorageAccount(FromConfigurationSetting("Connection"));
[...]
CloudBlockBlob blob = container.GetBlockBlobReference(uniqueBlobName);
blob.Properties.ContentType = ; // <--- something missing in your code...
blob.UploadByteArray(pdf);      // <--- upload byte[] instead of stream
PdfReader pdfReader = new PdfReader(pdf);