-
Notifications
You must be signed in to change notification settings - Fork 48
Task-972104-How to silent print PDF document using Syncfusion.Pdf.Net.Core Package? #181
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
Open
irfanajaffer
wants to merge
2
commits into
master
Choose a base branch
from
972104-SilentPrint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 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
...on/PDF-to-Image/How-to-silent-print-a-PDF-document/How-to-silent-print-a-PDF-document.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.13.35617.110 d17.13 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "How_to_silent_print_a_PDF_document", "How_to_silent_print_a_PDF_document\How_to_silent_print_a_PDF_document.csproj", "{C39DF450-AD95-418F-8946-A0F0FEB51117}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {C39DF450-AD95-418F-8946-A0F0FEB51117}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {C39DF450-AD95-418F-8946-A0F0FEB51117}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {C39DF450-AD95-418F-8946-A0F0FEB51117}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {C39DF450-AD95-418F-8946-A0F0FEB51117}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {A4847A47-8765-447B-BE70-E32347BCCF00} | ||
| EndGlobalSection | ||
| EndGlobal | ||
Binary file added
BIN
+14.6 MB
...mage/How-to-silent-print-a-PDF-document/How-to-silent-print-a-PDF-document/Data/Input.pdf
Binary file not shown.
17 changes: 17 additions & 0 deletions
17
...PDF-document/How-to-silent-print-a-PDF-document/How-to-silent-print-a-PDF-document.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,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" /> | ||
| <PackageReference Include="Syncfusion.PdfToImageConverter.Net" Version="*" /> | ||
| <PackageReference Include="System.Drawing.Common" Version="*" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
56 changes: 56 additions & 0 deletions
56
...to-Image/How-to-silent-print-a-PDF-document/How-to-silent-print-a-PDF-document/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,56 @@ | ||
| using Syncfusion.PdfToImageConverter; | ||
| using System.Drawing; | ||
| using System.Drawing.Printing; | ||
|
|
||
| class Program | ||
| { | ||
| static Bitmap[] bitmaps; | ||
| static int currentPageIndex = 0; | ||
| static void Main() | ||
| { | ||
| // Initialize PDF to Image converter. | ||
| PdfToImageConverter imageConverter = new PdfToImageConverter(); | ||
| // Load the PDF document as a stream | ||
| using (FileStream inputStream = new FileStream("Data/Input.pdf", FileMode.Open, FileAccess.ReadWrite)) | ||
|
||
| { | ||
| imageConverter.Load(inputStream); | ||
| // Convert PDF to Image. | ||
| Stream[] outputStream = imageConverter.Convert(0, imageConverter.PageCount - 1, false, false); | ||
| // Convert streams to bitmaps. | ||
| bitmaps = BitmapConverter.ConvertStreamsToBitmaps(outputStream); | ||
| } | ||
| // Initialize PrintDocument | ||
| PrintDocument printDocument = new PrintDocument(); | ||
| // Attach the PrintPage event handler | ||
| printDocument.PrintPage += PrintDocument_PrintPage; | ||
| // Print the document | ||
| printDocument.Print(); | ||
| } | ||
| private static void PrintDocument_PrintPage(object sender, PrintPageEventArgs e) | ||
| { | ||
| Bitmap bitmap = bitmaps[currentPageIndex]; | ||
| Graphics graphics = e.Graphics; | ||
| // Center the image on the page without scaling | ||
| float offsetX = (e.PageBounds.Width - bitmap.Width) / 2; | ||
| float offsetY = (e.PageBounds.Height - bitmap.Height) / 2; | ||
| graphics.DrawImage(bitmap, offsetX, offsetY); | ||
| currentPageIndex++; | ||
| e.HasMorePages = currentPageIndex < bitmaps.Length; | ||
| if (!e.HasMorePages) | ||
| { | ||
| currentPageIndex = 0; | ||
| } | ||
| } | ||
| public static class BitmapConverter | ||
| { | ||
| public static Bitmap[] ConvertStreamsToBitmaps(Stream[] streams) | ||
| { | ||
| Bitmap[] bitmaps = new Bitmap[streams.Length]; | ||
| for (int i = 0; i < streams.Length; i++) | ||
| { | ||
| bitmaps[i] = new Bitmap(streams[i]); | ||
| } | ||
| return bitmaps; | ||
| } | ||
| } | ||
| } | ||
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.
The project file and folder name are mentioned wrongly in the sln file. How it will be working on your end?