diff --git a/.vscode/tasks.json b/.vscode/tasks.json
deleted file mode 100644
index 2568383..0000000
--- a/.vscode/tasks.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- // See https://go.microsoft.com/fwlink/?LinkId=733558
- // for the documentation about the tasks.json format
- "version": "0.1.0",
- "command": "dotnet",
- "isShellCommand": true,
- "args": [],
- "tasks": [
- {
- "taskName": "build",
- "args": [ ],
- "isBuildCommand": true,
- "showOutput": "silent",
- "problemMatcher": "$msCompile"
- }
- ]
-}
\ No newline at end of file
diff --git a/nuget/XpdfNet.targets b/nuget/XpdfNet.targets
index 99f08d8..94bbf63 100644
--- a/nuget/XpdfNet.targets
+++ b/nuget/XpdfNet.targets
@@ -20,5 +20,17 @@
pdftotext
Always
+
+ pdftops.exe
+ Always
+
+
+ pdftops
+ Always
+
+
+ pdftops
+ Always
+
-
\ No newline at end of file
+
diff --git a/src/XpdfNet.Tests/Expected.ps b/src/XpdfNet.Tests/Expected.ps
new file mode 100644
index 0000000..679723a
Binary files /dev/null and b/src/XpdfNet.Tests/Expected.ps differ
diff --git a/src/XpdfNet.Tests/ExpectedArg.ps b/src/XpdfNet.Tests/ExpectedArg.ps
new file mode 100644
index 0000000..b47ca5a
Binary files /dev/null and b/src/XpdfNet.Tests/ExpectedArg.ps differ
diff --git a/src/XpdfNet.Tests/ExpectedArg.txt b/src/XpdfNet.Tests/ExpectedArg.txt
new file mode 100644
index 0000000..87fddf3
--- /dev/null
+++ b/src/XpdfNet.Tests/ExpectedArg.txt
@@ -0,0 +1,10 @@
+Adobe Acrobat PDF Files
+Adobe® Portable Document Format (PDF) is a universal file format that preserves all of the fonts, formatting, colours and graphics of any source document, regardless of the application and platform used to create it.
+Adobe PDF is an ideal format for electronic document distribution as it overcomes the problems commonly encountered with electronic file sharing.
+• Anyone, anywhere can open a PDF file. All you need is the free Adobe Acrobat Reader. Recipients of other file formats sometimes can't open files because they don't have the applications used to create the documents.
+• PDF files always print correctly on any printing device.
+• PDF files always display exactly as created, regardless of fonts, software, and operating systems. Fonts, and graphics are not lost due to platform, software, and version incompatibilities.
+• The free Acrobat Reader is easy to download and can be freely distributed by anyone.
+• Compact PDF files are smaller than their source files and download a page at a time for fast display on the Web.
+
+
\ No newline at end of file
diff --git a/src/XpdfNet.Tests/Service/DirectoryService/DirectoryServiceLinuxTest.cs b/src/XpdfNet.Tests/Service/DirectoryService/DirectoryServiceLinuxTest.cs
index 5e2cd84..773924d 100644
--- a/src/XpdfNet.Tests/Service/DirectoryService/DirectoryServiceLinuxTest.cs
+++ b/src/XpdfNet.Tests/Service/DirectoryService/DirectoryServiceLinuxTest.cs
@@ -24,10 +24,14 @@ public void GetPDFToTextExeFilename_ShouldReturnPdftotext_WhenItIsLinux()
// Act
string actual = this.directoryService.Filename;
+ string actual2 = this.directoryService.PDFToPSFilename;
+ string actual3 = this.directoryService.PDFToTextFilename;
// Assert
string expected = "/bin/bash";
Assert.Equal(expected, actual);
+ Assert.Equal(expected, actual2);
+ Assert.Equal(expected, actual3);
}
[Fact]
@@ -42,10 +46,32 @@ public void GetArguments_ShouldReturnPdftotextAndArguments()
};
// Act
- string actual = this.directoryService.GetArguments(parameter);
+ string actual = this.directoryService.GetArgumentsToText(parameter);
+ string actual2 = this.directoryService.GetArguments(parameter);
// Assert
string expected = "-c \"chmod +x ./pdftotext; ./pdftotext -enc UTF-8 \"1.pdf\" \"1.txt\"\"";
+
+ Assert.Equal(expected, actual);
+ Assert.Equal(expected, actual2);
+ }
+
+ [Fact]
+ public void GetArguments_ShouldReturnPdftopsAndArguments()
+ {
+ // Arrange
+ XpdfParameter parameter = new XpdfParameter
+ {
+ PDFLevel = "-level3",
+ PdfFilename = "1.pdf",
+ OutputFilename = "1.txt"
+ };
+
+ // Act
+ string actual = this.directoryService.GetArgumentsToPS(parameter);
+
+ // Assert
+ string expected = "-c \"chmod +x ./pdftops; ./pdftops -level3 \"1.pdf\" \"1.txt\"\"";
Assert.Equal(expected, actual);
}
}
diff --git a/src/XpdfNet.Tests/Service/DirectoryService/DirectoryServiceWindowsTest.cs b/src/XpdfNet.Tests/Service/DirectoryService/DirectoryServiceWindowsTest.cs
index 60975c4..4baa1d7 100644
--- a/src/XpdfNet.Tests/Service/DirectoryService/DirectoryServiceWindowsTest.cs
+++ b/src/XpdfNet.Tests/Service/DirectoryService/DirectoryServiceWindowsTest.cs
@@ -21,10 +21,48 @@ public void GetPDFToTextExeFilename_ShouldReturnPdftotextExe_WhenItIsWindows()
// Act
string actual = this.directoryService.Filename;
+ string actual2 = this.directoryService.PDFToTextFilename;
// Assert
string expected = Path.Combine(this.directoryService.WorkingDirectory, "pdftotext.exe");
+ Assert.Equal(expected, actual);
+ Assert.Equal(expected, actual2);
+ }
+
+ [Fact]
+ public void GetPDFToTextExeFilename_ShouldReturnPdftoPsExe_WhenItIsWindows()
+ {
+ // Arrange
+
+ // Act
+ string actual = this.directoryService.PDFToPSFilename;
+
+ // Assert
+ string expected = Path.Combine(this.directoryService.WorkingDirectory, "pdftops.exe");
+ Assert.Equal(expected, actual);
+ }
+
+ [Fact]
+ public void GetArguments_ShouldReturnString()
+ {
+ // Arrange
+ XpdfParameter par = new XpdfParameter()
+ {
+ OutputFilename = "b.ps",
+ PdfFilename = "b.pdf",
+ PDFLevel = "-level3"
+ };
+
+ // Act
+ string actual = this.directoryService.GetArguments(par);
+ string actual2 = this.directoryService.GetArgumentsToText(par);
+ string actual3 = this.directoryService.GetArgumentsToPS(par);
+
+ // Assert
+ string expected = "-level3 \"b.pdf\" \"b.ps\"";
Assert.Equal(expected, actual);
+ Assert.Equal(expected, actual2);
+ Assert.Equal(expected, actual3);
}
}
}
diff --git a/src/XpdfNet.Tests/Service/ProcessServiceTest.cs b/src/XpdfNet.Tests/Service/ProcessServiceTest.cs
index 5a40f10..3b7223f 100644
--- a/src/XpdfNet.Tests/Service/ProcessServiceTest.cs
+++ b/src/XpdfNet.Tests/Service/ProcessServiceTest.cs
@@ -24,6 +24,6 @@ public void ToText_ShouldThrowExceptionWithPathInformation_WhenPDFToTextExeCanNo
// Assert
string expected = $"Filename: {filename}; Arguments: {arguments}; WorkingDirectory: {workingDirectory};";
Assert.Contains(expected, ex.Message);
- }
+ }
}
}
diff --git a/src/XpdfNet.Tests/XpdfHelperTest.cs b/src/XpdfNet.Tests/XpdfHelperTest.cs
index 2559eec..a577966 100644
--- a/src/XpdfNet.Tests/XpdfHelperTest.cs
+++ b/src/XpdfNet.Tests/XpdfHelperTest.cs
@@ -1,49 +1,94 @@
-namespace XpdfNet.Tests
-{
- using System;
- using System.Globalization;
- using System.IO;
- using System.Text.RegularExpressions;
- using Xunit;
-
- public class XpdfHelperTest
- {
- private readonly XpdfHelper xpdfHelper;
-
- public XpdfHelperTest()
- {
- this.xpdfHelper = new XpdfHelper();
- }
-
- [Fact]
- public void ToText_ShouldReturnText()
- {
- // Arrange
-
- // Act
- string actual = this.xpdfHelper.ToText("sample1.pdf");
- actual = RemoveWhiteSpace(actual);
-
- // Assert
- string workingDirectory;
-
-#if NETCOREAPP1_1
- workingDirectory = AppContext.BaseDirectory;
-#else
- workingDirectory = AppDomain.CurrentDomain.BaseDirectory;
-#endif
-
- string expected = File.ReadAllText(Path.Combine(workingDirectory, "Expected.txt"));
- expected = RemoveWhiteSpace(expected);
-
- Assert.Equal(expected, actual);
- }
-
- private static string RemoveWhiteSpace(string input)
- {
- var result = Regex.Replace(input, @"\s+", string.Empty);
-
- return result;
- }
- }
-}
+namespace XpdfNet.Tests
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Globalization;
+ using System.IO;
+ using System.Text.RegularExpressions;
+ using Xunit;
+
+ public class XpdfHelperTest
+ {
+ private readonly XpdfHelper xpdfHelper;
+ private XpdfHelper xpdfHelper2;
+
+ public XpdfHelperTest()
+ {
+ this.xpdfHelper = new XpdfHelper();
+ List eArg = new List();
+ eArg.Add("-paperw 80");
+ this.xpdfHelper2 = new XpdfHelper(eArg);
+ }
+
+ [Fact]
+ public void XpdfHelperTest_withExtraArguments()
+ {
+ Assert.True(this.xpdfHelper2 != null);
+ }
+
+ [Fact]
+ public void ToText_ShouldReturnText()
+ {
+ // Arrange
+ List eArg = new List();
+ eArg.Add("-paperw 80");
+ this.xpdfHelper2 = new XpdfHelper(eArg);
+
+ // Act
+ string actual = this.xpdfHelper.ToText("sample1.pdf");
+ string actualExtraArgs = this.xpdfHelper2.ToText("sample1.pdf");
+ actual = RemoveWhiteSpace(actual);
+ actualExtraArgs = RemoveWhiteSpace(actualExtraArgs);
+
+ // Assert
+ string workingDirectory;
+
+#if NETCOREAPP1_1
+ workingDirectory = AppContext.BaseDirectory;
+#else
+ workingDirectory = AppDomain.CurrentDomain.BaseDirectory;
+#endif
+
+ string expected = File.ReadAllText(Path.Combine(workingDirectory, "Expected.txt"));
+ string expectedargs = File.ReadAllText(Path.Combine(workingDirectory, "ExpectedArg.txt"));
+ expected = RemoveWhiteSpace(expected);
+
+ Assert.Equal(expected, actual);
+ Assert.Equal(expected, actualExtraArgs);
+ }
+
+ [Fact]
+ public void ToPS_ShouldReturnText()
+ {
+ // Arrange
+ // Act
+ string actual = this.xpdfHelper.ToPS("sample1.pdf");
+ string actualExtraArgs = this.xpdfHelper2.ToPS("sample1.pdf");
+ actual = RemoveWhiteSpace(actual);
+ actualExtraArgs = RemoveWhiteSpace(actualExtraArgs);
+
+ // Assert
+ string workingDirectory;
+
+#if NETCOREAPP1_1
+ workingDirectory = AppContext.BaseDirectory;
+#else
+ workingDirectory = AppDomain.CurrentDomain.BaseDirectory;
+#endif
+
+ string expected_ps = File.ReadAllText(Path.Combine(workingDirectory, "Expected.ps"));
+ string expected_ps_args = File.ReadAllText(Path.Combine(workingDirectory, "ExpectedArg.ps"));
+ expected_ps = RemoveWhiteSpace(expected_ps);
+ expected_ps_args = RemoveWhiteSpace(expected_ps_args);
+ Assert.Equal(expected_ps, actual);
+ Assert.Equal(expected_ps_args, actualExtraArgs);
+ }
+
+ private static string RemoveWhiteSpace(string input)
+ {
+ var result = Regex.Replace(input, @"\s+", string.Empty);
+
+ return result;
+ }
+ }
+}
diff --git a/src/XpdfNet.Tests/XpdfNet.Tests.csproj b/src/XpdfNet.Tests/XpdfNet.Tests.csproj
index f068ceb..a840a74 100644
--- a/src/XpdfNet.Tests/XpdfNet.Tests.csproj
+++ b/src/XpdfNet.Tests/XpdfNet.Tests.csproj
@@ -28,6 +28,15 @@
+
+ Always
+
+
+ Always
+
+
+ Always
+
Always
diff --git a/src/XpdfNet/Model/XpdfParameter.cs b/src/XpdfNet/Model/XpdfParameter.cs
index 1ec9806..e78b94d 100644
--- a/src/XpdfNet/Model/XpdfParameter.cs
+++ b/src/XpdfNet/Model/XpdfParameter.cs
@@ -1,5 +1,7 @@
namespace XpdfNet
-{
+{
+ using System.Collections.Generic;
+
public class XpdfParameter
{
public string OutputFilename { get; set; }
@@ -7,5 +9,9 @@ public class XpdfParameter
public string Encoding { get; set; }
public string PdfFilename { get; set; }
+
+ public string PDFLevel { get; set; }
+
+ public List ExtraArguments { get; set; }
}
}
diff --git a/src/XpdfNet/Service/DirectoryService/DirectoryServiceBase.cs b/src/XpdfNet/Service/DirectoryService/DirectoryServiceBase.cs
index fc5c597..af0fa0e 100644
--- a/src/XpdfNet/Service/DirectoryService/DirectoryServiceBase.cs
+++ b/src/XpdfNet/Service/DirectoryService/DirectoryServiceBase.cs
@@ -1,62 +1,85 @@
-namespace XpdfNet
-{
- using System;
- using System.IO;
- using System.Runtime.InteropServices;
-
- public abstract class DirectoryServiceBase : IDirectoryService
- {
- public abstract string Filename { get; }
-
- public string WorkingDirectory
- {
- get
- {
- string workingDirectory;
-
-#if NET45
- workingDirectory = AppDomain.CurrentDomain.BaseDirectory;
-#else
- workingDirectory = AppContext.BaseDirectory;
-#endif
-
- return workingDirectory;
- }
- }
-
- public XpdfParameter GetParameter(string pdfFilePath)
- {
- return new XpdfParameter
- {
- Encoding = "-enc UTF-8",
- PdfFilename = pdfFilePath,
- OutputFilename = Path.Combine(this.WorkingDirectory, Guid.NewGuid() + ".txt")
- };
- }
-
- public abstract string GetArguments(XpdfParameter parameter);
-
- protected static string WrapWith(string text, string ends)
- {
- return ends + text + ends;
- }
-
- protected static string WrapQuotes(string text)
- {
- return WrapWith(text, "\"");
- }
-
- protected string JoinXpdfParameters(XpdfParameter parameter)
- {
- string[] argumentsArray =
- {
- parameter.Encoding,
- WrapQuotes(parameter.PdfFilename),
- WrapQuotes(parameter.OutputFilename),
- };
-
- string arguments = string.Join(" ", argumentsArray);
- return arguments;
- }
- }
-}
+namespace XpdfNet
+{
+ using System;
+ using System.IO;
+ using System.Linq;
+ using System.Runtime.InteropServices;
+
+ public abstract class DirectoryServiceBase : IDirectoryService
+ {
+ public abstract string Filename { get; }
+
+ public abstract string PDFToPSFilename { get; }
+
+ public abstract string PDFToTextFilename { get; }
+
+ public string WorkingDirectory
+ {
+ get
+ {
+ string workingDirectory;
+
+#if NET45
+ workingDirectory = AppDomain.CurrentDomain.BaseDirectory;
+#else
+ workingDirectory = AppContext.BaseDirectory;
+#endif
+
+ return workingDirectory;
+ }
+ }
+
+ public XpdfParameter GetParameter(string pdfFilePath)
+ {
+ return new XpdfParameter
+ {
+ Encoding = "-enc UTF-8",
+ PdfFilename = pdfFilePath,
+ OutputFilename = Path.Combine(this.WorkingDirectory, Guid.NewGuid() + ".txt")
+ };
+ }
+
+ public XpdfParameter GetParameterToPs(string pdfFilePath)
+ {
+ return new XpdfParameter
+ {
+ PDFLevel = "-level3",
+ PdfFilename = pdfFilePath,
+ OutputFilename = Path.Combine(this.WorkingDirectory, Guid.NewGuid() + ".ps")
+ };
+ }
+
+ [Obsolete("GetArguments is deprecated, please use GetArgumentsToText instead.")]
+ public abstract string GetArguments(XpdfParameter parameter);
+
+ public abstract string GetArgumentsToText(XpdfParameter parameter);
+
+ public abstract string GetArgumentsToPS(XpdfParameter parameter);
+
+ protected static string WrapWith(string text, string ends)
+ {
+ return ends + text + ends;
+ }
+
+ protected static string WrapQuotes(string text)
+ {
+ return WrapWith(text, "\"");
+ }
+
+ protected string JoinXpdfParameters(XpdfParameter parameter)
+ {
+ string extra = parameter.ExtraArguments != null ? string.Join(" ", parameter.ExtraArguments) : null;
+ string[] argumentsArray =
+ {
+ extra,
+ parameter.Encoding,
+ parameter.PDFLevel,
+ WrapQuotes(parameter.PdfFilename),
+ WrapQuotes(parameter.OutputFilename),
+ };
+ argumentsArray = argumentsArray.Where(c => c != null).ToArray();
+ string arguments = string.Join(" ", argumentsArray);
+ return arguments;
+ }
+ }
+}
diff --git a/src/XpdfNet/Service/DirectoryService/DirectoryServiceFactory.cs b/src/XpdfNet/Service/DirectoryService/DirectoryServiceFactory.cs
index 049ea01..2c39825 100644
--- a/src/XpdfNet/Service/DirectoryService/DirectoryServiceFactory.cs
+++ b/src/XpdfNet/Service/DirectoryService/DirectoryServiceFactory.cs
@@ -5,9 +5,9 @@
using System.Text;
public static class DirectoryServiceFactory
- {
+ {
public static IDirectoryService GetDirectoryService(IRuntimeInformation runtimeInformation)
- {
+ {
IDirectoryService result = null;
switch (runtimeInformation.GetOSPlatform())
diff --git a/src/XpdfNet/Service/DirectoryService/DirectoryServiceLinux.cs b/src/XpdfNet/Service/DirectoryService/DirectoryServiceLinux.cs
index 99b3e8a..b5916f3 100644
--- a/src/XpdfNet/Service/DirectoryService/DirectoryServiceLinux.cs
+++ b/src/XpdfNet/Service/DirectoryService/DirectoryServiceLinux.cs
@@ -5,6 +5,6 @@
using System.Text;
public class DirectoryServiceLinux : DirectoryServiceUnix
- {
+ {
}
}
diff --git a/src/XpdfNet/Service/DirectoryService/DirectoryServiceUnix.cs b/src/XpdfNet/Service/DirectoryService/DirectoryServiceUnix.cs
index 13bf9bf..78cf551 100644
--- a/src/XpdfNet/Service/DirectoryService/DirectoryServiceUnix.cs
+++ b/src/XpdfNet/Service/DirectoryService/DirectoryServiceUnix.cs
@@ -1,23 +1,59 @@
-namespace XpdfNet
-{
- using System;
- using System.Collections.Generic;
- using System.Text;
-
- public class DirectoryServiceUnix : DirectoryServiceBase
- {
- private const string PDFToText = "pdftotext";
- private const string Bash = "/bin/bash";
-
- public override string Filename => Bash;
-
- public override string GetArguments(XpdfParameter parameter)
- {
- string arguments = this.JoinXpdfParameters(parameter);
-
- string newArguments = $"-c \"chmod +x ./{PDFToText}; ./{PDFToText} {arguments}\"";
-
- return newArguments;
- }
- }
-}
+namespace XpdfNet
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Text;
+
+ public class DirectoryServiceUnix : DirectoryServiceBase
+ {
+ private const string PDFToText = "pdftotext";
+ private const string PDFToPS = "pdftops";
+ private const string Bash = "/bin/bash";
+
+ public DirectoryServiceUnix()
+ {
+ if (!File.Exists(PDFToText))
+ {
+ // throw new FileNotFoundException(PDFToText);
+ Console.WriteLine("Cannot find PDFToText executable.");
+ }
+
+ if (!File.Exists(PDFToPS))
+ {
+ // throw new FileNotFoundException(PDFToPS);
+ Console.WriteLine("Cannot find PDFToPS executable.");
+ }
+ }
+
+ public override string Filename => Bash;
+
+ public override string PDFToPSFilename => Bash;
+
+ public override string PDFToTextFilename => Bash;
+
+ [Obsolete("GetArguments is deprecated, please use GetArgumentsToText instead.")]
+ public override string GetArguments(XpdfParameter parameter)
+ {
+ return this.GetArgumentsToText(parameter);
+ }
+
+ public override string GetArgumentsToText(XpdfParameter parameter)
+ {
+ string arguments = this.JoinXpdfParameters(parameter);
+
+ string newArguments = $"-c \"chmod +x ./{PDFToText}; ./{PDFToText} {arguments}\"";
+
+ return newArguments;
+ }
+
+ public override string GetArgumentsToPS(XpdfParameter parameter)
+ {
+ string arguments = this.JoinXpdfParameters(parameter);
+
+ string newArguments = $"-c \"chmod +x ./{PDFToPS}; ./{PDFToPS} {arguments}\"";
+
+ return newArguments;
+ }
+ }
+}
diff --git a/src/XpdfNet/Service/DirectoryService/DirectoryServiceWindows.cs b/src/XpdfNet/Service/DirectoryService/DirectoryServiceWindows.cs
index dcad371..acc8f0f 100644
--- a/src/XpdfNet/Service/DirectoryService/DirectoryServiceWindows.cs
+++ b/src/XpdfNet/Service/DirectoryService/DirectoryServiceWindows.cs
@@ -1,28 +1,60 @@
-namespace XpdfNet
-{
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
-
- public class DirectoryServiceWindows : DirectoryServiceBase
- {
- private const string PDFToText = "pdftotext.exe";
-
- public override string Filename
- {
- get
- {
- string filename = Path.Combine(this.WorkingDirectory, PDFToText);
- return filename;
- }
- }
-
- public override string GetArguments(XpdfParameter parameter)
- {
- var arguments = this.JoinXpdfParameters(parameter);
-
- return arguments;
- }
- }
-}
+namespace XpdfNet
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Text;
+
+ public class DirectoryServiceWindows : DirectoryServiceBase
+ {
+ private const string PDFToText = "pdftotext.exe";
+ private const string PDFToPS = "pdftops.exe";
+
+ public override string PDFToPSFilename
+ {
+ get
+ {
+ return Path.Combine(this.WorkingDirectory, PDFToPS);
+ }
+ }
+
+ public override string PDFToTextFilename
+ {
+ get
+ {
+ return Path.Combine(this.WorkingDirectory, PDFToText);
+ }
+ }
+
+ public override string Filename
+ {
+ get
+ {
+ return this.PDFToTextFilename;
+ }
+ }
+
+ [Obsolete("GetArguments is deprecated, please use GetArgumentsToText instead.")]
+ public override string GetArguments(XpdfParameter parameter)
+ {
+ return this.JoinArgumentsInString(parameter);
+ }
+
+ public override string GetArgumentsToText(XpdfParameter parameter)
+ {
+ return this.JoinArgumentsInString(parameter);
+ }
+
+ public override string GetArgumentsToPS(XpdfParameter parameter)
+ {
+ return this.JoinArgumentsInString(parameter);
+ }
+
+ private string JoinArgumentsInString(XpdfParameter parameter)
+ {
+ var arguments = this.JoinXpdfParameters(parameter);
+
+ return arguments.Replace(" ", " ").TrimStart(' ');
+ }
+ }
+}
diff --git a/src/XpdfNet/Service/DirectoryService/IDirectoryService.cs b/src/XpdfNet/Service/DirectoryService/IDirectoryService.cs
index bd0cf57..875fbdc 100644
--- a/src/XpdfNet/Service/DirectoryService/IDirectoryService.cs
+++ b/src/XpdfNet/Service/DirectoryService/IDirectoryService.cs
@@ -4,10 +4,20 @@ public interface IDirectoryService
{
string WorkingDirectory { get; }
- string Filename { get; }
+ string Filename { get; }
+
+ string PDFToPSFilename { get; }
+
+ string PDFToTextFilename { get; }
+
+ XpdfParameter GetParameter(string pdfFilePath);
+
+ XpdfParameter GetParameterToPs(string pdfFilePath);
- XpdfParameter GetParameter(string pdfFilePath);
+ string GetArguments(XpdfParameter parameter);
+
+ string GetArgumentsToText(XpdfParameter parameter);
- string GetArguments(XpdfParameter parameter);
+ string GetArgumentsToPS(XpdfParameter parameter);
}
}
\ No newline at end of file
diff --git a/src/XpdfNet/XpdfHelper.cs b/src/XpdfNet/XpdfHelper.cs
index 020a2f7..b5eef61 100644
--- a/src/XpdfNet/XpdfHelper.cs
+++ b/src/XpdfNet/XpdfHelper.cs
@@ -1,50 +1,83 @@
-namespace XpdfNet
-{
- using System;
- using System.IO;
-
- public class XpdfHelper
- {
- private readonly IDirectoryService directoryService;
- private string filename;
- private XpdfParameter parameter;
- private string workingDirectory;
- private string arguments;
-
- public XpdfHelper()
- {
- IRuntimeInformation runtimeInformation = new MyRuntimeInformation();
- this.directoryService = DirectoryServiceFactory.GetDirectoryService(runtimeInformation);
- }
-
- public string ToText(string pdfFilePath)
- {
- this.PrepareParameters(pdfFilePath);
-
- ProcessService processService = new ProcessService(this.filename, this.arguments, this.workingDirectory);
- processService.StartAndWaitForExit();
-
- var textResult = GetTextResult(this.parameter);
-
- return textResult;
- }
-
- private static string GetTextResult(XpdfParameter parameter)
- {
- string textResult = File.ReadAllText(parameter.OutputFilename);
- File.Delete(parameter.OutputFilename);
-
- return textResult;
- }
-
- private void PrepareParameters(string pdfFilePath)
- {
- this.filename = this.directoryService.Filename;
- this.workingDirectory = this.directoryService.WorkingDirectory;
-
- this.parameter = this.directoryService.GetParameter(pdfFilePath);
-
- this.arguments = this.directoryService.GetArguments(this.parameter);
- }
- }
-}
+namespace XpdfNet
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+
+ public class XpdfHelper
+ {
+ private readonly IDirectoryService directoryService;
+ private string filename;
+ private XpdfParameter parameter;
+ private string workingDirectory;
+ private string arguments;
+ private List extraArguments = new List();
+
+ public XpdfHelper()
+ {
+ IRuntimeInformation runtimeInformation = new MyRuntimeInformation();
+ this.directoryService = DirectoryServiceFactory.GetDirectoryService(runtimeInformation);
+ }
+
+ public XpdfHelper(List extraarguments)
+ {
+ this.extraArguments = extraarguments;
+ IRuntimeInformation runtimeInformation = new MyRuntimeInformation();
+ this.directoryService = DirectoryServiceFactory.GetDirectoryService(runtimeInformation);
+ }
+
+ public string ToPS(string pdfFilePath)
+ {
+ this.PrepareParametersToPS(pdfFilePath);
+
+ ProcessService processService = new ProcessService(this.filename, this.arguments, this.workingDirectory);
+ processService.StartAndWaitForExit();
+
+ var textResult = GetTextResult(this.parameter);
+
+ return textResult;
+ }
+
+ public string ToText(string pdfFilePath)
+ {
+ this.PrepareParametersToText(pdfFilePath);
+
+ ProcessService processService = new ProcessService(this.filename, this.arguments, this.workingDirectory);
+ processService.StartAndWaitForExit();
+
+ var textResult = GetTextResult(this.parameter);
+
+ return textResult;
+ }
+
+ private static string GetTextResult(XpdfParameter parameter)
+ {
+ string textResult = File.ReadAllText(parameter.OutputFilename);
+
+ File.Delete(parameter.OutputFilename);
+
+ return textResult;
+ }
+
+ private void PrepareParametersToPS(string pdfFilePath)
+ {
+ this.filename = this.directoryService.PDFToPSFilename;
+
+ this.workingDirectory = this.directoryService.WorkingDirectory;
+
+ this.parameter = this.directoryService.GetParameterToPs(pdfFilePath);
+ this.parameter.ExtraArguments = this.extraArguments;
+ this.arguments = this.directoryService.GetArgumentsToPS(this.parameter);
+ }
+
+ private void PrepareParametersToText(string pdfFilePath)
+ {
+ this.filename = this.directoryService.Filename;
+ this.workingDirectory = this.directoryService.WorkingDirectory;
+
+ this.parameter = this.directoryService.GetParameter(pdfFilePath);
+
+ this.arguments = this.directoryService.GetArgumentsToText(this.parameter);
+ }
+ }
+}
diff --git a/src/XpdfNet/XpdfNet.csproj b/src/XpdfNet/XpdfNet.csproj
index 4ef66db..8233f73 100644
--- a/src/XpdfNet/XpdfNet.csproj
+++ b/src/XpdfNet/XpdfNet.csproj
@@ -45,8 +45,21 @@
Always
pdftotext
+
+
+ Always
+ pdftops.exe
+
+
+ Always
+ pdftops
+
+
+ Always
+ pdftops
+
-
\ No newline at end of file
+
diff --git a/src/XpdfNet/lib/OSX/pdftops b/src/XpdfNet/lib/OSX/pdftops
new file mode 100644
index 0000000..5377aba
Binary files /dev/null and b/src/XpdfNet/lib/OSX/pdftops differ
diff --git a/src/XpdfNet/lib/Unix/pdftops b/src/XpdfNet/lib/Unix/pdftops
new file mode 100644
index 0000000..3001cf7
Binary files /dev/null and b/src/XpdfNet/lib/Unix/pdftops differ
diff --git a/src/XpdfNet/lib/Windows_NT/pdftops.exe b/src/XpdfNet/lib/Windows_NT/pdftops.exe
new file mode 100644
index 0000000..c75f78e
Binary files /dev/null and b/src/XpdfNet/lib/Windows_NT/pdftops.exe differ