We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to export PDF document as metafile and save as EMF?

Platform: WinForms |
Control: PdfViewer |
Published Date: September 4, 2018 |
Last Revised Date: September 20, 2018

The PDF viewer for WF allows the user to export pages of the PDF document as Metafile, which is a vector format which does not lose quality when zooming.

Directly saving the Metafile image to disk with *.emf extension will save the resultant in scalar format which would result in quality loss. Here in the KB we have explained the way to save the metafile in *.emf format, which does not lead to quality loss.

 

private PdfViewerControl viewer = new PdfViewerControl();

viewer.Load("../../Data/HTTP Succinctly.pdf");

Metafile[] images ;

 

            if (allpageBtn.Checked)

            {

                images = this.viewer.ExportAsMetafile(0, viewer.PageCount - 1);

            }

            else

            {

                images = this.viewer.ExportAsMetafile((int)fromPage.Value - 1, (int)toPage.Value - 1);

            }

 

            foreach (Metafile image in images)

            {

             

                //Create new MemoryStream

                System.IO.MemoryStream metafileStream = new System.IO.MemoryStream();

                System.Drawing.Graphics OffScreenDC = System.Drawing.Graphics.FromHwndInternal(IntPtr.Zero);

                System.Drawing.Imaging.Metafile wrappedMetaFile = new System.Drawing.Imaging.Metafile(metafileStream, OffScreenDC.GetHdc(), System.Drawing.Imaging.EmfType.EmfOnly);

 

                //Draw image

                System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(wrappedMetaFile);

                g.DrawImage(image, 0, 0);

                g.Dispose();

 

                //Write to file

                System.IO.FileStream wfile = new System.IO.FileStream("../../Output/Output" + Guid.NewGuid().ToString() + ".emf", System.IO.FileMode.Create);

                metafileStream.WriteTo(wfile);

                wfile.Close();

                OffScreenDC.ReleaseHdc();

            }

 

Please find the sample from below link:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/ExportAsMetafileSample698644188



2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile