とても珍しいことが起こっています。
私の rdlc レポートでは、MVC 4 プロジェクトでいくつかのテキスト ボックスを PDF として表示するように設定しました。これを localhost モードで実行すると、うまく機能します。
しかし、ソリューションをデプロイすると、次のエラーがスローされます。
パラメータが無効です。[ArgumentException: パラメータが無効です。] System.Drawing.Graphics.GetHdc() +1144409
Microsoft.ReportingServices.Rendering.RichText.LineBreaker.Flow(TextBox textBox, Graphics g, FontCache fontCache, FlowContext flowContext, Boolean keepLines, Single& height) +57
Microsoft.ReportingServices.Rendering.RichText.TextBox.MeasureFullHeight(TextBox textBox, Graphics g, FontCache fontCache, FlowContext flowContext, Single& contentHeight) +500
Microsoft.ReportingServices.Rendering.HPBProcessing.TextBox.DetermineVerticalSize(PageContext pageContext, Double topInParentSystem, Double bottomInParentSystem、....[LocalProcessingException: ローカル レポートの処理中にエラーが発生しました。]
Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings) +338
Microsoft.Reporting.WebForms .LocalReport.InternalRender(文字列形式、ブール型 allowInternalRenderers、文字列 deviceInfo、PageCountMode ...
注: rdlc でこれらのテキスト ボックスを削除すると (すべてを削除することを意味します)、空白の PDF が生成されることに気付きました。それで、テキストボックスが問題だと気づきましたが、展開したときだけ理由がわかりません。
私は何が欠けていますか?
私が使用しているコードは次のコードです。
public ActionResult SampleReport()
{
LocalReport localReport = new LocalReport();
localReport.ReportPath = Server.MapPath("~/Reports/Report1.rdlc");
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
//The DeviceInfo settings should be changed based on the reportType
//http://msdn2.microsoft.com/en-us/library/ms155397.aspx
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>1in</MarginLeft>" +
" <MarginRight>1in</MarginRight>" +
" <MarginBottom>0.5in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
//Render the report
renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
//Response.AddHeader("content-disposition", "attachment; filename=NorthWindCustomers." + fileNameExtension);
return File(renderedBytes, mimeType);
}
更新: Report Services を使用して PDF を作成する方法について掘り下げ始めたとき、次のガイドのみに従いました。
- http://weblogs.asp.net/rajbk/archive/2009/11/25/rendering-an-rdlc-directly-to-the-response-stream-in-asp-net-mvc.aspx
- Microsoft Report Viewer をインストールせずに Web サイトを発行する
最後の 1 つは、参照ライブラリとして 3 つを含める必要があるためです。また、ソリューションをデプロイするとMicrosoft.ReportViewer.Common
、これらのライブラリにはカウントされないため、手動で追加しました。Microsoft.ReportViewer.WebForms
Microsoft.ReportViewer.ProcessingObjectModel
以上です!