4
4
using Microsoft . AspNetCore . Hosting ;
5
5
using Microsoft . Extensions . Caching . Memory ;
6
6
using Newtonsoft . Json ;
7
- using Syncfusion . EJ2 . PdfViewer ;
8
7
using System . IO ;
9
- using System . Linq ;
10
- using System . Threading . Tasks ;
11
- using Microsoft . AspNetCore . Http ;
12
- using System . Web . Helpers ;
13
- using Microsoft . Ajax . Utilities ;
14
8
using WFormatType = Syncfusion . DocIO . FormatType ;
15
9
using Syncfusion . Pdf ;
16
10
using Syncfusion . Pdf . Graphics ;
17
11
using Syncfusion . Drawing ;
18
12
using Syncfusion . Pdf . Parsing ;
19
- using Antlr . Runtime . Misc ;
20
13
using Syncfusion . DocIORenderer ;
21
14
using Syncfusion . Presentation ;
22
15
using Syncfusion . PresentationToPdfConverter ;
23
16
using Syncfusion . XlsIO ;
24
17
using Syncfusion . XlsIORenderer ;
18
+ using Syncfusion . EJ2 . PdfViewer ;
25
19
26
20
namespace PdfViewerLatestDemo . Controllers
27
21
{
@@ -30,10 +24,10 @@ namespace PdfViewerLatestDemo.Controllers
30
24
public class PdfViewerController : Controller
31
25
{
32
26
private IHostingEnvironment _hostingEnvironment ;
27
+
33
28
//Initialize the memory cache object
34
29
public IMemoryCache _cache ;
35
30
36
-
37
31
public PdfViewerController ( IHostingEnvironment hostingEnvironment , IMemoryCache cache )
38
32
39
33
{
@@ -75,22 +69,28 @@ public IActionResult Load([FromBody] Dictionary<string, string> jsonObject)
75
69
stream = new MemoryStream ( bytes ) ;
76
70
}
77
71
}
72
+
78
73
//Water mark method
79
74
PdfLoadedDocument loadedDocument = new PdfLoadedDocument ( stream ) ;
80
75
for ( int pageCounter = 0 ; pageCounter < loadedDocument . PageCount ; pageCounter ++ )
81
76
{
82
77
PdfPageBase loadedPage = loadedDocument . Pages [ pageCounter ] ;
83
78
PdfGraphics graphics = loadedPage . Graphics ;
79
+
84
80
//set the font
85
81
PdfFont font = new PdfStandardFont ( PdfFontFamily . Helvetica , 20 ) ;
82
+
86
83
// watermark text.
87
84
PdfGraphicsState state = graphics . Save ( ) ;
88
85
graphics . SetTransparency ( 0.25f ) ;
86
+
89
87
//Applies the specified rotation to the transformation matrix of this graphics
90
88
graphics . RotateTransform ( - 40 ) ;
89
+
91
90
//Draws the specified text string at the specified location with the specified brush and font objects.
92
91
graphics . DrawString ( "CONFIDENTIAL" , font , PdfPens . Red , PdfBrushes . Red , new PointF ( - 150 , 450 ) ) ;
93
92
}
93
+
94
94
MemoryStream str = new MemoryStream ( ) ;
95
95
loadedDocument . Save ( str ) ;
96
96
loadedDocument . Close ( true ) ;
@@ -99,10 +99,10 @@ public IActionResult Load([FromBody] Dictionary<string, string> jsonObject)
99
99
}
100
100
101
101
[ AcceptVerbs ( "Post" ) ]
102
- [ HttpPost ( "GetImageStream " ) ]
103
- [ Route ( "[controller]/GetImageStream " ) ]
102
+ [ HttpPost ( "LoadFile " ) ]
103
+ [ Route ( "[controller]/LoadFile " ) ]
104
104
//Post action for loading the Office products
105
- public IActionResult GetImageStream ( [ FromBody ] Dictionary < string , string > jsonObject )
105
+ public IActionResult LoadFile ( [ FromBody ] Dictionary < string , string > jsonObject )
106
106
{
107
107
if ( jsonObject . ContainsKey ( "data" ) )
108
108
{
@@ -167,29 +167,24 @@ public IActionResult GetImageStream([FromBody] Dictionary<string, string> jsonOb
167
167
}
168
168
169
169
}
170
- pdfDocument . Save ( outputStream ) ;
170
+ pdfDocument . Save ( outputStream ) ;
171
171
outputStream . Position = 0 ;
172
- byte [ ] byteArray = outputStream . ToArray ( ) ;
172
+ byte [ ] byteArray = outputStream . ToArray ( ) ;
173
173
pdfDocument . Close ( ) ;
174
174
outputStream . Close ( ) ;
175
175
176
- string base64String = Convert . ToBase64String ( byteArray ) ;
176
+ string base64String = Convert . ToBase64String ( byteArray ) ;
177
177
return Content ( "data:application/pdf;base64," + base64String ) ;
178
178
179
-
179
+
180
180
}
181
181
return Content ( "data:application/pdf;base64," + "" ) ;
182
- }
183
- public void loadPDFdocument ( byte [ ] bytes )
184
- {
185
-
186
-
187
182
}
188
183
189
184
public static WFormatType GetWFormatType ( string format )
190
185
{
191
186
if ( string . IsNullOrEmpty ( format ) )
192
- throw new NotSupportedException ( "EJ2 DocumentEditor does not support this file format ." ) ;
187
+ throw new NotSupportedException ( "This is not a valid Word documnet ." ) ;
193
188
switch ( format . ToLower ( ) )
194
189
{
195
190
case "dotx" :
@@ -207,7 +202,7 @@ public static WFormatType GetWFormatType(string format)
207
202
case "rtf" :
208
203
return WFormatType . Rtf ;
209
204
default :
210
- throw new NotSupportedException ( "EJ2 DocumentEditor does not support this file format ." ) ;
205
+ throw new NotSupportedException ( "This is not a valid Word documnet ." ) ;
211
206
}
212
207
}
213
208
0 commit comments