XPS文件转换PDF小工具,集成了界面,方便大家使用

网上有关于XPS转换PDF的工具gxps.exe,由GhostPDL的代码编译而成。但是很不方便使用,需要设置参数,不够直观。

所以想出了给它集成一个外壳的想法。

 

利用C++语言,编写了外壳,调用gxps.exe,可以直接选择需要转换的文件和保存的地址。

 

完成界面后,感觉大家还需要再下gxps.exe,两个exe看起来很不爽。所以就将exe集成到了外壳程序里。需要转换时释放该文件,转换后自动删除。让大家感觉像是一个独立的程序,使用更方便友好。

 

大家来捧场,哈哈!!

 

下载地址:http://download.csdn.net/source/1693950

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用iTextSharp库来实现将XPS转换PDF的操作。以下是一个简单的C#代码示例: ```csharp using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; public void ConvertXpsToPdf(string xpsFilePath, string pdfFilePath) { using (Stream xpsStream = new FileStream(xpsFilePath, FileMode.Open, FileAccess.Read)) { using (FileStream pdfStream = new FileStream(pdfFilePath, FileMode.Create, FileAccess.Write)) { // Create a new iTextSharp document Document pdfDoc = new Document(); // Create a PdfWriter that listens to the document PdfWriter writer = PdfWriter.GetInstance(pdfDoc, pdfStream); // Open the iTextSharp document pdfDoc.Open(); // Create a new XpsDocument from the XPS file XpsDocument xpsDoc = new XpsDocument(xpsStream, FileAccess.Read); // Create a FixedDocumentSequence from the XpsDocument FixedDocumentSequence fixedDocSeq = xpsDoc.GetFixedDocumentSequence(); // Loop through each FixedDocument in the FixedDocumentSequence foreach (FixedDocument fixedDoc in fixedDocSeq.Documents) { // Loop through each PageContent in the FixedDocument foreach (PageContent pageContent in fixedDoc.Pages) { // Convert the PageContent to a WPF Visual FixedPage fixedPage = pageContent.GetPageRoot(false); System.Windows.Controls.Canvas canvas = new System.Windows.Controls.Canvas(); canvas.Children.Add(fixedPage); canvas.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity)); canvas.Arrange(new System.Windows.Rect(new System.Windows.Point(), canvas.DesiredSize)); // Convert the WPF Visual to an iTextSharp image RenderTargetBitmap bitmap = new RenderTargetBitmap((int)canvas.ActualWidth, (int)canvas.ActualHeight, 96, 96, PixelFormats.Default); bitmap.Render(canvas); MemoryStream ms = new MemoryStream(); BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmap)); encoder.Save(ms); Image iTextImage = Image.GetInstance(ms.ToArray()); // Add the iTextSharp image to the PDF document pdfDoc.Add(iTextImage); } } // Close the iTextSharp document pdfDoc.Close(); } } } ``` 你需要将 `xpsFilePath` 和 `pdfFilePath` 参数分别替换为你要转换XPS文件的路径和要生成的PDF文件的路径。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值