Creating pdf from emf is loosing formatting
Posted: Tue Feb 24, 2015 2:43 pm
i am creating a pdf from the enhanced meta files. but after the pdf is created i am loosing the formatting from the emf's. if i have a number that is underline the underline is gone after the pdf created. here is my code and i am hoping someone will help me figure this out. Thanks.
Code: Select all
public static string CreatePdfFromIEnhanceMetaFile(List<string> filePath, string outPath)
{
if (filePath == null)
throw new ArgumentNullException();
if (outPath == null)
throw new ArgumentNullException();
try
{
int imagePdfObject;
if (!CreateBlankDocument(out imagePdfObject))
return string.Empty;
//loop thru each individual pages and add them to our pdf blank document
foreach (string filePage in filePath)
{
Metafile metafile = new Metafile(filePage);
// Get the handle of the enhanced metafile.
IntPtr hEmf = metafile.GetHenhmetafile();
try
{
int iPdfImage;
int iPdfPage;
if (IsFailed(PdfXCFunctions.PXC_AddEnhMetafile(imagePdfObject, hEmf, out iPdfImage)))
return string.Empty;
double imageWidth;
double imageHeight;
if (IsFailed(PdfXCFunctions.PXC_GetImageDimension(imagePdfObject, iPdfImage, out imageWidth, out imageHeight)))
return string.Empty;
int updatedHeight;
int updatedWidth;
MakeProportionalSize(imageWidth, imageHeight, out updatedWidth, out updatedHeight);
if (IsFailed(PdfXCFunctions.PXC_AddPage(imagePdfObject, updatedWidth, updatedHeight, out iPdfPage)))
return string.Empty;
if (IsFailed(PdfXCFunctions.PXC_PlaceImage(iPdfPage, iPdfImage, 0, updatedHeight, updatedWidth, updatedHeight)))
return string.Empty;
}
finally
{
//delete the handle
DeleteEnhMetaFile(hEmf); //free handle
}
}
//now write to a document if we fail return empty string
if (!WriteDocumentExA(outPath, imagePdfObject))
return string.Empty;
}
catch (Exception)
{
return string.Empty;
}
return outPath;
}