File tree 3 files changed +64
-3
lines changed
Ghostscript.NET.Samples/Samples
3 files changed +64
-3
lines changed Original file line number Diff line number Diff line change @@ -42,16 +42,49 @@ namespace Ghostscript.NET.Samples
42
42
/// </summary>
43
43
public class RasterizerSample1 : ISample
44
44
{
45
- private GhostscriptVersionInfo _lastInstalledVersion = null ;
46
-
47
45
public void Start ( )
46
+ {
47
+ Sample1 ( ) ;
48
+ Sample2 ( ) ;
49
+ }
50
+
51
+ public void Sample1 ( )
48
52
{
49
53
int desired_x_dpi = 96 ;
50
54
int desired_y_dpi = 96 ;
51
55
52
56
string inputPdfPath = @"E:\gss_test\test.pdf" ;
53
57
string outputPath = @"E:\gss_test\output\" ;
54
58
59
+ using ( var rasterizer = new GhostscriptRasterizer ( ) )
60
+ {
61
+ rasterizer . Open ( inputPdfPath ) ;
62
+
63
+ for ( var pageNumber = 1 ; pageNumber <= rasterizer . PageCount ; pageNumber ++ )
64
+ {
65
+ var pageFilePath = Path . Combine ( outputPath , string . Format ( "Page-{0}.png" , pageNumber ) ) ;
66
+
67
+ var img = rasterizer . GetPage ( desired_x_dpi , desired_y_dpi , pageNumber ) ;
68
+ img . Save ( pageFilePath , ImageFormat . Png ) ;
69
+
70
+ Console . WriteLine ( pageFilePath ) ;
71
+ }
72
+ }
73
+ }
74
+
75
+ public void Sample2 ( )
76
+ {
77
+ int desired_x_dpi = 96 ;
78
+ int desired_y_dpi = 96 ;
79
+
80
+ string inputPdfPath = @"E:\gss_test\test.pdf" ;
81
+ string outputPath = @"E:\gss_test\output\" ;
82
+
83
+ var output = new DelegateStdIOHandler (
84
+ stdOut : Console . WriteLine ,
85
+ stdErr : Console . WriteLine
86
+ ) ;
87
+
55
88
using ( var rasterizer = new GhostscriptRasterizer ( output ) )
56
89
{
57
90
rasterizer . Open ( inputPdfPath ) ;
Original file line number Diff line number Diff line change @@ -46,12 +46,22 @@ public class GhostscriptRasterizer : IDisposable
46
46
47
47
#region Constructor
48
48
49
- public GhostscriptRasterizer ( )
49
+ public GhostscriptRasterizer ( GhostscriptStdIO stdIo )
50
50
{
51
51
_viewer = new GhostscriptViewer ( ) ;
52
52
_viewer . ShowPageAfterOpen = false ;
53
53
_viewer . ProgressiveUpdate = false ;
54
54
_viewer . DisplayPage += new GhostscriptViewerViewEventHandler ( _viewer_DisplayPage ) ;
55
+
56
+ if ( stdIo != null )
57
+ {
58
+ _viewer . AttachStdIO ( stdIo ) ;
59
+ }
60
+ }
61
+
62
+ public GhostscriptRasterizer ( )
63
+ : this ( default ( GhostscriptStdIO ) )
64
+ {
55
65
}
56
66
57
67
#endregion
Original file line number Diff line number Diff line change @@ -1040,6 +1040,24 @@ public List<string> CustomSwitches
1040
1040
1041
1041
#endregion
1042
1042
1043
+ #region DPI
1044
+
1045
+ public int Dpi
1046
+ {
1047
+ get { return ZoomXDpi ; }
1048
+ set
1049
+ {
1050
+ ZoomXDpi = value ;
1051
+ ZoomYDpi = value ;
1052
+ }
1053
+ }
1054
+
1055
+ #endregion
1056
+
1057
+ #endregion
1058
+
1059
+ #region Internal properties
1060
+
1043
1061
#region ShowPageAfterOpen
1044
1062
1045
1063
public bool ShowPageAfterOpen
You can’t perform that action at this time.
0 commit comments