EMF Meta-file to PDF Conversion inside .NET Apps
Using Aspose.Imaging for Java, developers can convert EMF metafile to PDF format. Aspose.Imaging provides the EmfImage class to load EMF files and same can be used to save the image to PDF format. Below provided sample code demonstrate how to convert EMF to PDF.
String[] filePaths = new String[] {
"input\FilledRectangleRotateMode_c.emf",
"input\image5.emf",
"input\LinearGradientBrushCircuitMode.emf",
"input\Pict.emf",
"input\Picture1.emf",
"input\test.emf",
"input\wrong-font-size.emf"
};
for (String filePath : filePaths)
{
String outPath = filePath + ".pdf";
com.aspose.imaging.fileformats.emf.EmfImage image = com.aspose.imaging.fileformats.emf.EmfImage.load(filePath);
try
{
com.aspose.imaging.system.io.FileStream outputStream =
new com.aspose.imaging.system.io.FileStream(outPath, com.aspose.imaging.system.io.FileMode.Create);
try
{
if(!image.getHeader().getEmfHeader().getValid())
{
throw new com.aspose.imaging.exceptions.ImageLoadException("The file" + outPath +" is not valid");
}
com.aspose.imaging.imageoptions.EmfRasterizationOptions emfRasterization =
new com.aspose.imaging.imageoptions.EmfRasterizationOptions();
emfRasterization.setPageWidth(image.getWidth());
emfRasterization.setPageHeight(image.getHeight());
emfRasterization.setBackgroundColor(com.aspose.imaging.Color.getWhiteSmoke());
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(emfRasterization);
image.save(outputStream.toOutputStream(), pdfOptions);
}
finally
{
outputStream.close();
outputStream.dispose();
}
}
finally
{
image.dispose();
}
}
Written by zondray
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Java imaging api
Authors
Related Tags
#java imaging api
#convert emf to pdf
#create blur effect on image
#import image to psd layer
#
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#