【问题标题】:Adobe Reader could not open 'StreamTest5.pdf' because it is either not a supported file or file has been damaged errorAdobe Reader 无法打开“StreamTest5.pdf”,因为它不是受支持的文件或文件已损坏错误
【发布时间】:2017-02-28 21:15:04
【问题描述】:

我正在尝试使用文件流创建 pdf 文件,并且在路径的指定文件夹中创建文件时,当我尝试打开文件时,Adobe Reader 抛出了我在标题中提到的错误。我不确定我做错了什么,但如果有人可以调查并帮助我,我将不胜感激。谢谢!。这是我的文件流代码:

            System.IO.FileStream wFile;
            byte[] byteData = null;
            byteData = Encoding.ASCII.GetBytes("FileStream Test");
            string filePath = $"{_ApplicationPath}PrintedResults\\StreamTest5.pdf";
            wFile = new FileStream(filePath, FileMode.Create);
            wFile.Write(byteData, 0, byteData.Length);
            wFile.Close();
            using (var fileStream = new FileStream(filePath, FileMode.Open))
            {

                Console.WriteLine("This is a test stream file");

            }
        System.Diagnostics.Process.Start(filePath);

【问题讨论】:

    标签: c# wpf pdf filestream


    【解决方案1】:

    您正在编写内容为“FileStream Test”的文本文件,但文件扩展名为“.PDF”。这不是 PDF 文件。它是一个具有误导性名称的文本文件。 Adobe Reader 正确报告它不是有效的 PDF。

    【讨论】:

    • 你能帮我写一个pdf文件而不是文本的代码吗?
    • 您将需要一个第三方库来生成 PDF,或者花费大量时间研究 PDF 格式本身并尝试编写自己的。
    【解决方案2】:

    这不是答案,但我没有足够的声誉将其添加为评论:

    您可能想查看http://www.dynamicpdf.com/ 提供的第 3 方库 他们的免费评估版功能非常强大,而且不像他们在网站上所说的那样有时间限制。只需稍加努力,您就可以仅使用评估版创建相当复杂的 PDF!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-18
      • 2018-05-10
      • 2017-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-21
      • 1970-01-01
      相关资源
      最近更新 更多