我有一个存储为 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>";
关于c# - 使用 PDFsharp 连接 PDF 返回空 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37109232/