2011-05-21 30 views
2

我有一個圖像的文本框。用戶在文本框中輸入份數(N)並點擊打印。打印機將照片打印N次(每張3張照片,一張在另一張下面)。多次用silverlight打印相同的圖像

Hiw你會做那樣的事嗎?我是否需要首先生成silverlight頁面?

回答

0

Silverlight有一個非常簡單易用的打印API。我最近一直在使用它,並學習瞭如何使用Melodtron列出的教程和this one over at the Visiblox site。這是特定於他們的圖表庫,但我仍然認爲它非常有用。

我假設你只有1張圖像在這裏一次打印,讓我知道你是否有更多。首先,你需要設置一個網格或類似的東西來放置你的照片。在這個網格中你需要N行。你必須做到這一點在後面的代碼,你有一定的行數你想創建,但這很容易被這樣的事情來實現:

Grid grid = new Grid(); 

// Set the column and row definitions 
for (int i = 0; i < Number of rows; i++) 
{ 
    grid.RowDefinitions.Add(new RowDefinition()); 
} 

這應該設置你的網格你需要。擁有網格後,您需要使用您擁有的圖像來填充網格。這很簡單,唯一的問題是你的圖像不能多次使用 - 即你已經擁有的圖像只能出現在網格上一次。您將不得不復制它以將其放置在網格上多次。我不確定你是如何創建你的圖像,但你可能會創建一個基於現有圖像的源路徑的新圖像?有一個關於如何做到這一點的線程here。如果您需要幫助,您需要提供更多詳細信息。

// Set the column and row definitions 
for (int i = 0; i < Number of rows; i++) 
{ 
    // Duplicate your existing image here. 
    Image image = new Image(); 
    grid.Children.Add(image); 
    Grid.SetRow(image, i); 
} 

所有的代碼上面的應該是這個方法:

private void printDocument_PrintPage(object sender, PrintPageEventArgs e) 
{ 
    //Code from above... 

    e.PageVisual = grid; 
} 

在要打印按鈕事件處理程序,做到這一點:

private void Button_Click(object sender, RoutedEventArgs e) 
{ 
    PrintDocument printDocument = new PrintDocument(); 
    printDocument.PrintPage += new EventHandler<PrintPageEventArgs>(printDocument_PrintPage); 
    printDocument.Print("TITLE"); 
} 

希望這有助於!