- PR -

クリスタルレポートでのPDF出力方法

1
投稿者投稿内容
ギャンブラー
会議室デビュー日: 2003/06/05
投稿数: 3
投稿日時: 2003-06-05 18:34
先ほどのメールが説明不足でわかりにくいとご指摘があり
誠に申し上げありませんでした。

クリスタルレポートを使用して、PDF出力を行います。
テキストエリアの入力結果をリアルタイムPDF出力したいのですが、
コーディング手法が不明です。
リアルタイムPDF出力のサンプルソース等がありましたら
ご教授の程、お願い致します。

[やりたいこと]

@ Webフォームにテキストボックスとボタンを追加する。
A CrystalReport.rptにTextObjectを追加する。
B ボタン押下時にテキストボックスに入力された文字列を
  上記、AのTextObjectに表示しPDF出力。

[環境]
ASP.NET(C#)
[ボタン押下時処理]
private void Button1_Click(object sender, System.EventArgs e)
{
//レポートをロード
report.Load("c:/inetpub/wwwroot/test/CrystalReport1.rpt");
CrystalDecisions.Shared.ExportOptions exportOpts;

//以下エクスポート処理
exportOpts = report.ExportOptions;

//PDFを指定
exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
exportOpts.FormatOptions = new CrystalDecisions.Shared.PdfRtfWordFormatOptions();
CrystalDecisions.Shared.ExportRequestContext req = new CrystalDecisions.Shared.ExportRequestContext();
req.ExportInfo = exportOpts;
System.IO.Stream st;
st = report.FormatEngine.ExportToStream(req);
byte[] b = new byte [st.Length];
st.Read(b, 0, (int)st.Length);

//適切な ContentType を設定します。
Response.ContentType = "Application/pdf";

//HTTP コンテンツ出力ストリームにファイルを直接書き出します。
Response.BinaryWrite(b);
Response.End();
}

以上、よろしくお願いいたします。
ギャンブラー
会議室デビュー日: 2003/06/05
投稿数: 3
投稿日時: 2003-06-06 16:39
自己レスです。

[ボタンクリック時処理]
    private void Button1_Click(object sender, System.EventArgs e)
{
TextObject txtOutputField;

//レポートをロード
report.Load("c:/inetpub/wwwroot/Sample/CrystalReport1.rpt");

txtOutputField = report.ReportDefinition.ReportObjects["txtOutputFieldName"] as TextObject;
txtOutputField.Text = "SomeValue";

ExportOptions exportOpts;
//以下エクスポート処理
exportOpts = report.ExportOptions;

//PDFを指定
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
exportOpts.FormatOptions = new PdfRtfWordFormatOptions();

ExportRequestContext req = new ExportRequestContext();
req.ExportInfo = exportOpts;
System.IO.Stream st;
st = report.FormatEngine.ExportToStream(req);
byte[] b = new byte [st.Length];
st.Read(b, 0, (int)st.Length);

//適切な ContentType を設定します。
Response.ContentType = "Application/pdf";

//HTTP コンテンツ出力ストリームにファイルを直接書き出します。
Response.BinaryWrite(b);
Response.End();
}
1

スキルアップ/キャリアアップ(JOB@IT)