Skip to content

Commit 4bc8a79

Browse files
authored
Windows FTS (#130)
The PR will add a new native module for the windows react native PSPDFKit layer. LibraryModule exposes support for FTS in react native windows. You can open multiple libraries from either the picker or local folders in which the application has access to (use RNFS itinance/react-native-fs) Configuration of the search is passed in via a json object which is converted internally and pass up to PSPDFKit windows. The results are passed back in a promise, the results comprises of a json objet with information dependent on the configuration. Much like the native library.
1 parent 8ef2e11 commit 4bc8a79

File tree

14 files changed

+552
-33
lines changed

14 files changed

+552
-33
lines changed

samples/Catalog/Catalog.windows.js

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ import { StackNavigator } from "react-navigation";
2121
import PSPDFKitView from "react-native-pspdfkit";
2222

2323
var PSPDFKit = NativeModules.ReactPSPDFKit;
24+
var PSPDFKitLibrary = NativeModules.ReactPSPDFKitLibrary;
25+
var RNFS = require("react-native-fs");
26+
27+
const complexSearchConfiguration = {
28+
searchString: "the",
29+
excludeAnnotations: false,
30+
excludeDocumentText: false,
31+
matchExactPhrases: false,
32+
maximumSearchResultsPerDocument: 0,
33+
maximumSearchResultsTotal: 500,
34+
maximumPreviewResultsPerDocument: 0,
35+
maximumPreviewResultsTotal: 500,
36+
generateTextPreviews: true,
37+
previewRange: { position: 20, length: 120 }
38+
};
39+
40+
const simpleSearch = {
41+
searchString: "the"
42+
};
2443

2544
var examples = [
2645
{
@@ -35,9 +54,10 @@ var examples = [
3554
description: "Open document from source",
3655
action: component => {
3756
component.props.navigation.navigate("PdfView");
38-
// Present can only take files loaded in the Visual studio Project's Assets.
57+
// Present can only take files loaded in the Visual studio Project's Assets. Please use RNFS.
3958
// See https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions
40-
PSPDFKit.Present("ms-appx:///Assets/pdf/Business Report.pdf");
59+
var path = RNFS.MainBundlePath + "\\Assets\\pdf\\Business Report.pdf";
60+
PSPDFKit.Present(path);
4161
}
4262
},
4363
{
@@ -54,6 +74,44 @@ var examples = [
5474
action: component => {
5575
component.props.navigation.navigate("PdfViewInstantJsonScreen");
5676
}
77+
},
78+
{
79+
name: "Index Full Text Search From Picker",
80+
description: "A simple full text search over a folder of the users choice.",
81+
action: async component => {
82+
await PSPDFKitLibrary.OpenLibrary("MyLibrary");
83+
await PSPDFKitLibrary.EnqueueDocumentsInFolderPicker("MyLibrary");
84+
alert(
85+
'Searching Library for "' +
86+
simpleSearch.searchString +
87+
'". Please wait.'
88+
);
89+
PSPDFKitLibrary.SearchLibrary("MyLibrary", simpleSearch)
90+
.then(result => {
91+
alert("Search : \n" + JSON.stringify(result));
92+
})
93+
.finally(() => PSPDFKitLibrary.DeleteAllLibraries());
94+
}
95+
},
96+
{
97+
name: "Index Full Text Search From Assets",
98+
description: "A simple full text search over the assets folder.",
99+
action: async component => {
100+
var path = RNFS.MainBundlePath + "\\Assets\\pdf";
101+
102+
await PSPDFKitLibrary.OpenLibrary("AssetsLibrary");
103+
await PSPDFKitLibrary.EnqueueDocumentsInFolder("AssetsLibrary", path);
104+
alert(
105+
'Searching Library for "' +
106+
complexSearchConfiguration.searchString +
107+
'". Please wait.'
108+
);
109+
PSPDFKitLibrary.SearchLibrary("AssetsLibrary", complexSearchConfiguration)
110+
.then(result => {
111+
alert("Search : \n" + JSON.stringify(result));
112+
})
113+
.finally(() => PSPDFKitLibrary.DeleteAllLibraries());
114+
}
57115
}
58116
];
59117

samples/Catalog/windows/Catalog.sln

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1616
EndProject
1717
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactNativePSPDFKit", "..\node_modules\react-native-pspdfkit\windows\ReactNativePSPDFKit\ReactNativePSPDFKit\ReactNativePSPDFKit.csproj", "{475F630C-9EA0-4CD2-823A-0BB2DBB4778A}"
1818
EndProject
19+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RNFS", "..\node_modules\react-native-fs\windows\RNFS\RNFS.csproj", "{746610D0-8693-11E7-A20D-BF83F7366778}"
20+
EndProject
1921
Global
2022
GlobalSection(SharedMSBuildProjectFiles) = preSolution
2123
..\node_modules\react-native-windows\ReactWindows\ReactNative.Shared\ReactNative.Shared.projitems*{c7673ad5-e3aa-468c-a5fd-fa38154e205c}*SharedItemsImports = 4
@@ -250,6 +252,43 @@ Global
250252
{475F630C-9EA0-4CD2-823A-0BB2DBB4778A}.ReleaseBundle|x64.Build.0 = Release|x64
251253
{475F630C-9EA0-4CD2-823A-0BB2DBB4778A}.ReleaseBundle|x86.ActiveCfg = Release|x86
252254
{475F630C-9EA0-4CD2-823A-0BB2DBB4778A}.ReleaseBundle|x86.Build.0 = Release|x86
255+
{746610D0-8693-11E7-A20D-BF83F7366778}.Debug|Any CPU.ActiveCfg = Debug|x86
256+
{746610D0-8693-11E7-A20D-BF83F7366778}.Debug|ARM.ActiveCfg = Debug|ARM
257+
{746610D0-8693-11E7-A20D-BF83F7366778}.Debug|ARM.Build.0 = Debug|ARM
258+
{746610D0-8693-11E7-A20D-BF83F7366778}.Debug|x64.ActiveCfg = Debug|x64
259+
{746610D0-8693-11E7-A20D-BF83F7366778}.Debug|x64.Build.0 = Debug|x64
260+
{746610D0-8693-11E7-A20D-BF83F7366778}.Debug|x86.ActiveCfg = Debug|x86
261+
{746610D0-8693-11E7-A20D-BF83F7366778}.Debug|x86.Build.0 = Debug|x86
262+
{746610D0-8693-11E7-A20D-BF83F7366778}.DebugBundle|Any CPU.ActiveCfg = Release|x64
263+
{746610D0-8693-11E7-A20D-BF83F7366778}.DebugBundle|Any CPU.Build.0 = Release|x64
264+
{746610D0-8693-11E7-A20D-BF83F7366778}.DebugBundle|ARM.ActiveCfg = Debug|ARM
265+
{746610D0-8693-11E7-A20D-BF83F7366778}.DebugBundle|ARM.Build.0 = Debug|ARM
266+
{746610D0-8693-11E7-A20D-BF83F7366778}.DebugBundle|x64.ActiveCfg = Debug|x64
267+
{746610D0-8693-11E7-A20D-BF83F7366778}.DebugBundle|x64.Build.0 = Debug|x64
268+
{746610D0-8693-11E7-A20D-BF83F7366778}.DebugBundle|x86.ActiveCfg = Debug|x86
269+
{746610D0-8693-11E7-A20D-BF83F7366778}.DebugBundle|x86.Build.0 = Debug|x86
270+
{746610D0-8693-11E7-A20D-BF83F7366778}.Development|Any CPU.ActiveCfg = Development|x86
271+
{746610D0-8693-11E7-A20D-BF83F7366778}.Development|ARM.ActiveCfg = Development|ARM
272+
{746610D0-8693-11E7-A20D-BF83F7366778}.Development|ARM.Build.0 = Development|ARM
273+
{746610D0-8693-11E7-A20D-BF83F7366778}.Development|x64.ActiveCfg = Development|x64
274+
{746610D0-8693-11E7-A20D-BF83F7366778}.Development|x64.Build.0 = Development|x64
275+
{746610D0-8693-11E7-A20D-BF83F7366778}.Development|x86.ActiveCfg = Development|x86
276+
{746610D0-8693-11E7-A20D-BF83F7366778}.Development|x86.Build.0 = Development|x86
277+
{746610D0-8693-11E7-A20D-BF83F7366778}.Release|Any CPU.ActiveCfg = Release|x86
278+
{746610D0-8693-11E7-A20D-BF83F7366778}.Release|ARM.ActiveCfg = Release|ARM
279+
{746610D0-8693-11E7-A20D-BF83F7366778}.Release|ARM.Build.0 = Release|ARM
280+
{746610D0-8693-11E7-A20D-BF83F7366778}.Release|x64.ActiveCfg = Release|x64
281+
{746610D0-8693-11E7-A20D-BF83F7366778}.Release|x64.Build.0 = Release|x64
282+
{746610D0-8693-11E7-A20D-BF83F7366778}.Release|x86.ActiveCfg = Release|x86
283+
{746610D0-8693-11E7-A20D-BF83F7366778}.Release|x86.Build.0 = Release|x86
284+
{746610D0-8693-11E7-A20D-BF83F7366778}.ReleaseBundle|Any CPU.ActiveCfg = Release|x64
285+
{746610D0-8693-11E7-A20D-BF83F7366778}.ReleaseBundle|Any CPU.Build.0 = Release|x64
286+
{746610D0-8693-11E7-A20D-BF83F7366778}.ReleaseBundle|ARM.ActiveCfg = Release|ARM
287+
{746610D0-8693-11E7-A20D-BF83F7366778}.ReleaseBundle|ARM.Build.0 = Release|ARM
288+
{746610D0-8693-11E7-A20D-BF83F7366778}.ReleaseBundle|x64.ActiveCfg = Release|x64
289+
{746610D0-8693-11E7-A20D-BF83F7366778}.ReleaseBundle|x64.Build.0 = Release|x64
290+
{746610D0-8693-11E7-A20D-BF83F7366778}.ReleaseBundle|x86.ActiveCfg = Release|x86
291+
{746610D0-8693-11E7-A20D-BF83F7366778}.ReleaseBundle|x86.Build.0 = Release|x86
253292
EndGlobalSection
254293
GlobalSection(SolutionProperties) = preSolution
255294
HideSolutionNode = FALSE

samples/Catalog/windows/Catalog/Catalog.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@
209209
</ApplicationDefinition>
210210
</ItemGroup>
211211
<ItemGroup>
212+
<ProjectReference Include="..\..\node_modules\react-native-fs\windows\RNFS\RNFS.csproj">
213+
<Project>{746610D0-8693-11E7-A20D-BF83F7366778}</Project>
214+
<Name>RNFS</Name>
215+
</ProjectReference>
212216
<ProjectReference Include="..\..\node_modules\react-native-pspdfkit\windows\ReactNativePSPDFKit\ReactNativePSPDFKit\ReactNativePSPDFKit.csproj">
213217
<Project>{475f630c-9ea0-4cd2-823a-0bb2dbb4778a}</Project>
214218
<Name>ReactNativePSPDFKit</Name>
@@ -230,7 +234,7 @@
230234
<SDKReference Include="Microsoft.VCLibs, Version=14.0">
231235
<Name>Visual C++ 2015 Runtime for Universal Windows Platform Apps</Name>
232236
</SDKReference>
233-
<SDKReference Include="PSPDFKitSDK, Version=1.6.0">
237+
<SDKReference Include="PSPDFKitSDK, Version=1.6.1">
234238
<Name>PSPDFKit for UWP</Name>
235239
</SDKReference>
236240
</ItemGroup>
@@ -249,4 +253,4 @@
249253
<Target Name="AfterBuild">
250254
</Target>
251255
-->
252-
</Project>
256+
</Project>

samples/Catalog/windows/Catalog/MainReactNativeHost.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using ReactNative.Modules.Core;
33
using ReactNative.Shell;
44
using System.Collections.Generic;
5-
using Windows.UI.Core;
5+
using RNFS;
66

77
namespace Catalog
88
{
@@ -26,6 +26,7 @@ class MainReactNativeHost : ReactNativeHost
2626
{
2727
new MainReactPackage(),
2828
new ReactNativePSPDFKit.PSPDFKitPackage(),
29+
new RNFSPackage()
2930
};
3031
}
3132
}

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/Events/PdfViewAnnotationChangedEvent.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Newtonsoft.Json.Linq;
1+
using Newtonsoft.Json.Linq;
72
using PSPDFKit.Pdf.Annotation;
83
using ReactNative.UIManager.Events;
94

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/Events/PdfViewDataReturnedEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public PdfViewDataReturnedEvent(int viewId, int requestId, string errorMessage)
4646
_payload.Add("error", errorMessage);
4747
}
4848

49-
public override String EventName => EVENT_NAME;
49+
public override string EventName => EVENT_NAME;
5050

5151
public override void Dispatch(RCTEventEmitter eventEmitter)
5252
{

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/Events/PdfViewDocumentSaveFailedEvent.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Newtonsoft.Json.Linq;
1+
using Newtonsoft.Json.Linq;
72
using ReactNative.UIManager.Events;
83

94
namespace ReactNativePSPDFKit.Events

windows/ReactNativePSPDFKit/ReactNativePSPDFKit/Events/PdfViewDocumentSavedEvent.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Newtonsoft.Json.Linq;
7-
using ReactNative.UIManager.Events;
1+
using ReactNative.UIManager.Events;
82

93
namespace ReactNativePSPDFKit.Events
104
{
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json.Linq;
3+
using PSPDFKit.Search;
4+
using PSPDFKitFoundation;
5+
using PSPDFKitFoundation.Search;
6+
using PSPDFKitNative;
7+
8+
namespace ReactNativePSPDFKit
9+
{
10+
static class JsonUtils
11+
{
12+
public static LibraryQuery ToLibraryQuery(JObject libraryQueryJson)
13+
{
14+
var libraryQuery = new LibraryQuery(libraryQueryJson.Value<string>("searchString"));
15+
16+
if (libraryQueryJson.ContainsKey("excludeAnnotations"))
17+
{
18+
libraryQuery.ExcludeAnnotations = libraryQueryJson.Value<bool>("excludeAnnotations");
19+
}
20+
21+
if (libraryQueryJson.ContainsKey("excludeDocumentText"))
22+
{
23+
libraryQuery.ExcludeDocumentText = libraryQueryJson.Value<bool>("excludeDocumentText");
24+
}
25+
26+
if (libraryQueryJson.ContainsKey("matchExactPhrases"))
27+
{
28+
libraryQuery.MatchExactPhrases = libraryQueryJson.Value<bool>("matchExactPhrases");
29+
}
30+
31+
if (libraryQueryJson.ContainsKey("maximumSearchResultsPerDocument"))
32+
{
33+
libraryQuery.MaximumSearchResultsPerDocument = libraryQueryJson.Value<int>("maximumSearchResultsPerDocument");
34+
}
35+
36+
if (libraryQueryJson.ContainsKey("maximumSearchResultsTotal"))
37+
{
38+
libraryQuery.MaximumSearchResultsTotal = libraryQueryJson.Value<int>("maximumSearchResultsTotal");
39+
}
40+
41+
42+
if (libraryQueryJson.ContainsKey("maximumPreviewResultsPerDocument"))
43+
{
44+
libraryQuery.MaximumPreviewResultsPerDocument = libraryQueryJson.Value<int>("maximumPreviewResultsPerDocument");
45+
}
46+
47+
if (libraryQueryJson.ContainsKey("maximumPreviewResultsTotal"))
48+
{
49+
libraryQuery.MaximumPreviewResultsTotal = libraryQueryJson.Value<int>("maximumPreviewResultsTotal");
50+
}
51+
52+
if (libraryQueryJson.ContainsKey("generateTextPreviews"))
53+
{
54+
libraryQuery.GenerateTextPreviews = libraryQueryJson.Value<bool>("generateTextPreviews");
55+
}
56+
57+
if (libraryQueryJson.ContainsKey("generateTextPreviews"))
58+
{
59+
libraryQuery.GenerateTextPreviews = libraryQueryJson.Value<bool>("generateTextPreviews");
60+
}
61+
62+
if (libraryQueryJson.ContainsKey("previewRange"))
63+
{
64+
libraryQuery.PreviewRange = ToRange(libraryQueryJson.GetValue("previewRange"));
65+
}
66+
67+
return libraryQuery;
68+
}
69+
70+
internal static JToken PreviewResultsToJson(IEnumerable<LibraryPreviewResult> previewResults)
71+
{
72+
var previewResultsJson = new JArray();
73+
foreach (var documentQueryResult in previewResults)
74+
{
75+
var result = new JObject
76+
{
77+
{"uid", documentQueryResult.Uid},
78+
{"pageIndex", documentQueryResult.PageIndex},
79+
{"previewText", documentQueryResult.PreviewText},
80+
{"rangeInText", RangeToJson(documentQueryResult.RangeInText)},
81+
{"rangeInPreviewText", RangeToJson(documentQueryResult.RangeInPreviewText)},
82+
{"annotationId", documentQueryResult.AnnotationId}
83+
};
84+
85+
previewResultsJson.Add(result);
86+
}
87+
88+
return previewResultsJson;
89+
}
90+
91+
internal static JToken SearchResultsToJson(IDictionary<string, LibraryQueryResult> queryResults)
92+
{
93+
var queryResultsJson = new JArray();
94+
foreach (var documentQueryResult in queryResults)
95+
{
96+
var result = new JObject
97+
{
98+
{"uid", documentQueryResult.Key},
99+
{"pageResults", LibraryQueryReultToJson(documentQueryResult.Value)}
100+
};
101+
102+
103+
queryResultsJson.Add(result);
104+
}
105+
106+
return queryResultsJson;
107+
}
108+
109+
private static JToken RangeToJson(IRange range)
110+
{
111+
return new JObject
112+
{
113+
{ "position", range.Position},
114+
{ "length", range.Length}
115+
};
116+
}
117+
118+
private static IRange ToRange(JToken rangeJson)
119+
{
120+
return new Range(rangeJson.Value<int>("postion"), rangeJson.Value<int>("length"));
121+
}
122+
123+
private static JArray LibraryQueryReultToJson(LibraryQueryResult libraryQueryResult)
124+
{
125+
var pageNumbersJson = new JArray();
126+
127+
foreach (var pageNumber in libraryQueryResult.PageResults)
128+
{
129+
pageNumbersJson.Add(pageNumber);
130+
}
131+
132+
return pageNumbersJson;
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)