Skip to content

Commit 3698b4b

Browse files
Merge pull request #3957 from syncfusion-content/1043654-h
1043654-h: Added Vector Image Support for Cross-Platform
2 parents 284b8ca + d7ee924 commit 3698b4b

1 file changed

Lines changed: 36 additions & 4 deletions

File tree

Document-Processing/PDF/PDF-Library/NET/Working-with-Images.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,43 @@ Syncfusion<sup>&reg;</sup> PDF supports adding metafile vector images. During th
285285
* EMF Plus Dual
286286
* WMF (Windows Metafile)
287287

288-
The [PdfMetafile](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfMetafile.html) class is used to load metafile images. The [PdfMetafileLayoutFormat](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfMetafileLayoutFormat.html) class allows you to control how the metafile is paginated across multiple pages, including options to split text and images at page boundaries.
288+
For cross-platform .NET applications, install the [Syncfusion.MetafileRenderer.Net.Core](https://www.nuget.org/packages/Syncfusion.MetafileRenderer.Net.Core) NuGet package from [NuGet.org](https://www.nuget.org/). This package provides the `MetafileRenderer` class, which converts EMF and WMF streams into PDF templates that can be rendered in PDF documents.
289289

290-
The following code example illustrates this,
290+
For Windows-specific applications, The [PdfMetafile](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfMetafile.html) class loads EMF images, and the [PdfMetafileLayoutFormat](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfMetafileLayoutFormat.html) class allows you to control how text and images are split across pages in the PDF document. The following code example illustrates this.
291291

292292
{% tabs %}
293293

294294
{% highlight c# tabtitle="C# [Cross-platform]" %}
295295

296-
//PDF doesn't support inserting a vector image C#.NET Cross platforms.
296+
using Syncfusion.Drawing;
297+
using Syncfusion.Metafile;
298+
using Syncfusion.Pdf;
299+
using Syncfusion.Pdf.Graphics;
300+
301+
//Create a new PDF document.
302+
PdfDocument document = new PdfDocument();
303+
//Open the EMF file as a stream.
304+
using (FileStream metafileStream = new FileStream("Input.emf", FileMode.Open, FileAccess.Read))
305+
{
306+
//Create a new instance of the MetafileRenderer class.
307+
MetafileRenderer renderer = new MetafileRenderer();
308+
//Convert the Metafile stream to a PdfTemplate.
309+
PdfTemplate template = renderer.ConvertToPdfTemplate(metafileStream);
310+
//Set the page size to match the template size.
311+
document.PageSettings.Size = new Syncfusion.Drawing.SizeF(template.Size);
312+
//Remove page margins.
313+
document.PageSettings.Margins.All = 0;
314+
//Add a page to the document.
315+
PdfPage page = document.Pages.Add();
316+
//Get the PDF page graphics.
317+
PdfGraphics graphics = page.Graphics;
318+
//Draw the template on the PDF page.
319+
graphics.DrawPdfTemplate(template, PointF.Empty);
320+
}
321+
//Save the PDF document.
322+
document.Save("Output.pdf");
323+
//Close the document.
324+
document.Close(true);
297325

298326
{% endhighlight %}
299327

@@ -359,7 +387,11 @@ doc.Close(True)
359387

360388
{% endtabs %}
361389

362-
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Images/Insert-vector-image-in-a-PDF-document/).
390+
You can download a complete working Cross-platform sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Images/Converting-Metafile-to-PDF/.NET).
391+
392+
You can download a complete working Window-specific sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Images/Insert-vector-image-in-a-PDF-document/).
393+
394+
N> EMF and WMF images can be converted on cross-platform .NET applications by using the `Syncfusion.MetafileRenderer.Net.Core` NuGet package. On Windows-specific platforms, you can also use the PdfMetafile class for rendering Metafile images directly into PDF documents.
363395

364396
## Working with image masking
365397

0 commit comments

Comments
 (0)