using (var image = (EmfImage)Aspose.Imaging.Image.Load(childEmfFilePath))
{
using (FileStream outputStream = new FileStream(childPdfFilePath, FileMode.Create))
{//Aspose分辨率为96
using (PdfOptions pdfOptions = new PdfOptions())
{
using (EmfRasterizationOptions emfRasterization = new EmfRasterizationOptions())
{
float resolution = (float)96.0;
if (this.deviceMode.Orientation == Orientation.Potrait)
{
emfRasterization.PageWidth = (float)(this.deviceMode.PaperWidth * resolution / 10 / 25.4);
emfRasterization.PageHeight = (float)(this.deviceMode.PaperLength * resolution / 10 / 25.4);
}
else
{
emfRasterization.PageHeight = (float)(this.deviceMode.PaperWidth * resolution / 10 / 25.4);
emfRasterization.PageWidth = (float)(this.deviceMode.PaperLength * resolution / 10 / 25.4);
}
emfRasterization.PageHeight = (float)(image.HeightF + 8.0 * 600.0 / 25.4) * resolution / deviceMode.YResolution;
emfRasterization.PageWidth = (float)(image.WidthF + 8.0 * 600.0 / 25.4) * resolution / deviceMode.YResolution;
pdfOptions.VectorRasterizationOptions = emfRasterization;
pdfOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting();
pdfOptions.ResolutionSettings.HorizontalResolution = resolution;
pdfOptions.ResolutionSettings.VerticalResolution = resolution;
}
try
{
image.Save(outputStream, pdfOptions);
filesPathList.Add(childPdfFilePath);
}
catch (Exception ex)
{
MsgLogHelper.WriteLog("SaveAsPDF", "EmfSpoolFile SaveToPdfByEmf Exception", ex, 2);
image.Dispose();
outputStream.Close();
if (File.Exists(childPdfFilePath))
{
File.Delete(childPdfFilePath);
}
}
}
}
}
1.zip (120.0 KB)
使用这段代码转emf文件为PDF,结果乱码,emf文件见1.zip