Skip to content

Commit 1b5fb9a

Browse files
898803
1 parent 4b18dec commit 1b5fb9a

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed
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.9.34622.214
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{4343B126-0BE7-4A4C-BD14-CEFB86AA8DF2}"
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+
{4343B126-0BE7-4A4C-BD14-CEFB86AA8DF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{4343B126-0BE7-4A4C-BD14-CEFB86AA8DF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{4343B126-0BE7-4A4C-BD14-CEFB86AA8DF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{4343B126-0BE7-4A4C-BD14-CEFB86AA8DF2}.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 = {420AD2DD-DF09-4048-9EDC-E17668C6235F}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.PdfToImageConverter.Net" Version="*" />
12+
<PackageReference Include="System.Drawing.Common" Version="8.0.6" />
13+
</ItemGroup>
14+
15+
</Project>
Binary file not shown.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using SkiaSharp;
2+
using Syncfusion.PdfToImageConverter;
3+
using System.Drawing;
4+
using System.Drawing.Printing;
5+
using System.IO;
6+
7+
namespace ConsoleApp
8+
{
9+
internal class Program
10+
{
11+
static int itr = 0;
12+
static Bitmap[] bitmaps;
13+
static void Main(string[] args)
14+
{
15+
//Initialize PDF to Image converter.
16+
PdfToImageConverter imageConverter = new PdfToImageConverter();
17+
//Load the PDF document as a stream
18+
FileStream inputStream = new FileStream("../../../Input.pdf", FileMode.Open, FileAccess.ReadWrite);
19+
imageConverter.Load(inputStream);
20+
bitmaps = new Bitmap[imageConverter.PageCount - 1];
21+
//Convert PDF to Image.
22+
Stream[] outputStream = imageConverter.Convert(0, imageConverter.PageCount - 1, false, false);
23+
bitmaps = BitmapConverter.ConvertStreamsToBitmaps(outputStream);
24+
PrintDocument printDocument = new PrintDocument();
25+
printDocument.PrintPage += PrintDocument_PrintPage;
26+
printDocument.Print();
27+
}
28+
29+
private static void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
30+
{
31+
e.Graphics.DrawImage(bitmaps[itr], 0, 0, e.PageBounds.Width, e.PageBounds.Height);
32+
e.HasMorePages = itr < bitmaps.Length - 1;
33+
itr = itr + 1;
34+
}
35+
}
36+
37+
public class BitmapConverter
38+
{
39+
public static Bitmap[] ConvertStreamsToBitmaps(Stream[] streams)
40+
{
41+
Bitmap[] bitmaps = new Bitmap[streams.Length];
42+
43+
for (int i = 0; i < streams.Length; i++)
44+
{
45+
bitmaps[i] = new Bitmap(streams[i]);
46+
}
47+
48+
return bitmaps;
49+
}
50+
}
51+
52+
}

0 commit comments

Comments
 (0)