Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .vscode/tasks.json

This file was deleted.

14 changes: 13 additions & 1 deletion nuget/XpdfNet.targets
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,17 @@
<Link>pdftotext</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Windows_NT/pdftops.exe" Condition="$(IsWindows) == 'true'">
<Link>pdftops.exe</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Unix/pdftops" Condition="$(IsLinux) == 'true'">
<Link>pdftops</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)OSX/pdftops" Condition="$(IsOSX) == 'true'">
<Link>pdftops</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
</Project>
Binary file added src/XpdfNet.Tests/Expected.ps
Binary file not shown.
Binary file added src/XpdfNet.Tests/ExpectedArg.ps
Binary file not shown.
10 changes: 10 additions & 0 deletions src/XpdfNet.Tests/ExpectedArg.txt
Original file line number Diff line number Diff line change
@@ -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.


Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/XpdfNet.Tests/Service/ProcessServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public void ToText_ShouldThrowExceptionWithPathInformation_WhenPDFToTextExeCanNo
// Assert
string expected = $"Filename: {filename}; Arguments: {arguments}; WorkingDirectory: {workingDirectory};";
Assert.Contains(expected, ex.Message);
}
}
}
}
143 changes: 94 additions & 49 deletions src/XpdfNet.Tests/XpdfHelperTest.cs
Original file line number Diff line number Diff line change
@@ -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<string> eArg = new List<string>();
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<string> eArg = new List<string>();
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;
}
}
}
9 changes: 9 additions & 0 deletions src/XpdfNet.Tests/XpdfNet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
<ProjectReference Include="..\XpdfNet\XpdfNet.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="ExpectedArg.ps">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ExpectedArg.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Expected.ps">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Expected.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
8 changes: 7 additions & 1 deletion src/XpdfNet/Model/XpdfParameter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
namespace XpdfNet
{
{
using System.Collections.Generic;

public class XpdfParameter
{
public string OutputFilename { get; set; }

public string Encoding { get; set; }

public string PdfFilename { get; set; }

public string PDFLevel { get; set; }

public List<string> ExtraArguments { get; set; }
}
}
Loading