如何在不提示路径的情况下将固定文档打印为pdf?

时间:2018-06-22 16:12:40

标签: wpf pdf printing

我知道如何从用户控件创建固定文档并创建pdf,但是我知道应用程序何时提示您选择文档的路径和名称。代码是这样的:

MyUserControlView myView = new MyUserControlView();
MyUserControlViewModel myViewModel = new MyUserControlViewModel();
myView.DataContext = myViewModel;

System.Windows.Controls.PrintDialog miDialogo = new System.Windows.Controls.PrintDialog();
FixedDocument myDocument = new FixedDocument();

int myFactor;
myFactor = 6;

myView.Measure(new Size(794 * 1, 1122 * 1));
myView.Arrange(new Rect(new Size(794 * 1, 1122 * 1)));

myView.UpdateLayout();

System.Windows.Media.Imaging.RenderTargetBitmap bitmap = new System.Windows.Media.Imaging
.RenderTargetBitmap(794 * miFactor, 1122 * miFactor, 96 * miFactor, 96 * miFactor, System.Windows.Media.PixelFormats.Pbgra32);
bitmap.Render(myView);

System.Windows.Controls.Image myImage = new System.Windows.Controls.Image();
myImage.Source = bitmap;

myDocument.DocumentPaginator.PageSize = new Size(myImage.Width, myImage.Height);
FixedPage miPagina1 = new FixedPage();
myPage1.Width = myDocument.DocumentPaginator.PageSize.Width;
myPage1.Height = myDocument.DocumentPaginator.PageSize.Height;
myPage1.Children.Add(myImage);

PageContent miContent1 = new PageContent();
((IAddChild)miContent1).AddChild(myPage1);

myDocument.Pages.Add(miContent1);


System.Windows.Controls.PrintDialog myDialog = new System.Windows.Controls.PrintDialog();
if (myDialog.ShowDialog() == true)
{
    myDialog.PrintDocument(myDocument.DocumentPaginator, string.Empty);
}

但是,我希望能够在不提示文档路径的情况下打印为pdf,而不是默认目录,并使用默认打印机来打印为Windows 10 pdf。

谢谢。

0 个答案:

没有答案