gpt4 book ai didi

c# - 使用 PDFSharp 连接 PDF 文件返回空白页

转载 作者:太空狗 更新时间:2023-10-29 21:35:55 25 4
gpt4 key购买 nike

我尝试连接来自 rdlc 报告的 2 个 PDF 数据。

问题是结果是空白页。

我不知道为什么,请有人帮助我。

这是我的代码:

private ActionResult ConcatPdf(byte[] pdfData1, byte[] pdfData2)
{
MemoryStream ms1 = new MemoryStream(pdfData1);
MemoryStream ms2 = new MemoryStream(pdfData2);

PdfDocument inputDoc1 = PdfReader.Open(ms1, PdfDocumentOpenMode.Import);
PdfDocument inputDoc2 = PdfReader.Open(ms2, PdfDocumentOpenMode.Import);

PdfDocument outputDoc = new PdfDocument();

foreach (PdfPage page in inputDoc1.Pages)
{
outputDoc.AddPage(page);
}

foreach (PdfPage page in inputDoc2.Pages)
{
outputDoc.AddPage(page);
}

MemoryStream outputMs = new MemoryStream();
outputDoc.Save(outputMs);

return File(outputMs.ToArray(), "application/pdf");
}

生成报告函数如下所示:

public ActionResult TestPDF(int id)
{
// Set report path.
LocalReport rep = viewer.LocalReport;
rep.ReportPath = Server.MapPath("~/Reports/rptExternalTransferIndividual.rdlc");
rep.DataSources.Clear();


//
// Set data and parameter to report.
//
...
...

return ConcatPdf(viewer.LocalReport.Render("PDF"), viewer.LocalReport.Render("PDF"));
}

最佳答案

我知道这是旧的,但添加 HumanReadablePDF:

 string deviceInfo = "<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>29.7cm</PageWidth>" +
" <PageHeight>21cm</PageHeight>" +
" <MarginTop>0cm</MarginTop>" +
" <MarginLeft>0cm</MarginLeft>" +
" <MarginRight>0cm</MarginRight>" +
" <MarginBottom>0cm</MarginBottom>" +
" <HumanReadablePDF>True</HumanReadablePDF>" +
"</DeviceInfo>";

byte[] reportBytes = LocalReport.Render(
"PDF", deviceInfo, out mimeType, out encoding,
out extension,
out streamids, out warnings);

然后将字节数组返回给 PdfSharp。

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com