2016-07-20 29 views
1

PDFを印刷し、プログラムで使用する用紙トレイを選択する方法はありますか?異なるプリンタトレイを使用してPDFを印刷するc#

私は、PDFを別の形式に変換してそこから印刷するなどの提案を受けています。

PaperSource()とPrintDocument()を使用して正しいトレイに印刷できます。これらの機能で理解できる形式にPDFを変換できますか?

ありがとうございました。

あなたが Ghostscript.NETを使用して気にしないならば、これはあなたのために働く必要があり、 here on MSDNのようなものから、用紙トレイ PaperSourceを得ることに基づいて
+0

あなたは異なる用紙サイズ上のPDF文書を生成しようとしたことがありますか?今、あなたはどのようなコードを使ってPDFを生成していますか?プリンタはどのようなスクリプトを理解していますか? – zipzit

+0

私はPDFフォームを使用していて、iTextSharpを使って編集した後、PDFとして保存しますが、どのスクリプトがプリンタに認識されているのかわからない –

+0

あなたは[PaperCut](http://www.papercut.com/tour/advanced-scripting) /)かそれとまったく同じもの。私は、適切なプリンタスクリプトツールを使用して、ファイル名抽出を介して使用する用紙ビンを判断することができると考えています。 E. G. 'Filename_big.pdf'対 'Filename_little.pdf' – zipzit

答えて

1

public void PrintPdf(string filePath, string printQueueName, PaperSource paperTray) 
{ 
    using (ManualResetEvent done = new ManualResetEvent(false)) 
    using (PrintDocument document = new PrintDocument()) 
    { 
     document.DocumentName = "My PDF"; 
     document.PrinterSettings.PrinterName = printQueueName; 
     document.DefaultPageSettings.PaperSize = new PaperSize("Letter", 850, 1100); 
     document.DefaultPageSettings.PaperSource = paperTray; 
     document.OriginAtMargins = false; 

     using (var rasterizer = new GhostscriptRasterizer()) 
     { 
      var lastInstalledVersion = 
       GhostscriptVersionInfo.GetLastInstalledVersion(
         GhostscriptLicense.GPL | GhostscriptLicense.AFPL, 
         GhostscriptLicense.GPL); 

      rasterizer.Open(filePath, lastInstalledVersion, false); 

      int xDpi = 96, yDpi = 96, pageNumber = 0; 

      document.PrintPage += (o, p) => 
      { 
       pageNumber++; 
       p.Graphics.DrawImageUnscaledAndClipped(
        rasterizer.GetPage(xDpi, yDpi, pageNumber), 
        new Rectangle(0, 0, 850, 1100)); 
       p.HasMorePages = pageNumber < rasterizer.PageCount; 
      }; 

      document.EndPrint += (o, p) => 
      { 
       done.Set(); 
      }; 

      document.Print(); 
      done.WaitOne(); 
     } 
    } 
} 
関連する問題