回覆列表
  • 1 # 未來可期_487

    首先需要在專案中新建一個報表(命名為XtraReport1)。還請注意,如果您希望用於開啟系統中*.pdf檔案的預設程式自動開啟生成的檔案,你可以呼叫StartProcess方法,示例中也有展示。

    using System.Diagnostics;

    using DevExpress.XtraPrinting;

    using DevExpress.XtraReports.UI;

    // ...

    private void button1_Click(object sender, EventArgs e)

    {

    // A path to export a report.

    string reportPath = "c:\\Test.pdf";

    // Create a report instance.

    XtraReport1 report = new XtraReport1();

    // Get its PDF export options.

    PdfExportOptions pdfOptions = report.ExportOptions.Pdf;

    // Set PDF-specific export options.

    pdfOptions.Compressed = true;

    pdfOptions.ImageQuality = PdfJpegImageQuality.Low;

    pdfOptions.NeverEmbeddedFonts = "Tahoma;Courier New";

    pdfOptions.DocumentOptions.Application = "Test Application";

    pdfOptions.DocumentOptions.Author = "DX Documentation Team";

    pdfOptions.DocumentOptions.Keywords = "XtraReports, XtraPrinting";

    pdfOptions.DocumentOptions.Subject = "Test Subject";

    pdfOptions.DocumentOptions.Title = "Test Title";

    // Set the pages to be exported.

    pdfOptions.PageRange = "1, 3-5";

    // Export the report to PDF.

    report.ExportToPdf(reportPath);

    // Show the result.

    StartProcess(reportPath);

    }

    // Use this method if you want to automaically open

    // the created PDF file in the default program.

    public void StartProcess(string path)

    {

    Process process = new Process();

    try

    {

    process.StartInfo.FileName = path;

    process.Start();

    process.WaitForInputIdle();

    }

    catch { }

    }

    Imports System.Diagnostics

    Imports DevExpress.XtraPrinting

    Imports DevExpress.XtraReports.UI

    " ...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _

    Handles Button1.Click

    " A path to export a report.

    Dim reportPath As String = "c:\\Test.pdf"

    " Create a report instance.

    Dim report As New XtraReport1()

    " Get its PDF export options.

    Dim pdfOptions As PdfExportOptions = report.ExportOptions.Pdf

    " Set PDF-specific export options.

    pdfOptions.Compressed = True

    pdfOptions.ImageQuality = PdfJpegImageQuality.Low

    pdfOptions.NeverEmbeddedFonts = "Tahoma;Courier New"

    pdfOptions.DocumentOptions.Application = "Test Application"

    pdfOptions.DocumentOptions.Author = "DX Documentation Team"

    pdfOptions.DocumentOptions.Keywords = "XtraReports, XtraPrinting"

    pdfOptions.DocumentOptions.Subject = "Test Subject"

    pdfOptions.DocumentOptions.Title = "Test Title"

    " Set the pages to be exported.

    pdfOptions.PageRange = "1, 3-5"

    " Export the report to PDF.

    report.ExportToPdf(reportPath)

    " Show the result.

    StartProcess(reportPath)

    End Sub

    " Use this method if you want to automaically open

    " the created PDF file in the default program.

    Public Sub StartProcess(ByVal path As String)

    Dim process As New Process()

    Try

    process.StartInfo.FileName = path

    process.Start()

    process.WaitForInputIdle()

    Catch

    End Try

    End Sub

  • 中秋節和大豐收的關聯?
  • 婚前沒錢,婚後會比婚前要好嗎?