Skip to content

Commit 0637b22

Browse files
author
SasidharanKaruppiah
authored
Merge pull request #12 from SyncfusionExamples/EJ2-69537-angular
EJ2-69537 : modification in index and controllers file
2 parents 85a07d9 + 98cefd8 commit 0637b22

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

Common/Load PDF, Excel, PPT file types/Load PDF, Excel, PPT file types/src/index.html

+2-4
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@
141141
]);
142142
}
143143

144-
145-
146144
function onFileUpload(args) {
147145
var li = document
148146
.getElementById('dropArea')
@@ -178,7 +176,7 @@
178176
'data': reader.result,
179177
'type': type
180178
})
181-
const url = "https://localhost:44327/pdfviewer/GetImageStream"
179+
const url = "https://localhost:44327/pdfviewer/LoadFile"
182180
let xhr = new XMLHttpRequest()
183181
xhr.open('Post', url, true)
184182
xhr.setRequestHeader('Content-type', 'application/json; charset=UTF-8')
@@ -515,4 +513,4 @@
515513

516514
</style>
517515

518-
</html>
516+
</html>

Common/Load PDF, Excel, PPT file types/Web Service/Controllers/PdfViewerController.cs

+17-22
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,18 @@
44
using Microsoft.AspNetCore.Hosting;
55
using Microsoft.Extensions.Caching.Memory;
66
using Newtonsoft.Json;
7-
using Syncfusion.EJ2.PdfViewer;
87
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;
148
using WFormatType = Syncfusion.DocIO.FormatType;
159
using Syncfusion.Pdf;
1610
using Syncfusion.Pdf.Graphics;
1711
using Syncfusion.Drawing;
1812
using Syncfusion.Pdf.Parsing;
19-
using Antlr.Runtime.Misc;
2013
using Syncfusion.DocIORenderer;
2114
using Syncfusion.Presentation;
2215
using Syncfusion.PresentationToPdfConverter;
2316
using Syncfusion.XlsIO;
2417
using Syncfusion.XlsIORenderer;
18+
using Syncfusion.EJ2.PdfViewer;
2519

2620
namespace 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
{
@@ -167,29 +167,24 @@ public IActionResult GetImageStream([FromBody] Dictionary<string, string> jsonOb
167167
}
168168

169169
}
170-
pdfDocument.Save(outputStream);
170+
pdfDocument.Save(outputStream);
171171
outputStream.Position = 0;
172-
byte[] byteArray= outputStream.ToArray();
172+
byte[] byteArray = outputStream.ToArray();
173173
pdfDocument.Close();
174174
outputStream.Close();
175175

176-
string base64String = Convert.ToBase64String(byteArray);
176+
string base64String = Convert.ToBase64String(byteArray);
177177
return Content("data:application/pdf;base64," + base64String);
178178

179-
179+
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

0 commit comments

Comments
 (0)