using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; using PdfSharp; using PdfSharp.Drawing; using PdfSharp.Fonts; using PdfSharp.Forms; using PdfSharp.Internal; using PdfSharp.Pdf; using PdfSharp.SharpZipLib; using System.Diagnostics; using System.IO; namespace BCCI.Utils { public class PDFHelper { public static void CreatePdfFromForm(Form frm,string FilePath) { PdfDocument doc = new PdfDocument(); PdfPage p = doc.AddPage(); XGraphics xgr = XGraphics.FromPdfPage(p); Bitmap bm = new Bitmap(frm.Width, frm.Height); Graphics grfx = Graphics.FromImage(bm); grfx.CopyFromScreen(frm.Location.X, frm.Location.Y, 0, 0, frm.Size, CopyPixelOperation.SourceCopy); XImage img = XImage.FromGdiPlusImage(bm); p.Width = img.PixelWidth; p.Height = img.PixelHeight; p.Orientation = PageOrientation.Landscape; xgr.DrawImage(img,0,0); doc.Save(FilePath); doc.Close(); bm.Dispose(); grfx.Dispose(); img.Dispose(); xgr.Dispose(); } } }