2016-02-18 45 views
0

我努力學習,如果有可能建立在C#中這需要滿足要求的應用程序:從模板文件創建PDF,繪製文本,並打印文件

  1. 可以加載一個模板PDF文件,並在其上繪製一些文本(例如像素定位)
  2. 將此文件保存在特定目錄中
  3. 而且最重要的...應用程序應該能夠打印這樣的PDF文件。我不是說打印在屏幕上,我的意思是'悄悄地'在打印機上發送。

我聽說iTextSharp/iTextPdf可以完成兩個第一點。但它是否允許我簡單地將此文件發送到打印機?我現在正在尋找一個解決方案。
用戶應該在選項中選擇默認打印機一次,而他所要做的就是在生成這樣的PDF文件後點擊「打印」。我很樂意在後臺打開Adobe Reader的解決方案。

有沒有可能的選擇?

我知道它可以將圖像發送到打印機,而無需在後臺運行任何其他程序。但我需要它爲PDF工作。

private void SendToPrinter(string path) 
{ 
    PrinterSettings defaultprinter = new PrinterSettings(); 
    PrintDocument pd = new PrintDocument(); 
    pd.PrinterSettings.PrinterName = defaultprinter.PrinterName; 
    pd.PrintPage += (sender, e) => PrintPage(e, path); 
    pd.Print(); 
} 
private void PrintPage(PrintPageEventArgs e, string path) 
{ 
    Bitmap bitma = new Bitmap(776, 538, PixelFormat.Format32bppArgb); 
    System.Drawing.Image dest = bitma; 
    Graphics graph = Graphics.FromImage(dest); 
    graph.Clear(Color.FromArgb(255, 255, 255)); 

    Bitmap z = new Bitmap(path); 
    System.Drawing.Image img = z; 
    graph.DrawImage(img, new System.Drawing.Point(120, 350)); 
    e.Graphics.DrawImage(dest, new System.Drawing.Point(0, 0)); 
} 

PS。是的,我試過搜索。谷歌,stackoverflow,甚至幾乎看到類似的問題,但沒有找到一個回答我所有的問題。

回答

0

如果你看看我把自己放在這裏的不同問題你會發現使用GhostScript打印PDF文件是一個很好的工具。你可以找到問題here,here,herehere

在他們4人之間你會找到所有你需要的信息:)