-
Notifications
You must be signed in to change notification settings - Fork 48
260329: Added the code sample for create PDF page based on the image size using PdfUnitConvertor class #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
Images/Unit-conversion-in-image-position/.NET/Unit-conversion-in-image-position.sln
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Binary file added
BIN
+20.9 KB
...version-in-image-position/.NET/Unit-conversion-in-image-position/Data/Input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
41 changes: 41 additions & 0 deletions
41
Images/Unit-conversion-in-image-position/.NET/Unit-conversion-in-image-position/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.Pixel); | ||
|
|
||
| //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")); | ||
| } | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
...-position/.NET/Unit-conversion-in-image-position/Unit-conversion-in-image-position.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we convert the image physicalDimension from pixel to point, then the PdfGraphicsUnit must be specified as point. Can you cross check and update it.