2015-04-16 40 views
0

我需要在我的Win 8.1應用程序中實現打印,關鍵要求是能夠在之後生成頁面已選擇打印機並且點擊了打印按鈕。這是驅動圖像周圍的安全需求,不可談判。最終,這是我必須下載打印所需圖像的關鍵。打印時圖像不可見

目前我的測試我使用的是形象,是本地的項目:

string testImageLocalSource = "ms-appx:///Assets/testImage.png"; 

在我的測試項目中,我的工作中,將PrintDocument.AddPages事件處理過程中,我生成打印頁面如下(爲簡潔移除佈局/保證金碼):

private void PrintDocument_AddPages(object sender, AddPagesEventArgs e) 
    { 
     var printPageDescription = e.PrintTaskOptions.GetPageDescription(0); 
     FrameworkElement printPage; 

     printPage = new MainPrintPage(); 

     // get the printable content 
     Grid printableArea = (Grid)printPage.FindName("printableArea"); 

     Run myRun1 = new Run(); 
     myRun1.Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; 
     myRun1.FontStyle = Windows.UI.Text.FontStyle.Oblique; 
     myRun1.Foreground = new SolidColorBrush(Windows.UI.Colors.Purple); 
     myRun1.FontSize = 42; 

     Image i = new Image(); 
     i.Source = new BitmapImage(new Uri(testImageLocalSource, UriKind.Absolute)); 
     i.Height = 200; 

     InlineUIContainer container = new InlineUIContainer(); 
     container.Child = i; 

     // Create a paragraph and add the content. 
     Paragraph myParagraph = new Paragraph(); 
     myParagraph.Inlines.Add(container); 
     myParagraph.Inlines.Add(myRun1); 

     // add paragraph to RichTextBlock blocks 
     var mainRTB = printPage.FindName("mainrtb"); 
     ((RichTextBlock)mainRTB).Blocks.Add(myParagraph); 

     // add page to hidden canvas 
     printingRoot.Children.Add(printPage); 
     printingRoot.InvalidateMeasure(); 
     printingRoot.UpdateLayout(); 

     printDocument.AddPage(printPage); 

     PrintDocument printDoc = (PrintDocument)sender; 
     printDoc.AddPagesComplete(); 

    } 

文本顯示細膩,而且似乎是多餘的空間,圖像應該是,但圖像顯示不出來。

如果我在早期事件處理程序中使用此代碼(如PrintDocument.Paginate),圖像顯示在打印中。

有沒有人試圖做類似的事情,並找到了解決方案,或者是否有人解釋了這裏發生了什麼,以及如何補救它的想法?

UPDATE
我試圖移動的散裝這段代碼的PrintTask.Submitting事件的,這正顯示出的承諾。我會用一個例子來更新它,如果它有效的話。

回答

0

不完全知道什麼是在Win 8.1導致此,但它似乎被固定在Windows 10

0

你忘了設置圖像的寬度嗎?

i.Width = 200; 
+0

試過了。在這種情況下,寬度和高度不影響可視性。 – earthling