@@ -21,290 +21,5 @@ public IndexModel(Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnviro
2121 _cache = cache ;
2222 }
2323
24- public IActionResult OnPostLoad ( [ FromBody ] jsonObjects responseData )
25- {
26- PdfRenderer pdfviewer = new PdfRenderer ( _cache ) ;
27- MemoryStream stream = new MemoryStream ( ) ;
28- var jsonObject = JsonConverterstring ( responseData ) ;
29- object jsonResult = new object ( ) ;
30- if ( jsonObject != null && jsonObject . ContainsKey ( "document" ) )
31- {
32- if ( bool . Parse ( jsonObject [ "isFileName" ] ) )
33- {
34- string documentPath = GetDocumentPath ( jsonObject [ "document" ] ) ;
35- if ( ! string . IsNullOrEmpty ( documentPath ) )
36- {
37- byte [ ] bytes = System . IO . File . ReadAllBytes ( documentPath ) ;
38- stream = new MemoryStream ( bytes ) ;
39- }
40- else
41- {
42- string fileName = jsonObject [ "document" ] . Split ( new string [ ] { "://" } , StringSplitOptions . None ) [ 0 ] ;
43- if ( fileName == "http" || fileName == "https" )
44- {
45- WebClient WebClient = new WebClient ( ) ;
46- byte [ ] pdfDoc = WebClient . DownloadData ( jsonObject [ "document" ] ) ;
47- stream = new MemoryStream ( pdfDoc ) ;
48- }
49- else
50- return this . Content ( jsonObject [ "document" ] + " is not found" ) ;
51- }
52- }
53- else
54- {
55- byte [ ] bytes = Convert . FromBase64String ( jsonObject [ "document" ] ) ;
56- stream = new MemoryStream ( bytes ) ;
57- }
58- }
59- jsonResult = pdfviewer . Load ( stream , jsonObject ) ;
60- return Content ( JsonConvert . SerializeObject ( jsonResult ) ) ;
61- }
62-
63- public IActionResult OnPostValidatePassword ( [ FromBody ] jsonObjects responseData )
64- {
65- PdfRenderer pdfviewer = new PdfRenderer ( _cache ) ;
66- MemoryStream stream = new MemoryStream ( ) ;
67- var jsonObject = JsonConverterstring ( responseData ) ;
68- object jsonResult = new object ( ) ;
69- if ( jsonObject != null && jsonObject . ContainsKey ( "document" ) )
70- {
71- if ( bool . Parse ( jsonObject [ "isFileName" ] ) )
72- {
73- string documentPath = GetDocumentPath ( jsonObject [ "document" ] ) ;
74- if ( ! string . IsNullOrEmpty ( documentPath ) )
75- {
76- byte [ ] bytes = System . IO . File . ReadAllBytes ( documentPath ) ;
77- stream = new MemoryStream ( bytes ) ;
78- }
79- else
80- {
81- string fileName = jsonObject [ "document" ] . Split ( new string [ ] { "://" } , StringSplitOptions . None ) [ 0 ] ;
82- if ( fileName == "http" || fileName == "https" )
83- {
84- WebClient WebClient = new WebClient ( ) ;
85- byte [ ] pdfDoc = WebClient . DownloadData ( jsonObject [ "document" ] ) ;
86- stream = new MemoryStream ( pdfDoc ) ;
87- }
88- else
89- return this . Content ( jsonObject [ "document" ] + " is not found" ) ;
90- }
91- }
92- else
93- {
94- byte [ ] bytes = Convert . FromBase64String ( jsonObject [ "document" ] ) ;
95- stream = new MemoryStream ( bytes ) ;
96- }
97- }
98- string password = null ;
99- if ( jsonObject . ContainsKey ( "password" ) )
100- {
101- password = jsonObject [ "password" ] ;
102- }
103- var result = pdfviewer . Load ( stream , password ) ;
104-
105- return Content ( JsonConvert . SerializeObject ( result ) ) ;
106- }
107- public Dictionary < string , string > JsonConverterstring ( jsonObjects results )
108- {
109- Dictionary < string , object > resultObjects = new Dictionary < string , object > ( ) ;
110- resultObjects = results . GetType ( ) . GetProperties ( BindingFlags . Instance | BindingFlags . Public )
111- . ToDictionary ( prop => prop . Name , prop => prop . GetValue ( results , null ) ) ;
112- var emptyObjects = ( from kv in resultObjects
113- where kv . Value != null
114- select kv ) . ToDictionary ( kv => kv . Key , kv => kv . Value ) ;
115- Dictionary < string , string > jsonResult = emptyObjects . ToDictionary ( k => k . Key , k => k . Value . ToString ( ) ) ;
116- return jsonResult ;
117- }
118-
119- //Post action for processing the PDF documents.
120- public IActionResult OnPostRenderPdfPages ( [ FromBody ] jsonObjects responseData )
121- {
122- PdfRenderer pdfviewer = new PdfRenderer ( _cache ) ;
123- var jsonObject = JsonConverterstring ( responseData ) ;
124- object jsonResult = pdfviewer . GetPage ( jsonObject ) ;
125- return Content ( JsonConvert . SerializeObject ( jsonResult ) ) ;
126- }
127-
128- //Post action for unloading and disposing the PDF document resources
129- public IActionResult OnPostUnload ( [ FromBody ] jsonObjects responseData )
130- {
131- PdfRenderer pdfviewer = new PdfRenderer ( _cache ) ;
132- var jsonObject = JsonConverterstring ( responseData ) ;
133- pdfviewer . ClearCache ( jsonObject ) ;
134- return this . Content ( "Document cache is cleared" ) ;
135- }
136-
137- //Post action for rendering the ThumbnailImages
138- public IActionResult OnPostRenderThumbnailImages ( [ FromBody ] jsonObjects responseData )
139- {
140- PdfRenderer pdfviewer = new PdfRenderer ( _cache ) ;
141- var jsonObject = JsonConverterstring ( responseData ) ;
142- object result = pdfviewer . GetThumbnailImages ( jsonObject ) ;
143- return Content ( JsonConvert . SerializeObject ( result ) ) ;
144- }
145-
146- //Post action for processing the bookmarks from the PDF documents
147- public IActionResult OnPostBookmarks ( [ FromBody ] jsonObjects responseData )
148- {
149- PdfRenderer pdfviewer = new PdfRenderer ( _cache ) ;
150- var jsonObject = JsonConverterstring ( responseData ) ;
151- object jsonResult = pdfviewer . GetBookmarks ( jsonObject ) ;
152- return Content ( JsonConvert . SerializeObject ( jsonResult ) ) ;
153- }
154-
155- //Post action for rendering the annotation comments
156- public IActionResult OnPostRenderAnnotationComments ( [ FromBody ] jsonObjects responseData )
157- {
158- PdfRenderer pdfviewer = new PdfRenderer ( _cache ) ;
159- var jsonObject = JsonConverterstring ( responseData ) ;
160- object jsonResult = pdfviewer . GetAnnotationComments ( jsonObject ) ;
161- return Content ( JsonConvert . SerializeObject ( jsonResult ) ) ;
162- }
163-
164- //Post action for exporting the annotations
165- public IActionResult OnPostExportAnnotations ( [ FromBody ] jsonObjects responseData )
166- {
167- PdfRenderer pdfviewer = new PdfRenderer ( _cache ) ;
168- var jsonObject = JsonConverterstring ( responseData ) ;
169- string jsonResult = pdfviewer . ExportAnnotation ( jsonObject ) ;
170- return Content ( jsonResult ) ;
171- }
172-
173- //Post action for importing the annotations
174- public IActionResult OnPostImportAnnotations ( [ FromBody ] jsonObjects responseData )
175- {
176- PdfRenderer pdfviewer = new PdfRenderer ( _cache ) ;
177- var jsonObject = JsonConverterstring ( responseData ) ;
178- string jsonResult = string . Empty ;
179- object JsonResult ;
180- if ( jsonObject != null && jsonObject . ContainsKey ( "fileName" ) )
181- {
182- string documentPath = GetDocumentPath ( jsonObject [ "fileName" ] ) ;
183- if ( ! string . IsNullOrEmpty ( documentPath ) )
184- {
185- jsonResult = System . IO . File . ReadAllText ( documentPath ) ;
186- }
187- else
188- {
189- return this . Content ( jsonObject [ "document" ] + " is not found" ) ;
190- }
191- }
192- else
193- {
194- string extension = Path . GetExtension ( jsonObject [ "importedData" ] ) ;
195- if ( extension != ".xfdf" )
196- {
197- JsonResult = pdfviewer . ImportAnnotation ( jsonObject ) ;
198- return Content ( JsonConvert . SerializeObject ( JsonResult ) ) ;
199- }
200- else
201- {
202- string documentPath = GetDocumentPath ( jsonObject [ "importedData" ] ) ;
203- if ( ! string . IsNullOrEmpty ( documentPath ) )
204- {
205- byte [ ] bytes = System . IO . File . ReadAllBytes ( documentPath ) ;
206- jsonObject [ "importedData" ] = Convert . ToBase64String ( bytes ) ;
207- JsonResult = pdfviewer . ImportAnnotation ( jsonObject ) ;
208- return Content ( JsonConvert . SerializeObject ( JsonResult ) ) ;
209- }
210- else
211- {
212- return this . Content ( jsonObject [ "document" ] + " is not found" ) ;
213- }
214- }
215- }
216- return Content ( jsonResult ) ;
217- }
218-
219- //Post action for downloading the PDF documents
220- public IActionResult OnPostDownload ( [ FromBody ] jsonObjects responseData )
221- {
222- PdfRenderer pdfviewer = new PdfRenderer ( _cache ) ;
223- var jsonObject = JsonConverterstring ( responseData ) ;
224- string documentBase = pdfviewer . GetDocumentAsBase64 ( jsonObject ) ;
225- return Content ( documentBase ) ;
226- }
227-
228- //Post action for printing the PDF documents
229- public IActionResult OnPostPrintImages ( [ FromBody ] jsonObjects responseData )
230- {
231- PdfRenderer pdfviewer = new PdfRenderer ( _cache ) ;
232- var jsonObject = JsonConverterstring ( responseData ) ;
233- object pageImage = pdfviewer . GetPrintImage ( jsonObject ) ;
234- return Content ( JsonConvert . SerializeObject ( pageImage ) ) ;
235- }
236-
237- //Gets the path of the PDF document
238- private string GetDocumentPath ( string document )
239- {
240- string documentPath = string . Empty ;
241- if ( ! System . IO . File . Exists ( document ) )
242- {
243- string basePath = _hostingEnvironment . WebRootPath ;
244- string dataPath = string . Empty ;
245- dataPath = basePath + "/" ;
246- if ( System . IO . File . Exists ( dataPath + ( document ) ) )
247- documentPath = dataPath + document ;
248- }
249- else
250- {
251- documentPath = document ;
252- }
253- return documentPath ;
254- }
255- }
256-
257- public class jsonObjects
258- {
259- public string document { get ; set ; }
260- public string password { get ; set ; }
261- public string zoomFactor { get ; set ; }
262- public string isFileName { get ; set ; }
263- public string xCoordinate { get ; set ; }
264- public string yCoordinate { get ; set ; }
265- public string pageNumber { get ; set ; }
266- public string documentId { get ; set ; }
267- public string hashId { get ; set ; }
268- public string sizeX { get ; set ; }
269- public string sizeY { get ; set ; }
270- public string startPage { get ; set ; }
271- public string endPage { get ; set ; }
272- public string stampAnnotations { get ; set ; }
273- public string textMarkupAnnotations { get ; set ; }
274- public string stickyNotesAnnotation { get ; set ; }
275- public string shapeAnnotations { get ; set ; }
276- public string measureShapeAnnotations { get ; set ; }
277- public string action { get ; set ; }
278- public string pageStartIndex { get ; set ; }
279- public string pageEndIndex { get ; set ; }
280- public string fileName { get ; set ; }
281- public string elementId { get ; set ; }
282- public string pdfAnnotation { get ; set ; }
283- public string importPageList { get ; set ; }
284- public string uniqueId { get ; set ; }
285- public string data { get ; set ; }
286- public string viewPortWidth { get ; set ; }
287- public string viewPortHeight { get ; set ; }
288- public string tilecount { get ; set ; }
289- public bool isCompletePageSizeNotReceived { get ; set ; }
290- public string freeTextAnnotation { get ; set ; }
291- public string signatureData { get ; set ; }
292- public string fieldsData { get ; set ; }
293- public string FormDesigner { get ; set ; }
294- public string inkSignatureData { get ; set ; }
295- public bool hideEmptyDigitalSignatureFields { get ; set ; }
296- public bool showDigitalSignatureAppearance { get ; set ; }
297- public bool digitalSignaturePresent { get ; set ; }
298- public string tileXCount { get ; set ; }
299- public string tileYCount { get ; set ; }
300- public string digitalSignaturePageList { get ; set ; }
301- public string annotationCollection { get ; set ; }
302- public string annotationsPageList { get ; set ; }
303- public string formFieldsPageList { get ; set ; }
304- public bool isAnnotationsExist { get ; set ; }
305- public bool isFormFieldAnnotationsExist { get ; set ; }
306- public string documentLiveCount { get ; set ; }
307- public string annotationDataFormat { get ; set ; }
308- public string importedData { get ; set ; }
30924 }
31025}
0 commit comments