-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathExample1.cs
More file actions
60 lines (53 loc) · 1.77 KB
/
Example1.cs
File metadata and controls
60 lines (53 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Text;
using GhostscriptSharp;
using System.Runtime.InteropServices;
namespace Examples
{
/// <summary>
/// Example of using GS DLL as a ps2pdf converter.
/// </summary>
/// <remarks>Port of Ghostscript Example code at http://pages.cs.wisc.edu/~ghost/doc/cvs/API.htm</remarks>
class Example1
{
public const String KernelDllName = "kernel32.dll";
public const String GhostscriptDllDirectory = @"C:\Program Files\gs\gs8.71\bin";
[DllImport(KernelDllName, SetLastError = true)]
static extern int SetDllDirectory(string lpPathName);
static void Main(string[] args)
{
IntPtr minst;
int code, code1;
string[] gsargv = new string[10];
gsargv[0] = "ps2pdf"; /* actual value doesn't matter */
gsargv[1] = "-dNOPAUSE";
gsargv[2] = "-dBATCH";
gsargv[3] = "-dSAFER";
gsargv[4] = "-sDEVICE=pdfwrite";
gsargv[5] = "-sOutputFile=out.pdf";
gsargv[6] = "-c";
gsargv[7] = ".setpdfwrite";
gsargv[8] = "-f";
gsargv[9] = @"Files\input.ps";
SetDllDirectory(GhostscriptDllDirectory);
code = API.CreateAPIInstance(out minst, IntPtr.Zero);
if (code < 0)
{
System.Environment.Exit(1);
}
code = API.InitAPI(minst, gsargv.Length, gsargv);
code1 = API.ExitAPI(minst);
if ((code == 0) || (code == (int)API.GhostscriptErrorCode.e_Quit))
{
code = code1;
}
API.DeleteAPIInstance(minst);
if ((code == 0) || (code == (int)API.GhostscriptErrorCode.e_Quit))
{
System.Environment.Exit(0);
}
System.Environment.Exit(1);
}
}
}