Skip to content
This repository was archived by the owner on Sep 20, 2022. It is now read-only.

Commit 6afdb67

Browse files
committed
Upgraded embedded ghostscript version to 9.50
1 parent 404575e commit 6afdb67

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

PostScriptValidator.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C488C313-51AE-4614-8F69-BC6853E81991}"
1111
ProjectSection(SolutionItems) = preProject
1212
appveyor.yml = appveyor.yml
13+
README.md = README.md
1314
EndProjectSection
1415
EndProject
1516
Global

PostScriptValidator/PostScriptValidator.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,45 @@ namespace PostScriptValidator
1414
public class PostScriptValidator : IDisposable
1515
{
1616
private string pathGhostscriptDirectory;
17+
1718
/// <summary>
18-
/// Used Path to ghostscript bin
19+
/// Used Path to ghostscript bin
1920
/// </summary>
2021
/// <value>Path to ghostscript bin</value>
2122
public string GhostscriptBinPath { get; private set; }
23+
2224
/// <summary>
2325
/// Last exitcode from ghostscript
2426
/// </summary>
2527
/// <value>Is 0 if ghostscript could parse the validated postscript file</value>
2628
public int ExitCode { get; private set; }
29+
2730
/// <summary>
2831
/// Last stderr output from ghostscript
2932
/// </summary>
3033
/// <value>Can give you some hints if ghostscript failes to parse the validated postscript file</value>
3134

3235
public string ErrorMessage { get; private set; }
36+
3337
/// <summary>
3438
/// Last stdout output from ghostscript
3539
/// </summary>
3640
/// <value>Contains the stdout of the last validation session of ghostscript</value>
3741
public string StandardOutput { get; private set; }
42+
3843
private bool isInitilized;
3944
private bool customGhostscriptlocation;
4045
private bool disposed;
4146
private readonly object lockObject = new object();
4247
private const string c_maskedQuote = "\"";
48+
4349
/// <summary>
44-
/// Use this constructor to use the embedded ghostscript binaries on windows, or guess the location on linux
50+
/// Use this constructor to use the embedded ghostscript binaries on windows, or guess the location on linux
4551
/// </summary>
4652
public PostScriptValidator()
4753
{
4854
}
55+
4956
/// <summary>
5057
/// Use this constructor to use custom ghostscritp bins, e.g. for ubuntu 18.04 /usr/bin/gs
5158
/// </summary>
@@ -55,14 +62,15 @@ public PostScriptValidator(string customPathToGhostscriptBin)
5562
customGhostscriptlocation = false;
5663
isInitilized = true;
5764
}
65+
5866
/// <summary>
5967
/// Validates a ps by trying to parse it using ghostscript
6068
/// </summary>
6169
/// <param name="pathToPsFile"></param>
6270
/// <returns>True for parseable postscript files</returns>
6371
public bool Validate(string pathToPsFile)
6472
{
65-
string absolutePathToPsFile = getAbsoluteFilePath(pathToPsFile);
73+
var absolutePathToPsFile = getAbsoluteFilePath(pathToPsFile);
6674

6775
//https://stackoverflow.com/questions/258132/validating-a-postscript-without-trying-to-print-it#2981290
6876
var ghostScriptArguments = new[] { "-sDEVICE=nullpage -dNOPAUSE -dBATCH ", c_maskedQuote, absolutePathToPsFile, c_maskedQuote };
@@ -84,7 +92,7 @@ public bool Validate(string pathToPsFile)
8492
/// <param name="pathToPdfFileWithEmbeddedFonts"></param>
8593
public void EmbedFonts(string pathToPdfFile, string pathToPdfFileWithEmbeddedFonts)
8694
{
87-
string absolutePathToPdfFile = getAbsoluteFilePath(pathToPdfFile);
95+
var absolutePathToPdfFile = getAbsoluteFilePath(pathToPdfFile);
8896

8997
// https://stackoverflow.com/questions/258132/validating-a-postscript-without-trying-to-print-it#2981290
9098

@@ -153,14 +161,13 @@ private void IntiPathToGhostscriptBin()
153161
isInitilized = true;
154162
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
155163
{
156-
157164
lock (lockObject)
158165
{
159166
pathGhostscriptDirectory = Path.Combine(Path.GetTempPath(), "Ghostscript" + Guid.NewGuid());
160167
Directory.CreateDirectory(pathGhostscriptDirectory);
161168

162-
ExtractBinaryFromManifest("PostScriptValidator.gs9.27.zip");
163-
GhostscriptBinPath = Path.Combine(pathGhostscriptDirectory, @"gs9.27\bin", "gswin32c.exe");
169+
ExtractBinaryFromManifest("PostScriptValidator.gs9.50.zip");
170+
GhostscriptBinPath = Path.Combine(pathGhostscriptDirectory, @"gs9.50\bin", "gswin32c.exe");
164171

165172
isInitilized = true;
166173
}
@@ -175,6 +182,7 @@ private void IntiPathToGhostscriptBin()
175182
throw new NotImplementedException("Sorry, only supporting linux and windows.");
176183
}
177184
}
185+
178186
private static string GetStreamOutput(StreamReader stream)
179187
{
180188
//Read output i<n separate task to avoid deadlocks
@@ -185,7 +193,7 @@ private static string GetStreamOutput(StreamReader stream)
185193

186194
private void ExtractBinaryFromManifest(string resourceName)
187195
{
188-
var pathZipGhostscript = Path.Combine(pathGhostscriptDirectory, "gs9.27.zip");
196+
var pathZipGhostscript = Path.Combine(pathGhostscriptDirectory, "gs9.50.zip");
189197
var assembly = Assembly.GetExecutingAssembly();
190198

191199
using (var stream = assembly.GetManifestResourceStream(resourceName))
@@ -196,6 +204,7 @@ private void ExtractBinaryFromManifest(string resourceName)
196204
}
197205
ZipFile.ExtractToDirectory(pathZipGhostscript, pathGhostscriptDirectory);
198206
}
207+
199208
/// <summary>
200209
/// Disposing ghostscript bins
201210
/// </summary>

PostScriptValidator/PostScriptValidator.csproj

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
<EmbedUntrackedSources>true</EmbedUntrackedSources>
2525
<PackageIcon>NugetIcon.png</PackageIcon>
2626
</PropertyGroup>
27-
27+
2828
<ItemGroup>
29-
<None Remove="gs9.27.zip" />
29+
<None Remove="gs9.50.zip" />
3030
</ItemGroup>
3131

3232
<ItemGroup>
33-
<None Include="NugetIcon.png" Pack="true" PackagePath="\" />
33+
<EmbeddedResource Include="gs9.50.zip" />
3434
</ItemGroup>
3535

3636
<ItemGroup>
37-
<EmbeddedResource Include="gs9.27.zip" />
37+
<None Include="NugetIcon.png" Pack="true" PackagePath="\" />
3838
</ItemGroup>
3939

4040
<ItemGroup>
@@ -46,7 +46,11 @@
4646
</ItemGroup>
4747

4848
<ItemGroup>
49-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
49+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.6">
50+
<PrivateAssets>all</PrivateAssets>
51+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
52+
</PackageReference>
53+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
5054
</ItemGroup>
5155

5256
<ItemGroup>

PostScriptValidatorTest/PostScriptValidatorTest.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.6">
11+
<PrivateAssets>all</PrivateAssets>
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
</PackageReference>
1014
<PackageReference Include="nunit" Version="3.11.0" />
1115
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
1216
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ using (var postscriptValidator = new PostScriptValidator.PostScriptValidator())
2020
}
2121
```
2222

23-
# Dependencies
23+
## Dependencies
2424

2525
Windows:
26-
* none
26+
27+
* The nuget package brings every depency
2728

2829
Ubuntu:
2930
```bash
30-
suod apt install ghostscript
31+
sudo apt install ghostscript
3132
```

0 commit comments

Comments
 (0)