Articles in this section
Category / Section

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

1 min read

The WinForms 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:

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

 

Conclusion

I hope you enjoyed learning about how to export PDF document as metafile and save as EMF.

You can refer to our WinForms PDF Viewer feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF Viewer documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied