Click here to Skip to main content
15,909,242 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

C#
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);
         
           
            
        }
Posted
Updated 7-Sep-16 14:58pm

1 solution

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

C#
System.Diagnostics.Process.Start(@"c:\aPath\somePDF.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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900