c# - 使用 PDFsharp 连接 PDF 返回空 PDF

标签 c# pdf concatenation pdfsharp

我有一个存储为 list<byte[]> 的 PDF 列表.我尝试使用 PDFsharp 连接所有这些 PDF 文件,但在我操作后我得到了一个具有正确页数的 PDF,但所有页面都是空白的。看起来我丢失了一些标题或其他东西,但我找不到位置。

我的代码:

        PdfDocument output = new PdfDocument();
        try
        {
            foreach (var report in reports)
            {
                using (MemoryStream stream = new MemoryStream(report))
                {

                    PdfDocument input = PdfReader.Open(stream, PdfDocumentOpenMode.Import);

                    foreach (PdfPage page in input.Pages)
                    {
                        output.AddPage(page);
                    }
                }
            }


            if (output.Pages.Count <= 0)
            {
                throw new Exception("Empty Document");
            }
            MemoryStream final = new MemoryStream();
            output.Save(final);
            output.Close();
            return final.ToArray();
        }
        catch (Exception e)
        {
            throw new Exception(e.ToString());
        }

我想将其退回为 byte[]因为我稍后会用到它们:

return File(report, System.Net.Mime.MediaTypeNames.Application.Octet, "test.pdf");

这将返回具有正确页数的 PDF,但全部为空白。

最佳答案

您在评论中说明这些文件来自 SSRS。

旧版本的 PDFsharp 需要特殊的 SSRS 设置:

For the DeviceSettings parameter for the Render method on the ReportExecutionService object, pass this value:

theDeviceSettings = "<DeviceInfo><HumanReadablePDF>True</HumanReadablePDF></DeviceInfo>"; 

来源:
http://forum.pdfsharp.net/viewtopic.php?p=1613#p1613

关于c# - 使用 PDFsharp 连接 PDF 返回空 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37109232/

相关文章:

c# - 如何将 DocumentDB 查询作为 List<Type> 返回?

Java : Any way to save a string input into pdf

python - 数字签名中pdf的消息摘要

pdf - 打印时隐藏 PDF 中的文本

c# - 列出一些免费 C# 视频播客的站点

c# - WPF 在选定的 ListItem 中显示按钮

C 宏串联作为函数参数

c - 字符串文字的 strcat 与 strncat

python - 如何使用numpy连接?

c# - 声明具有属性的类并同时填充这些属性的最佳方法是什么