Skip to content

Commit 797e8d2

Browse files
committed
synch
1 parent 6740475 commit 797e8d2

File tree

7 files changed

+157
-13
lines changed

7 files changed

+157
-13
lines changed

Ghostscript.NET.Samples/Ghostscript.NET.Samples.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<Compile Include="Samples\DeviceUsageSample.cs" />
7878
<Compile Include="Samples\PipedOutputSample.cs" />
7979
<Compile Include="Samples\ProcessorSample1.cs" />
80+
<Compile Include="Samples\RasterizerCropSample.cs" />
8081
<Compile Include="Samples\RasterizerSample1.cs" />
8182
<Compile Include="Samples\RasterizerSample2.cs" />
8283
<Compile Include="Samples\SendToPrinterSample.cs" />

Ghostscript.NET.Samples/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ static void Main(string[] args)
4949
//sample = new FindInstalledGhostscriptVersionsSample();
5050
//sample = new RunMultipleInstancesSample();
5151
//sample = new ViewerSample();
52-
sample = new RasterizerSample1();
52+
//sample = new RasterizerSample1();
5353
//sample = new RasterizerSample2();
5454
//sample = new AddWatermarkSample();
5555
//sample = new DeviceUsageSample();
56-
//sample = new PipedOutputSample();
56+
sample = new PipedOutputSample();
5757
//sample = new SendToPrinterSample();
58+
//sample = new RasterizerCropSample();
5859

5960
sample.Start();
6061

Ghostscript.NET.Samples/Samples/ProcessorSample1.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@
2727
using System;
2828
using System.Collections.Generic;
2929
using Ghostscript.NET.Processor;
30+
using System.IO;
31+
using System.Drawing;
3032

3133
namespace Ghostscript.NET.Samples
3234
{
3335
public class ProcessorSample1 : ISample
3436
{
3537
public void Start()
3638
{
39+
Start2();
40+
return;
41+
3742
string inputFile = @"E:\gss_test\test.pdf";
3843
string outputFile = @"E:\gss_test\output\page-%03d.png";
3944

@@ -68,5 +73,62 @@ void ghostscript_Processing(object sender, GhostscriptProcessorProcessingEventAr
6873
{
6974
Console.WriteLine(e.CurrentPage.ToString() + " / " + e.CurrentPage.ToString());
7075
}
76+
77+
private void Start2()
78+
{
79+
string inputFile = @"E:\__test_data\i1.pdf";
80+
string outputFile = @"E:\gss_test\output\page-%03d.png";
81+
82+
GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput();
83+
84+
string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2");
85+
86+
using (GhostscriptProcessor processor = new GhostscriptProcessor())
87+
{
88+
//"C:\Program Files\gs\gs9.15\bin\gswin64.exe" -sDEVICE=tiff24nc -r300 -dNOPAUSE -dBATCH -sOutputFile="Invoice 1_%03ld.tiff" "Invoice 1.pdf"
89+
90+
List<string> switches = new List<string>();
91+
switches.Add("-empty");
92+
switches.Add("-dQUIET");
93+
switches.Add("-dSAFER");
94+
switches.Add("-dBATCH");
95+
switches.Add("-dNOPAUSE");
96+
switches.Add("-dNOPROMPT");
97+
switches.Add("-dPrinted");
98+
switches.Add("-sDEVICE=pdfwrite");
99+
//switches.Add("-sDEVICE=tiffsep1");
100+
switches.Add("-sOutputFile=" + outputPipeHandle);
101+
//switches.Add("-q");
102+
switches.Add("-f");
103+
switches.Add(inputFile);
104+
105+
try
106+
{
107+
processor.Process(switches.ToArray());
108+
109+
byte[] rawDocumentData = gsPipedOutput.Data;
110+
var memStream = new MemoryStream(rawDocumentData);
111+
//var image = new Bitmap(memStream);
112+
//image.Save(@"Invocie 1.tiff");
113+
//if (writeToDatabase)
114+
//{
115+
// Database.ExecSP("add_document", rawDocumentData);
116+
//}
117+
//else if (writeToDisk)
118+
//{
119+
// File.WriteAllBytes(@"E:\gss_test\output\test_piped_output.pdf", rawDocumentData);
120+
//}
121+
}
122+
catch (Exception ex)
123+
{
124+
Console.WriteLine(ex.Message);
125+
}
126+
finally
127+
{
128+
gsPipedOutput.Dispose();
129+
gsPipedOutput = null;
130+
}
131+
}
132+
}
71133
}
72134
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//
2+
// RasterizerSample.cs
3+
// This file is part of Ghostscript.NET.Samples project
4+
//
5+
// Author: Josip Habjan (habjan@gmail.com, http://www.linkedin.com/in/habjan)
6+
// Copyright (c) 2013-2015 by Josip Habjan. All rights reserved.
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining
9+
// a copy of this software and associated documentation files (the
10+
// "Software"), to deal in the Software without restriction, including
11+
// without limitation the rights to use, copy, modify, merge, publish,
12+
// distribute, sublicense, and/or sell copies of the Software, and to
13+
// permit persons to whom the Software is furnished to do so, subject to
14+
// the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be
17+
// included in all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
27+
using System;
28+
using System.Drawing;
29+
using System.Drawing.Imaging;
30+
using System.IO;
31+
32+
// required Ghostscript.NET namespaces
33+
using Ghostscript.NET;
34+
using Ghostscript.NET.Rasterizer;
35+
36+
namespace Ghostscript.NET.Samples
37+
{
38+
39+
/// <summary>
40+
/// GhostscriptRasterizer allows you to rasterize pdf and postscript files into the
41+
/// memory. If you want Ghostscript to store files on the disk use GhostscriptProcessor
42+
/// or one of the GhostscriptDevices (GhostscriptPngDevice, GhostscriptJpgDevice).
43+
/// </summary>
44+
public class RasterizerCropSample : ISample
45+
{
46+
public void Start()
47+
{
48+
int desired_x_dpi = 300;
49+
int desired_y_dpi = 300;
50+
51+
string inputPdfPath = @"E:\__test_data\test2.pdf";
52+
string outputPath = @"E:\__test_data\output\";
53+
54+
using (GhostscriptRasterizer rasterizer = new GhostscriptRasterizer())
55+
{
56+
rasterizer.CustomSwitches.Add("-dUseCropBox");
57+
rasterizer.CustomSwitches.Add("-c");
58+
rasterizer.CustomSwitches.Add("[/CropBox [24 72 559 794] /PAGES pdfmark");
59+
rasterizer.CustomSwitches.Add("-f");
60+
61+
rasterizer.Open(inputPdfPath);
62+
63+
for (int pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++)
64+
{
65+
string pageFilePath = Path.Combine(outputPath, "Page-" + pageNumber.ToString() + ".png");
66+
67+
Image 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+
}
76+

Ghostscript.NET.Samples/Samples/RasterizerSample1.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@ namespace Ghostscript.NET.Samples
4343
/// </summary>
4444
public class RasterizerSample1 : ISample
4545
{
46-
private GhostscriptVersionInfo _lastInstalledVersion = null;
47-
4846
public void Start()
4947
{
50-
int desired_x_dpi = 96;
51-
int desired_y_dpi = 96;
48+
int desired_x_dpi = 300;
49+
int desired_y_dpi = 300;
5250

53-
string inputPdfPath = @"E:\gss_test\test.pdf";
54-
string outputPath = @"E:\gss_test\output\";
51+
string inputPdfPath = @"E:\__test_data\test2.pdf";
52+
string outputPath = @"E:\__test_data\output\";
5553

5654
using (GhostscriptRasterizer rasterizer = new GhostscriptRasterizer())
5755
{

Ghostscript.NET.Samples/Samples/RasterizerSample2.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ namespace Ghostscript.NET.Samples
4343
/// </summary>
4444
public class RasterizerSample2 : ISample
4545
{
46-
private GhostscriptVersionInfo _lastInstalledVersion = null;
47-
4846
public void Start()
4947
{
5048
int desired_x_dpi = 96;
@@ -53,9 +51,6 @@ public void Start()
5351
string inputPdfPath = @"E:\gss_test\test.pdf";
5452
string outputPath = @"E:\gss_test\output\";
5553

56-
57-
_lastInstalledVersion = GhostscriptVersionInfo.GetLastInstalledVersion();
58-
5954
using (GhostscriptRasterizer rasterizer = new GhostscriptRasterizer())
6055
{
6156
/* custom switches can be added before the file is opened

VERSION-HISTORY

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212

1313
HISTORY of the Ghostscript.NET library
1414

15+
1.2.1. 2015-03-??
16+
-------------------------
17+
- GhostscriptRasterizer - added a constructor to allow capture of IO using GhostscriptStdIO
18+
(Rasterizer samples updated with example of using GhostscriptStdIO)
19+
- GhostscriptViewer - added GridFitTT=0 to improve text quality.
20+
- GhostscriptViewer - added public setter for DPI settings in viewer.
21+
- GhostscriptViewre - change zoom method to public.
22+
- GhostscriptViewer - set test to false by default in Zoom method.
23+
- GhostscriptViewer - changed ShowAfterOpen to public to set parameters without having
24+
to generate a pdf
25+
1526
1.2.0. 2015-02-05
1627
-------------------------
1728
- fixed problem with checking for pdf file header signature in pdf files that has

0 commit comments

Comments
 (0)