如何在打印预览关闭事件上创建PDF文件 [英] How to create PDF file on print preview close event

查看:122
本文介绍了如何在打印预览关闭事件上创建PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想创建PDF文件并将其保存在打印预览对话框中的本地机器已经接近我使用的第三方PDFSharp-MigraDocFoundation- 1_32 dll





i完成编码但不明白如何传递printpreview对话框



我尝试过:



Hi all,

I want to create PDF file and save it local machine on print preview dialog box is close for this i used third party PDFSharp-MigraDocFoundation-1_32 dll


i done coding but not understand how to pass printpreview dialog box in that

What I have tried:

using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;

  private void printPreviewDialog1_FormClosing(object sender, FormClosingEventArgs e)
        {
            PdfDocument pdf = new PdfDocument();
            pdf.Info.Title = "Sales_Information";
            PdfPage pdfPage = pdf.AddPage();
            XGraphics graph = XGraphics.FromPdfPage(pdfPage);
            XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
            graph.DrawString(printPreviewDialog1,font, XBrushes.Black, new XRect(0, 0, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.Center);
            string pdfFilename = "Sales_Information_"+DateTime.Now.ToString("dd/MM/yyyy")+".pdf";
            pdf.Save(pdfFilename);
         
           
            
        }

推荐答案

不完全确定你的意思是什么那 - 我有一个创建pdf的过程,然后允许用户预览它们 - 我这样做是通过



not exactly sure what you mean by some of that - I have a process that creates pdfs, then allows the user to preview them - I do this by

System.Diagnostics.Process.Start(@"c:\aPath\somePDF.pdf");





使用用户/客户端机器上的默认应用程序来查看PDF - 他们可以打印/保存/从那里开始 - 它的工作原理无论是使用Acrobat还是Foxit。当程序开始确保他们确实有一个默认的应用程序'可以处理'pdf时,我会检查,但是,这是一个不同的故事



我可以我写了一个预览表格,我认为MigraDoc / PDFsharp包括一个,但我使用iTextSharp并且不想混合PDF堆栈



That uses whatever the default app is on the user/client's machine to view the PDF - they can print/save/whatever from there - it works regardless of whether its Acrobat or Foxit being used. I do run a check when the program starts to make sure that they do have a default application trhat 'can handle' pdf, but, thats a different story

I could have written a preview form, I think MigraDoc/PDFsharp include one, but Im using iTextSharp and didnt want to mix PDF stacks


这篇关于如何在打印预览关闭事件上创建PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆