I am printing my canvas with Microsoft Print to PDF. Now i have a requirement that when Microsoft Print to PDF is selected from available printers list then a FileSaveDialog is shown itself i do not want to show it rather than i want to save that PDF file on predefined path. Below is my code which i am using to print my canvas:
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;
}
Can anyone suggest any solution how can i save file on a predefined path.
Thanks in Advance