Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36616.10 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unit-conversion-in-image-position", "Unit-conversion-in-image-position\Unit-conversion-in-image-position.csproj", "{9268CB04-C4C4-42C3-B54F-028667D9C921}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9268CB04-C4C4-42C3-B54F-028667D9C921}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9268CB04-C4C4-42C3-B54F-028667D9C921}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9268CB04-C4C4-42C3-B54F-028667D9C921}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9268CB04-C4C4-42C3-B54F-028667D9C921}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C5FD0AEE-BADF-4195-9FA4-7B85BD875DD8}
EndGlobalSection
EndGlobal
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;

//Create a new PDF document
using (PdfDocument document = new PdfDocument())
{
using (FileStream stream = new FileStream(Path.GetFullPath(@"Data/Input.png"), FileMode.Open, FileAccess.Read))
{
//Load the image from the disk
PdfBitmap image = new PdfBitmap(stream);

//Add the first section to the PDF document
PdfSection section = document.Sections.Add();

//Initialize unit converter
PdfUnitConverter converter = new PdfUnitConverter();

//Convert the image size from pixel to points
SizeF size = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Point);

//Set section size based on the image size
section.PageSettings.Size = size;

// Set section orientation based on the image size (by default Portrait)
if (image.Width > image.Height)
section.PageSettings.Orientation = PdfPageOrientation.Landscape;

//Set a margin for the section
section.PageSettings.Margins.All = 0;

//Add a page to the section
PdfPage page = section.Pages.Add();

//Draw image
page.Graphics.DrawImage(image, 0, 0);

//Save the document
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Unit_conversion_in_image_position</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Imaging.Net.Core" Version="*" />
</ItemGroup>

</Project>
Loading