Skip to content

Commit 47d9c26

Browse files
committed
1043654: Added sample code for EMF to PDF
1 parent 64a4d91 commit 47d9c26

5 files changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.37516.0 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Converting-Metafile-to-PDF", "Converting-Metafile-to-PDF\Converting-Metafile-to-PDF.csproj", "{4AC761AC-C0CB-4022-93B4-DF27830765AF}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{4AC761AC-C0CB-4022-93B4-DF27830765AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{4AC761AC-C0CB-4022-93B4-DF27830765AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{4AC761AC-C0CB-4022-93B4-DF27830765AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{4AC761AC-C0CB-4022-93B4-DF27830765AF}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {8683346D-D856-4171-A269-2B4AFB761FD7}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Converting_Metafile_to_PDF</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.MetafileRenderer.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Input.emf">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
</ItemGroup>
20+
</Project>
Binary file not shown.

Images/Converting-Metafile-to-PDF/.NET/Converting-Metafile-to-PDF/Output/gitkeep.txt

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Syncfusion.Drawing;
2+
using Syncfusion.Metafile;
3+
using Syncfusion.Pdf;
4+
using Syncfusion.Pdf.Graphics;
5+
6+
//Create a new PDF document.
7+
PdfDocument document = new PdfDocument();
8+
//Open the WMF file as a stream.
9+
using (FileStream metafileStream = new FileStream(Path.GetFullPath(@"Data/Input.emf"), FileMode.Open, FileAccess.Read))
10+
{
11+
//Create a new instance of the MetafileRenderer class.
12+
MetafileRenderer renderer = new MetafileRenderer();
13+
//Convert the Metafile stream to a PdfTemplate.
14+
PdfTemplate template = renderer.ConvertToPdfTemplate(metafileStream);
15+
//Set the page size to match the template size.
16+
document.PageSettings.Size = new SizeF(template.Size);
17+
//Remove page margins.
18+
document.PageSettings.Margins.All = 0;
19+
//Add a page to the document.
20+
PdfPage page = document.Pages.Add();
21+
//Get the PDF page graphics.
22+
PdfGraphics graphics = page.Graphics;
23+
//Draw the template on the PDF page.
24+
graphics.DrawPdfTemplate(template, PointF.Empty);
25+
}
26+
//Save the PDF document.
27+
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
28+
//Close the document.
29+
document.Close(true);

0 commit comments

Comments
 (0)