Document Library for WinForms
PDF の印刷

PdfDocumentSource を使用して PDF ファイルを印刷できます。C1DocumentSource 抽象クラスの Print メソッドを使用した印刷がサポートされています。 Print メソッドには、Print (PrinterSettings printerSettings)Print (C1PrintOptions options) の 2 つのオーバーロードメソッドがあります。C1PdfDocumentSource を使用して Print メソッドを追加することで、ビューアがなくても PDF を印刷できます。以下のコードに、このメソッドの使用方法を示します。このトピックのコードでは、PDF ファイルの印刷に Print (C1PrintOptions options) メソッドを使用しています。

PDF を印刷するには

  1. PDF をエクスポートするためのボタンコントロールをフォームに追加します。
  2. C1PdfDocumentSource コンポーネントと PrintDialog コンポーネントをツールボックスからフォームにドラッグアンドドロップしてコンポーネントトレイに追加します。
  3. コードビューで、次の名前空間を追加します。
    Imports C1.Win.C1Document
    
    using C1.Win.C1Document;
    
  4. プロジェクトに PDF ファイルを追加します。この例では、製品サンプルにある DefaultDocument.pdf という PDF ファイルを使用します。
  5.  LoadFromFile メソッドを使用して、C1PdfDocumentSource のオブジェクトに PDF ファイルをロードします。
    c1PdfDocumentSource1.LoadFromFile("..\..\DefaultDocument.pdf")
    
    c1PdfDocumentSource1.LoadFromFile(@"..\..\DefaultDocument.pdf");
    
  6. 次のコードをボタンのクリックイベントに追加して、Print メソッドを使用して PDF ファイルを印刷します。
    If printDialog1.ShowDialog(Me) <> DialogResult.OK Then
       Return
    End If
    
    Try
       Dim po As New C1PrintOptions()
       po.PrinterSettings = printDialog1.PrinterSettings
       'PDFを印刷します
       c1PdfDocumentSource1.Print(po)
       MessageBox.Show(Me, "ドキュメントが正常にエクスポートされました。", _
                       "情報", MessageBoxButtons.OK, _
    
                       MessageBoxIcon.Information)
    Catch ex As Exception
        MessageBox.Show(Me, ex.Message, "エラー", MessageBoxButtons.OK, _
                        MessageBoxIcon.[Error])
    End Try
    
    if (printDialog1.ShowDialog(this) != DialogResult.OK)
        return;
    
    try
    {
        C1PrintOptions po = new C1PrintOptions();
        po.PrinterSettings = printDialog1.PrinterSettings;
        //PDFを印刷します
        c1PdfDocumentSource1.Print(po);
        MessageBox.Show(this, "ドキュメントが正常にエクスポートされました。",
                        "情報", MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
    }
    catch (Exception ex)
    {
        MessageBox.Show(this, ex.Message, "エラー", MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
    }
    
関連トピック