44using Microsoft . AspNetCore . Hosting ;
55using Microsoft . Extensions . Caching . Memory ;
66using Newtonsoft . Json ;
7- using Syncfusion . EJ2 . PdfViewer ;
87using 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 ;
148using WFormatType = Syncfusion . DocIO . FormatType ;
159using Syncfusion . Pdf ;
1610using Syncfusion . Pdf . Graphics ;
1711using Syncfusion . Drawing ;
1812using Syncfusion . Pdf . Parsing ;
19- using Antlr . Runtime . Misc ;
2013using Syncfusion . DocIORenderer ;
2114using Syncfusion . Presentation ;
2215using Syncfusion . PresentationToPdfConverter ;
2316using Syncfusion . XlsIO ;
2417using Syncfusion . XlsIORenderer ;
18+ using Syncfusion . EJ2 . PdfViewer ;
2519
2620namespace PdfViewerLatestDemo . Controllers
2721{
@@ -30,10 +24,10 @@ namespace PdfViewerLatestDemo.Controllers
3024 public class PdfViewerController : Controller
3125 {
3226 private IHostingEnvironment _hostingEnvironment ;
27+
3328 //Initialize the memory cache object
3429 public IMemoryCache _cache ;
3530
36-
3731 public PdfViewerController ( IHostingEnvironment hostingEnvironment , IMemoryCache cache )
3832
3933 {
@@ -75,22 +69,28 @@ public IActionResult Load([FromBody] Dictionary<string, string> jsonObject)
7569 stream = new MemoryStream ( bytes ) ;
7670 }
7771 }
72+
7873 //Water mark method
7974 PdfLoadedDocument loadedDocument = new PdfLoadedDocument ( stream ) ;
8075 for ( int pageCounter = 0 ; pageCounter < loadedDocument . PageCount ; pageCounter ++ )
8176 {
8277 PdfPageBase loadedPage = loadedDocument . Pages [ pageCounter ] ;
8378 PdfGraphics graphics = loadedPage . Graphics ;
79+
8480 //set the font
8581 PdfFont font = new PdfStandardFont ( PdfFontFamily . Helvetica , 20 ) ;
82+
8683 // watermark text.
8784 PdfGraphicsState state = graphics . Save ( ) ;
8885 graphics . SetTransparency ( 0.25f ) ;
86+
8987 //Applies the specified rotation to the transformation matrix of this graphics
9088 graphics . RotateTransform ( - 40 ) ;
89+
9190 //Draws the specified text string at the specified location with the specified brush and font objects.
9291 graphics . DrawString ( "CONFIDENTIAL" , font , PdfPens . Red , PdfBrushes . Red , new PointF ( - 150 , 450 ) ) ;
9392 }
93+
9494 MemoryStream str = new MemoryStream ( ) ;
9595 loadedDocument . Save ( str ) ;
9696 loadedDocument . Close ( true ) ;
@@ -99,10 +99,10 @@ public IActionResult Load([FromBody] Dictionary<string, string> jsonObject)
9999 }
100100
101101 [ AcceptVerbs ( "Post" ) ]
102- [ HttpPost ( "GetImageStream " ) ]
103- [ Route ( "[controller]/GetImageStream " ) ]
102+ [ HttpPost ( "LoadFile " ) ]
103+ [ Route ( "[controller]/LoadFile " ) ]
104104 //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 )
106106 {
107107 if ( jsonObject . ContainsKey ( "data" ) )
108108 {
@@ -179,17 +179,12 @@ public IActionResult GetImageStream([FromBody] Dictionary<string, string> jsonOb
179179
180180 }
181181 return Content ( "data:application/pdf;base64," + "" ) ;
182- }
183- public void loadPDFdocument ( byte [ ] bytes )
184- {
185-
186-
187182 }
188183
189184 public static WFormatType GetWFormatType ( string format )
190185 {
191186 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 ." ) ;
193188 switch ( format . ToLower ( ) )
194189 {
195190 case "dotx" :
@@ -207,7 +202,7 @@ public static WFormatType GetWFormatType(string format)
207202 case "rtf" :
208203 return WFormatType . Rtf ;
209204 default :
210- throw new NotSupportedException ( "EJ2 DocumentEditor does not support this file format ." ) ;
205+ throw new NotSupportedException ( "This is not a valid Word documnet ." ) ;
211206 }
212207 }
213208
@@ -458,4 +453,4 @@ public IActionResult Index()
458453 return View ( ) ;
459454 }
460455 }
461- }
456+ }
0 commit comments