Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Jun 02, 2020 6:37 pm

Whenever I try to add a WMF file into a PDF, the page that has it does not display it correctly. I am attaching the WMF I am using here.

I can browse the WMF file in Windows Explorer, paste it into MS Paint, all other viewing of it works fine, but when adding into Spire.PDF it is distorted, image is too small while the text is too huge, it's all scrunched up in the upper left corner of the page, and other anomalies. I have tried changing the PdfMetafile's PageUnit and PageScale, I have adjusted the size used on the Page.Canvas.Draw, just about everything I can think of to make this work. I do know that when this WMF is turned into a Bitmap and that Bitmap is inserted into the page, it looks just fine, however this is not the desired result as want a text searchable PDF and a raster image is not searchable.

The code below is mostly what I am using to do this, edited to keep non-PDF related source out as it's a long func otherwise. If you see any obvious issues with it, I'd appreciate knowing. Thanks!

var pdf = new PdfDocument());

pdf.PageSettings.SetMargins(0, 0, 0, 0);

PdfSection section = pdf.Sections.Add();
var bmp = new PdfMetafile((Metafile)sketchPage.Image); // sketchPage.Image is a Metafile object that was exported to create the attached WMF
PdfPageBase pdfPage = section.Pages.Add();

pdfPage.Canvas.DrawImage(bmp, 1F, 1F, pdfPage.ActualSize.Width, pdfPage.ActualSize.Height);

pdfPage.Canvas.Save();
pdf.SaveToFile(pdfSaveFileDialog.FileName);
pdf.Close();

[email protected]
 
Posts: 1
Joined: Wed Aug 31, 2016 4:15 pm

Wed Jun 03, 2020 8:26 am

Hello,

Thanks for your inquiry.
Sorry our Spire.PDF doesn't support adding a WMF file directly into a PDF file, we currently only support turning it to bitmap and then drawing it to the page at present. However, we will consider adding it as a new feature to our upgrade list. If it can be implemented in the future, we will let you know.
Sorry for the inconvenience caused.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Jun 24, 2020 7:49 am

Hello,

Hope you are doing well.
After analyzing the internal data of the WMF file you provided, we found that it is actually a PNG file, which means that it is essentially a bitmap, as shown below.
internal_data.png

To help us further investigate the issue regarding how to add a WMF file into a PDF file, could you please provide a real WMF file again? Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF

cron