Convert EMF to PDF
Contents
[
Hide
]EMFEMF stores graphical images device-independently. Metafiles of EMF comprises of variable-length records in chronological order that can render the stored image after parsing on any output device. Furthermore, you can convert EMF to PDF image using the below steps:
- Firstly, initialize Document class object
- Load EMF image file
- Add the loaded EMF image to a Page
- Save PDF document
Moreover, the following code snippet shows how to convert an EMF to PDF with C# in your .NET code snippet:
// Initialize new PDF document
var doc = new Document();
// Spcify path of input EMF image file
var imageFile = dataDir + "drawing.emf";
var page = doc.Pages.Add();
string file = imageFile;
FileStream filestream = new FileStream(file, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(filestream);
long numBytes = new FileInfo(file).Length;
byte[] bytearray = reader.ReadBytes((int)numBytes);
Stream stream = new MemoryStream(bytearray);
var b = new Bitmap(stream);
// Specify page dimesion properties
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Left = 0;
page.PageInfo.Margin.Right = 0;
page.PageInfo.Width = b.Width;
page.PageInfo.Height = b.Height;
var image = new Aspose.Pdf.Image();
image.File = imageFile;
page.Paragraphs.Add(image);
//Save output PDF document
doc.Save(dataDir + "EMFtoPDF.pdf");