Hi,
I just downloaded ASPOSE.Words .Net 9.5. In my test application I’m trying to convert an EMF file to PDF, but the output doesn’t seem to recognize the appropriate font/encoding (?) I’m attaching both the source EMF file (a screenshot of this website), source.emf, and the PDF generated (output1.pdf).
Here is the code I’m using (taken from the examples I found in this forum). I tried different combinations for the PDF options object to no avail:
Document doc = new Document();
doc.RemoveAllChildren();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.PageSetup.LeftMargin = Aspose.Words.ConvertUtil.MillimeterToPoint(10);
builder.PageSetup.RightMargin = Aspose.Words.ConvertUtil.MillimeterToPoint(10);
// read the image from file, ensure it is disposed.
using (Image image = Image.FromFile(sSourceEMFFilePath))
{
// get the number of frames in the image.
int framesCount = image.GetFrameCount(FrameDimension.Page);
// loop through all frames.
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)
{
// insert a section break before each new page, in case of a multi-frame TIFF.
if (frameIdx != 0)
builder.InsertBreak(BreakType.SectionBreakNewPage);
// select active frame.
image.SelectActiveFrame(FrameDimension.Page, frameIdx);
// we want the size of the page to be the same as the size of the image.
// convert pixels to points to size the page to the actual image size.
PageSetup ps = builder.PageSetup;
ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
// insert the image into the document and position it at the top left corner of the page.
builder.InsertImage(
image,
RelativeHorizontalPosition.Page,
0,
RelativeVerticalPosition.Page,
0,
ps.PageWidth,
ps.PageHeight,
WrapType.None);
}
}
var pdfOps = new PdfSaveOptions()
{
JpegQuality = 80,
//IsPreserveFormFields = false,
TextCompression = PdfTextCompression.None,
//IsEmbedTrueTypeFontsForAsciiChars = false,
EmbedFullFonts = false,
PrettyFormat = false,
SaveFormat = SaveFormat.Pdf,
};
// save the document to PDF temp file
sOutPDFFilePath = Path.ChangeExtension(Path.GetTempFileName(), ".pdf");
doc.Save(sOutPDFFilePath, pdfOps);
Just for testing purposes I also tried rasterizing the image before adding it to the document with the code below (also found in these forums) and that produced a legible PDF document, although of far inferior quality (not being vector and all that). It also has some weird black background. I attached output2.pdf so you can see the output.
using (MemoryStream resterImageStream = new MemoryStream())
{
image.Save(resterImageStream, ImageFormat.Jpeg);
// insert the image into the document and position it at the top left corner of the page.
builder.InsertImage(
resterImageStream,
RelativeHorizontalPosition.Page,
0,
RelativeVerticalPosition.Page,
0,
ps.PageWidth,
ps.PageHeight,
WrapType.None);
}
Any ideas what could be wrong or how to achieve the EMF to PDF conversion in vector mode? Thank you in advance for your help.
Esteban