要实现不显示文件保存对话框,将"Print FixedDocument / XPS"转换为PDF,可以使用PdfSharp库。以下是一个示例代码:
using PdfSharp.Xps;
using PdfSharp.Pdf;
public void ConvertToPdf(string xpsFilePath, string pdfFilePath)
{
// Load the XPS document
var xpsDocument = new PdfSharp.Xps.XpsDocument(xpsFilePath, System.IO.FileAccess.Read);
// Create the PDF document
var pdfDocument = new PdfDocument();
// Iterate through each page of the XPS document and add it to the PDF document
for (int pageIndex = 0; pageIndex < xpsDocument.PageCount; pageIndex++)
{
var xpsPage = xpsDocument.GetPage(pageIndex);
var pdfPage = pdfDocument.AddPage();
var pdfRenderer = new PdfSharp.Xps.Rendering.XpsRenderer(xpsPage, pdfPage);
pdfRenderer.RenderVisual(xpsPage.Visual);
}
// Save the PDF document to the specified file path
pdfDocument.Save(pdfFilePath);
// Close the XPS document and the PDF document
xpsDocument.Close();
pdfDocument.Close();
}
你可以使用上述代码的ConvertToPdf
方法,将一个XPS文件转换为PDF文件。你需要提供XPS文件的路径和PDF文件的保存路径作为方法的参数。
下一篇:不显示我所犯的拼写错误和错误。