我正在使用 Microsoft Print to PDF 打印我的画布。现在我要求从可用打印机列表中选择Microsoft Print to PDF然后显示FileSaveDialog本身我不想显示它而不是我想在预定义路径上保存该PDF文件。下面是我用于打印画布的代码:
public void RenderCanvasImage(int maxRight, int maxBottom, Canvas surface, Transform transform)
{
RenderTargetBitmap renderBitmap = new RenderTargetBitmap(maxRight, maxBottom, 96d, 96d, PixelFormats.Pbgra32);
renderBitmap.Render(surface);
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() != true)
{
return;
}
dialog.PrintQueue = new System.Printing.PrintQueue(new System.Printing.PrintServer() { }, "Microsoft Print to PDF");
Grid grid = new Grid();
Image myImage = new Image();
myImage.Source = renderBitmap;
myImage.Stretch = Stretch.Uniform;
grid.Children.Add(myImage);
Grid.SetColumn(myImage, 0);
Grid.SetRow(myImage, 1);
var pqueue = dialog.PrintQueue;
grid.Measure(new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight));
grid.Arrange(new Rect(new Point(0, 0), grid.DesiredSize));
dialog.PrintVisual(grid, "My Canvas");
surface.LayoutTransform = transform;
}
任何人都可以建议任何解决方案如何在预定义的路径上保存文件。
先谢谢