Skip to content

Commit c043411

Browse files
committed
synch
1 parent ed0bd65 commit c043411

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

Ghostscript.NET.Samples/Samples/RasterizerSample1.cs

+35-2
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,49 @@ namespace Ghostscript.NET.Samples
4242
/// </summary>
4343
public class RasterizerSample1 : ISample
4444
{
45-
private GhostscriptVersionInfo _lastInstalledVersion = null;
46-
4745
public void Start()
46+
{
47+
Sample1();
48+
Sample2();
49+
}
50+
51+
public void Sample1()
4852
{
4953
int desired_x_dpi = 96;
5054
int desired_y_dpi = 96;
5155

5256
string inputPdfPath = @"E:\gss_test\test.pdf";
5357
string outputPath = @"E:\gss_test\output\";
5458

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+
5588
using (var rasterizer = new GhostscriptRasterizer(output))
5689
{
5790
rasterizer.Open(inputPdfPath);

Ghostscript.NET/Rasterizer/GhostscriptRasterizer.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,22 @@ public class GhostscriptRasterizer : IDisposable
4646

4747
#region Constructor
4848

49-
public GhostscriptRasterizer()
49+
public GhostscriptRasterizer(GhostscriptStdIO stdIo)
5050
{
5151
_viewer = new GhostscriptViewer();
5252
_viewer.ShowPageAfterOpen = false;
5353
_viewer.ProgressiveUpdate = false;
5454
_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+
{
5565
}
5666

5767
#endregion

Ghostscript.NET/Viewer/GhostscriptViewer.cs

+18
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,24 @@ public List<string> CustomSwitches
10401040

10411041
#endregion
10421042

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+
10431061
#region ShowPageAfterOpen
10441062

10451063
public bool ShowPageAfterOpen

0 commit comments

Comments
 (0)