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