I'm trying to print a WPF window with the following code :
PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
{
var printArea = printDialog.PrintQueue.GetPrintCapabilities()
.PageImageableArea;
var item = (FrameworkElement)this;
DrawingVisual visual = new DrawingVisual();
using (DrawingContext context = visual.RenderOpen())
{
VisualBrush brush = new VisualBrush(item);
context.DrawRectangle(brush, null,
new Rect(new Point(printArea.OriginWidth, printArea.OriginHeight),
new Size(item.ActualWidth, item.ActualHeight)));
}
printDialog.PrintVisual(visual, String.Empty);
}
It works really well, but for a really strange reason, the buttons doesn't appear on the printed document.
I discovered that the cause seem to be that I have set a DropShadowEffect on the button, if I remove it, the button appears on the printed document :
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect Color="Gray" Opacity=".50" ShadowDepth="8" />
</Setter.Value>
</Setter>
This is not really a critical issue, but it would be nice if someone had a workaround.
The Effects like that are implemented as pixel shaders that run on the GPU. My best guess is that rendering done for a print job is being done on the CPU, so it would not have access to the necessary pixel shaders to do the drawing.
Probably your best bet is to disable the drop shadows just before printing, then reenable them after.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With