diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted.sln b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted.sln new file mode 100644 index 0000000..733a8ff --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34607.79 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtractTextCompleted", "ExtractTextCompleted\ExtractTextCompleted.csproj", "{59881E06-975A-4502-9E1A-558C2540FCFB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {59881E06-975A-4502-9E1A-558C2540FCFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {59881E06-975A-4502-9E1A-558C2540FCFB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {59881E06-975A-4502-9E1A-558C2540FCFB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {59881E06-975A-4502-9E1A-558C2540FCFB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {31245B35-82FC-4C3B-A888-4730D0AD8EE0} + EndGlobalSection +EndGlobal diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/ExtractTextCompleted.csproj b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/ExtractTextCompleted.csproj new file mode 100644 index 0000000..bd93b42 --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/ExtractTextCompleted.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/ExtractTextCompleted.csproj.user b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/ExtractTextCompleted.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/ExtractTextCompleted.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Error.cshtml b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Error.cshtml new file mode 100644 index 0000000..6f92b95 --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Error.cshtml @@ -0,0 +1,26 @@ +@page +@model ErrorModel +@{ + ViewData["Title"] = "Error"; +} + +

Error.

+

An error occurred while processing your request.

+ +@if (Model.ShowRequestId) +{ +

+ Request ID: @Model.RequestId +

+} + +

Development Mode

+

+ Swapping to the Development environment displays detailed information about the error that occurred. +

+

+ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +

diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Error.cshtml.cs b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Error.cshtml.cs new file mode 100644 index 0000000..c008cae --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Error.cshtml.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using System.Diagnostics; + +namespace PDFViewerSample.Pages +{ + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [IgnoreAntiforgeryToken] + public class ErrorModel : PageModel + { + public string? RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + private readonly ILogger _logger; + + public ErrorModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; + } + } + +} diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Index.cshtml b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Index.cshtml new file mode 100644 index 0000000..c029f7a --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Index.cshtml @@ -0,0 +1,28 @@ +@page "{handler?}" +@model IndexModel +@{ + ViewData["Title"] = "Home page"; +} + +
+ + +
+ + \ No newline at end of file diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Index.cshtml.cs b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Index.cshtml.cs new file mode 100644 index 0000000..721e2f7 --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Index.cshtml.cs @@ -0,0 +1,266 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Caching.Memory; +using Syncfusion.EJ2.PdfViewer; +using Newtonsoft.Json; +using Microsoft.AspNetCore.Mvc.RazorPages; +using System.Reflection; +using System.Net; + +namespace PDFViewerSample.Pages +{ + [IgnoreAntiforgeryToken(Order = 1001)] + public class IndexModel : PageModel + { + + private readonly Microsoft.AspNetCore.Hosting.IHostingEnvironment _hostingEnvironment; + private IMemoryCache _cache; + + public IndexModel(Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment, IMemoryCache cache) + { + _hostingEnvironment = hostingEnvironment; + _cache = cache; + } + + public IActionResult OnPostLoad([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + MemoryStream stream = new MemoryStream(); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = new object(); + if (jsonObject != null && jsonObject.ContainsKey("document")) + { + if (bool.Parse(jsonObject["isFileName"])) + { + string documentPath = GetDocumentPath(jsonObject["document"]); + if (!string.IsNullOrEmpty(documentPath)) + { + byte[] bytes = System.IO.File.ReadAllBytes(documentPath); + stream = new MemoryStream(bytes); + } + else + { + string fileName = jsonObject["document"].Split(new string[] { "://" }, StringSplitOptions.None)[0]; + if (fileName == "http" || fileName == "https") + { + WebClient WebClient = new WebClient(); + byte[] pdfDoc = WebClient.DownloadData(jsonObject["document"]); + stream = new MemoryStream(pdfDoc); + } + else + return this.Content(jsonObject["document"] + " is not found"); + } + } + else + { + byte[] bytes = Convert.FromBase64String(jsonObject["document"]); + stream = new MemoryStream(bytes); + } + } + jsonResult = pdfviewer.Load(stream, jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + public Dictionary JsonConverterstring(jsonObjects results) + { + Dictionary resultObjects = new Dictionary(); + resultObjects = results.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public) + .ToDictionary(prop => prop.Name, prop => prop.GetValue(results, null)); + var emptyObjects = (from kv in resultObjects + where kv.Value != null + select kv).ToDictionary(kv => kv.Key, kv => kv.Value); + Dictionary jsonResult = emptyObjects.ToDictionary(k => k.Key, k => k.Value.ToString()); + return jsonResult; + } + + //Post action for processing the PDF documents. + public IActionResult OnPostRenderPdfPages([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = pdfviewer.GetPage(jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + //Post action for unloading and disposing the PDF document resources + public IActionResult OnPostUnload([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + pdfviewer.ClearCache(jsonObject); + return this.Content("Document cache is cleared"); + } + + //Post action for rendering the ThumbnailImages + public IActionResult OnPostRenderThumbnailImages([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object result = pdfviewer.GetThumbnailImages(jsonObject); + return Content(JsonConvert.SerializeObject(result)); + } + + //Post action for processing the bookmarks from the PDF documents + public IActionResult OnPostBookmarks([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = pdfviewer.GetBookmarks(jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + //Post action for rendering the annotation comments + public IActionResult OnPostRenderAnnotationComments([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = pdfviewer.GetAnnotationComments(jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + //Post action for exporting the annotations + public IActionResult OnPostExportAnnotations([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + string jsonResult = pdfviewer.ExportAnnotation(jsonObject); + return Content(jsonResult); + } + + //Post action for importing the annotations + public IActionResult OnPostImportAnnotations([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + string jsonResult = string.Empty; + object JsonResult; + if (jsonObject != null && jsonObject.ContainsKey("fileName")) + { + string documentPath = GetDocumentPath(jsonObject["fileName"]); + if (!string.IsNullOrEmpty(documentPath)) + { + jsonResult = System.IO.File.ReadAllText(documentPath); + } + else + { + return this.Content(jsonObject["document"] + " is not found"); + } + } + else + { + string extension = Path.GetExtension(jsonObject["importedData"]); + if (extension != ".xfdf") + { + JsonResult = pdfviewer.ImportAnnotation(jsonObject); + return Content(JsonConvert.SerializeObject(JsonResult)); + } + else + { + string documentPath = GetDocumentPath(jsonObject["importedData"]); + if (!string.IsNullOrEmpty(documentPath)) + { + byte[] bytes = System.IO.File.ReadAllBytes(documentPath); + jsonObject["importedData"] = Convert.ToBase64String(bytes); + JsonResult = pdfviewer.ImportAnnotation(jsonObject); + return Content(JsonConvert.SerializeObject(JsonResult)); + } + else + { + return this.Content(jsonObject["document"] + " is not found"); + } + } + } + return Content(jsonResult); + } + + //Post action for downloading the PDF documents + public IActionResult OnPostDownload([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject); + return Content(documentBase); + } + + //Post action for printing the PDF documents + public IActionResult OnPostPrintImages([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object pageImage = pdfviewer.GetPrintImage(jsonObject); + return Content(JsonConvert.SerializeObject(pageImage)); + } + + //Gets the path of the PDF document + private string GetDocumentPath(string document) + { + string documentPath = string.Empty; + if (!System.IO.File.Exists(document)) + { + string basePath = _hostingEnvironment.WebRootPath; + string dataPath = string.Empty; + dataPath = basePath + "/"; + if (System.IO.File.Exists(dataPath + (document))) + documentPath = dataPath + document; + } + else + { + documentPath = document; + } + return documentPath; + } + } + + public class jsonObjects + { + public string document { get; set; } + public string password { get; set; } + public string zoomFactor { get; set; } + public string isFileName { get; set; } + public string xCoordinate { get; set; } + public string yCoordinate { get; set; } + public string pageNumber { get; set; } + public string documentId { get; set; } + public string hashId { get; set; } + public string sizeX { get; set; } + public string sizeY { get; set; } + public string startPage { get; set; } + public string endPage { get; set; } + public string stampAnnotations { get; set; } + public string textMarkupAnnotations { get; set; } + public string stickyNotesAnnotation { get; set; } + public string shapeAnnotations { get; set; } + public string measureShapeAnnotations { get; set; } + public string action { get; set; } + public string pageStartIndex { get; set; } + public string pageEndIndex { get; set; } + public string fileName { get; set; } + public string elementId { get; set; } + public string pdfAnnotation { get; set; } + public string importPageList { get; set; } + public string uniqueId { get; set; } + public string data { get; set; } + public string viewPortWidth { get; set; } + public string viewPortHeight { get; set; } + public string tilecount { get; set; } + public bool isCompletePageSizeNotReceived { get; set; } + public string freeTextAnnotation { get; set; } + public string signatureData { get; set; } + public string fieldsData { get; set; } + public string formDesigner { get; set; } + public string inkSignatureData { get; set; } + public bool hideEmptyDigitalSignatureFields { get; set; } + public bool showDigitalSignatureAppearance { get; set; } + public bool digitalSignaturePresent { get; set; } + public string tileXCount { get; set; } + public string tileYCount { get; set; } + public string digitalSignaturePageList { get; set; } + public string annotationCollection { get; set; } + public string annotationsPageList { get; set; } + public string formFieldsPageList { get; set; } + public bool isAnnotationsExist { get; set; } + public bool isFormFieldAnnotationsExist { get; set; } + public string documentLiveCount { get; set; } + public string annotationDataFormat { get; set; } + public string importedData { get; set; } + } +} \ No newline at end of file diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Privacy.cshtml b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Privacy.cshtml new file mode 100644 index 0000000..46ba966 --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Privacy.cshtml @@ -0,0 +1,8 @@ +@page +@model PrivacyModel +@{ + ViewData["Title"] = "Privacy Policy"; +} +

@ViewData["Title"]

+ +

Use this page to detail your site's privacy policy.

diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Privacy.cshtml.cs b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Privacy.cshtml.cs new file mode 100644 index 0000000..cd60641 --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Privacy.cshtml.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace PDFViewerSample.Pages +{ + public class PrivacyModel : PageModel + { + private readonly ILogger _logger; + + public PrivacyModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + } + } + +} diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Shared/_Layout.cshtml b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Shared/_Layout.cshtml new file mode 100644 index 0000000..f1ce8ac --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Shared/_Layout.cshtml @@ -0,0 +1,30 @@ + + + + + + @ViewData["Title"] - PDFViewerSample + + + + + + + + + +
+
+ @RenderBody() +
+
+ + + + + + @await RenderSectionAsync("Scripts", required: false) + + + + \ No newline at end of file diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Shared/_Layout.cshtml.css b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Shared/_Layout.cshtml.css new file mode 100644 index 0000000..c187c02 --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Shared/_Layout.cshtml.css @@ -0,0 +1,48 @@ +/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification +for details on configuring this project to bundle and minify static web assets. */ + +a.navbar-brand { + white-space: normal; + text-align: center; + word-break: break-all; +} + +a { + color: #0077cc; +} + +.btn-primary { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; +} + +.nav-pills .nav-link.active, .nav-pills .show > .nav-link { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; +} + +.border-top { + border-top: 1px solid #e5e5e5; +} +.border-bottom { + border-bottom: 1px solid #e5e5e5; +} + +.box-shadow { + box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); +} + +button.accept-policy { + font-size: 1rem; + line-height: inherit; +} + +.footer { + position: absolute; + bottom: 0; + width: 100%; + white-space: nowrap; + line-height: 60px; +} diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Shared/_ValidationScriptsPartial.cshtml b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Shared/_ValidationScriptsPartial.cshtml new file mode 100644 index 0000000..5a16d80 --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/Shared/_ValidationScriptsPartial.cshtml @@ -0,0 +1,2 @@ + + diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/_ViewImports.cshtml b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/_ViewImports.cshtml new file mode 100644 index 0000000..51b8015 --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/_ViewImports.cshtml @@ -0,0 +1,4 @@ +@using PDFViewerSample +@namespace PDFViewerSample.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@addTagHelper *, Syncfusion.EJ2 \ No newline at end of file diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/_ViewStart.cshtml b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/_ViewStart.cshtml new file mode 100644 index 0000000..a5f1004 --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Pages/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +} diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Program.cs b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Program.cs new file mode 100644 index 0000000..bc275e4 --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddRazorPages(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (!app.Environment.IsDevelopment()) +{ + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} + +app.UseHttpsRedirection(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthorization(); + +app.MapRazorPages(); + +app.Run(); diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Properties/launchSettings.json b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Properties/launchSettings.json new file mode 100644 index 0000000..dbe83ce --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:12333", + "sslPort": 44366 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5059", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7232;http://localhost:5059", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/appsettings.Development.json b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/appsettings.Development.json new file mode 100644 index 0000000..770d3e9 --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "DetailedErrors": true, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/appsettings.json b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/wwwroot/favicon.ico b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/wwwroot/favicon.ico new file mode 100644 index 0000000..63e859b Binary files /dev/null and b/How to/Extract Text Completed/ExtractTextCompleted/ExtractTextCompleted/wwwroot/favicon.ico differ diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption.sln b/How to/Extract Text option/ExtractTextOption/ExtractTextOption.sln new file mode 100644 index 0000000..eee0ea9 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34607.79 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtractTextOption", "ExtractTextOption\ExtractTextOption.csproj", "{69139F74-1893-4262-95A7-DED78CA5DFC0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {69139F74-1893-4262-95A7-DED78CA5DFC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {69139F74-1893-4262-95A7-DED78CA5DFC0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {69139F74-1893-4262-95A7-DED78CA5DFC0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {69139F74-1893-4262-95A7-DED78CA5DFC0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {31245B35-82FC-4C3B-A888-4730D0AD8EE0} + EndGlobalSection +EndGlobal diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/ExtractTextOption.csproj b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/ExtractTextOption.csproj new file mode 100644 index 0000000..bd93b42 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/ExtractTextOption.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/ExtractTextOption.csproj.user b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/ExtractTextOption.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/ExtractTextOption.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Error.cshtml b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Error.cshtml new file mode 100644 index 0000000..6f92b95 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Error.cshtml @@ -0,0 +1,26 @@ +@page +@model ErrorModel +@{ + ViewData["Title"] = "Error"; +} + +

Error.

+

An error occurred while processing your request.

+ +@if (Model.ShowRequestId) +{ +

+ Request ID: @Model.RequestId +

+} + +

Development Mode

+

+ Swapping to the Development environment displays detailed information about the error that occurred. +

+

+ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +

diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Error.cshtml.cs b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Error.cshtml.cs new file mode 100644 index 0000000..c008cae --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Error.cshtml.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using System.Diagnostics; + +namespace PDFViewerSample.Pages +{ + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [IgnoreAntiforgeryToken] + public class ErrorModel : PageModel + { + public string? RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + private readonly ILogger _logger; + + public ErrorModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; + } + } + +} diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Index.cshtml b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Index.cshtml new file mode 100644 index 0000000..d3fa1e5 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Index.cshtml @@ -0,0 +1,14 @@ +@page "{handler?}" +@model IndexModel +@{ + ViewData["Title"] = "Home page"; +} + +
+ + +
+ + \ No newline at end of file diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Index.cshtml.cs b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Index.cshtml.cs new file mode 100644 index 0000000..721e2f7 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Index.cshtml.cs @@ -0,0 +1,266 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Caching.Memory; +using Syncfusion.EJ2.PdfViewer; +using Newtonsoft.Json; +using Microsoft.AspNetCore.Mvc.RazorPages; +using System.Reflection; +using System.Net; + +namespace PDFViewerSample.Pages +{ + [IgnoreAntiforgeryToken(Order = 1001)] + public class IndexModel : PageModel + { + + private readonly Microsoft.AspNetCore.Hosting.IHostingEnvironment _hostingEnvironment; + private IMemoryCache _cache; + + public IndexModel(Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment, IMemoryCache cache) + { + _hostingEnvironment = hostingEnvironment; + _cache = cache; + } + + public IActionResult OnPostLoad([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + MemoryStream stream = new MemoryStream(); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = new object(); + if (jsonObject != null && jsonObject.ContainsKey("document")) + { + if (bool.Parse(jsonObject["isFileName"])) + { + string documentPath = GetDocumentPath(jsonObject["document"]); + if (!string.IsNullOrEmpty(documentPath)) + { + byte[] bytes = System.IO.File.ReadAllBytes(documentPath); + stream = new MemoryStream(bytes); + } + else + { + string fileName = jsonObject["document"].Split(new string[] { "://" }, StringSplitOptions.None)[0]; + if (fileName == "http" || fileName == "https") + { + WebClient WebClient = new WebClient(); + byte[] pdfDoc = WebClient.DownloadData(jsonObject["document"]); + stream = new MemoryStream(pdfDoc); + } + else + return this.Content(jsonObject["document"] + " is not found"); + } + } + else + { + byte[] bytes = Convert.FromBase64String(jsonObject["document"]); + stream = new MemoryStream(bytes); + } + } + jsonResult = pdfviewer.Load(stream, jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + public Dictionary JsonConverterstring(jsonObjects results) + { + Dictionary resultObjects = new Dictionary(); + resultObjects = results.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public) + .ToDictionary(prop => prop.Name, prop => prop.GetValue(results, null)); + var emptyObjects = (from kv in resultObjects + where kv.Value != null + select kv).ToDictionary(kv => kv.Key, kv => kv.Value); + Dictionary jsonResult = emptyObjects.ToDictionary(k => k.Key, k => k.Value.ToString()); + return jsonResult; + } + + //Post action for processing the PDF documents. + public IActionResult OnPostRenderPdfPages([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = pdfviewer.GetPage(jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + //Post action for unloading and disposing the PDF document resources + public IActionResult OnPostUnload([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + pdfviewer.ClearCache(jsonObject); + return this.Content("Document cache is cleared"); + } + + //Post action for rendering the ThumbnailImages + public IActionResult OnPostRenderThumbnailImages([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object result = pdfviewer.GetThumbnailImages(jsonObject); + return Content(JsonConvert.SerializeObject(result)); + } + + //Post action for processing the bookmarks from the PDF documents + public IActionResult OnPostBookmarks([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = pdfviewer.GetBookmarks(jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + //Post action for rendering the annotation comments + public IActionResult OnPostRenderAnnotationComments([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = pdfviewer.GetAnnotationComments(jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + //Post action for exporting the annotations + public IActionResult OnPostExportAnnotations([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + string jsonResult = pdfviewer.ExportAnnotation(jsonObject); + return Content(jsonResult); + } + + //Post action for importing the annotations + public IActionResult OnPostImportAnnotations([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + string jsonResult = string.Empty; + object JsonResult; + if (jsonObject != null && jsonObject.ContainsKey("fileName")) + { + string documentPath = GetDocumentPath(jsonObject["fileName"]); + if (!string.IsNullOrEmpty(documentPath)) + { + jsonResult = System.IO.File.ReadAllText(documentPath); + } + else + { + return this.Content(jsonObject["document"] + " is not found"); + } + } + else + { + string extension = Path.GetExtension(jsonObject["importedData"]); + if (extension != ".xfdf") + { + JsonResult = pdfviewer.ImportAnnotation(jsonObject); + return Content(JsonConvert.SerializeObject(JsonResult)); + } + else + { + string documentPath = GetDocumentPath(jsonObject["importedData"]); + if (!string.IsNullOrEmpty(documentPath)) + { + byte[] bytes = System.IO.File.ReadAllBytes(documentPath); + jsonObject["importedData"] = Convert.ToBase64String(bytes); + JsonResult = pdfviewer.ImportAnnotation(jsonObject); + return Content(JsonConvert.SerializeObject(JsonResult)); + } + else + { + return this.Content(jsonObject["document"] + " is not found"); + } + } + } + return Content(jsonResult); + } + + //Post action for downloading the PDF documents + public IActionResult OnPostDownload([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject); + return Content(documentBase); + } + + //Post action for printing the PDF documents + public IActionResult OnPostPrintImages([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object pageImage = pdfviewer.GetPrintImage(jsonObject); + return Content(JsonConvert.SerializeObject(pageImage)); + } + + //Gets the path of the PDF document + private string GetDocumentPath(string document) + { + string documentPath = string.Empty; + if (!System.IO.File.Exists(document)) + { + string basePath = _hostingEnvironment.WebRootPath; + string dataPath = string.Empty; + dataPath = basePath + "/"; + if (System.IO.File.Exists(dataPath + (document))) + documentPath = dataPath + document; + } + else + { + documentPath = document; + } + return documentPath; + } + } + + public class jsonObjects + { + public string document { get; set; } + public string password { get; set; } + public string zoomFactor { get; set; } + public string isFileName { get; set; } + public string xCoordinate { get; set; } + public string yCoordinate { get; set; } + public string pageNumber { get; set; } + public string documentId { get; set; } + public string hashId { get; set; } + public string sizeX { get; set; } + public string sizeY { get; set; } + public string startPage { get; set; } + public string endPage { get; set; } + public string stampAnnotations { get; set; } + public string textMarkupAnnotations { get; set; } + public string stickyNotesAnnotation { get; set; } + public string shapeAnnotations { get; set; } + public string measureShapeAnnotations { get; set; } + public string action { get; set; } + public string pageStartIndex { get; set; } + public string pageEndIndex { get; set; } + public string fileName { get; set; } + public string elementId { get; set; } + public string pdfAnnotation { get; set; } + public string importPageList { get; set; } + public string uniqueId { get; set; } + public string data { get; set; } + public string viewPortWidth { get; set; } + public string viewPortHeight { get; set; } + public string tilecount { get; set; } + public bool isCompletePageSizeNotReceived { get; set; } + public string freeTextAnnotation { get; set; } + public string signatureData { get; set; } + public string fieldsData { get; set; } + public string formDesigner { get; set; } + public string inkSignatureData { get; set; } + public bool hideEmptyDigitalSignatureFields { get; set; } + public bool showDigitalSignatureAppearance { get; set; } + public bool digitalSignaturePresent { get; set; } + public string tileXCount { get; set; } + public string tileYCount { get; set; } + public string digitalSignaturePageList { get; set; } + public string annotationCollection { get; set; } + public string annotationsPageList { get; set; } + public string formFieldsPageList { get; set; } + public bool isAnnotationsExist { get; set; } + public bool isFormFieldAnnotationsExist { get; set; } + public string documentLiveCount { get; set; } + public string annotationDataFormat { get; set; } + public string importedData { get; set; } + } +} \ No newline at end of file diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Privacy.cshtml b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Privacy.cshtml new file mode 100644 index 0000000..46ba966 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Privacy.cshtml @@ -0,0 +1,8 @@ +@page +@model PrivacyModel +@{ + ViewData["Title"] = "Privacy Policy"; +} +

@ViewData["Title"]

+ +

Use this page to detail your site's privacy policy.

diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Privacy.cshtml.cs b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Privacy.cshtml.cs new file mode 100644 index 0000000..cd60641 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Privacy.cshtml.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace PDFViewerSample.Pages +{ + public class PrivacyModel : PageModel + { + private readonly ILogger _logger; + + public PrivacyModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + } + } + +} diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Shared/_Layout.cshtml b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Shared/_Layout.cshtml new file mode 100644 index 0000000..6e668f7 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Shared/_Layout.cshtml @@ -0,0 +1,30 @@ + + + + + + @ViewData["Title"] - PDFViewerSample + + + + + + + + + +
+
+ @RenderBody() +
+
+ + + + + + @await RenderSectionAsync("Scripts", required: false) + + + + \ No newline at end of file diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Shared/_Layout.cshtml.css b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Shared/_Layout.cshtml.css new file mode 100644 index 0000000..c187c02 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Shared/_Layout.cshtml.css @@ -0,0 +1,48 @@ +/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification +for details on configuring this project to bundle and minify static web assets. */ + +a.navbar-brand { + white-space: normal; + text-align: center; + word-break: break-all; +} + +a { + color: #0077cc; +} + +.btn-primary { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; +} + +.nav-pills .nav-link.active, .nav-pills .show > .nav-link { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; +} + +.border-top { + border-top: 1px solid #e5e5e5; +} +.border-bottom { + border-bottom: 1px solid #e5e5e5; +} + +.box-shadow { + box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); +} + +button.accept-policy { + font-size: 1rem; + line-height: inherit; +} + +.footer { + position: absolute; + bottom: 0; + width: 100%; + white-space: nowrap; + line-height: 60px; +} diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Shared/_ValidationScriptsPartial.cshtml b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Shared/_ValidationScriptsPartial.cshtml new file mode 100644 index 0000000..5a16d80 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/Shared/_ValidationScriptsPartial.cshtml @@ -0,0 +1,2 @@ + + diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/_ViewImports.cshtml b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/_ViewImports.cshtml new file mode 100644 index 0000000..51b8015 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/_ViewImports.cshtml @@ -0,0 +1,4 @@ +@using PDFViewerSample +@namespace PDFViewerSample.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@addTagHelper *, Syncfusion.EJ2 \ No newline at end of file diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/_ViewStart.cshtml b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/_ViewStart.cshtml new file mode 100644 index 0000000..a5f1004 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Pages/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +} diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Program.cs b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Program.cs new file mode 100644 index 0000000..bc275e4 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddRazorPages(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (!app.Environment.IsDevelopment()) +{ + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} + +app.UseHttpsRedirection(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthorization(); + +app.MapRazorPages(); + +app.Run(); diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Properties/launchSettings.json b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Properties/launchSettings.json new file mode 100644 index 0000000..dbe83ce --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:12333", + "sslPort": 44366 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5059", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7232;http://localhost:5059", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/appsettings.Development.json b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/appsettings.Development.json new file mode 100644 index 0000000..770d3e9 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "DetailedErrors": true, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/appsettings.json b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/How to/Extract Text option/ExtractTextOption/ExtractTextOption/wwwroot/favicon.ico b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/wwwroot/favicon.ico new file mode 100644 index 0000000..63e859b Binary files /dev/null and b/How to/Extract Text option/ExtractTextOption/ExtractTextOption/wwwroot/favicon.ico differ diff --git a/How to/Extract Text/ExtractText/ExtractText.sln b/How to/Extract Text/ExtractText/ExtractText.sln new file mode 100644 index 0000000..ea7e4f4 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34607.79 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtractText", "ExtractText\ExtractText.csproj", "{4E49C222-33F9-4DD3-96D1-EAA16A2A3D32}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4E49C222-33F9-4DD3-96D1-EAA16A2A3D32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4E49C222-33F9-4DD3-96D1-EAA16A2A3D32}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4E49C222-33F9-4DD3-96D1-EAA16A2A3D32}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4E49C222-33F9-4DD3-96D1-EAA16A2A3D32}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {31245B35-82FC-4C3B-A888-4730D0AD8EE0} + EndGlobalSection +EndGlobal diff --git a/How to/Extract Text/ExtractText/ExtractText/ExtractText.csproj b/How to/Extract Text/ExtractText/ExtractText/ExtractText.csproj new file mode 100644 index 0000000..bd93b42 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/ExtractText.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/How to/Extract Text/ExtractText/ExtractText/ExtractText.csproj.user b/How to/Extract Text/ExtractText/ExtractText/ExtractText.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/ExtractText.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/How to/Extract Text/ExtractText/ExtractText/Pages/Error.cshtml b/How to/Extract Text/ExtractText/ExtractText/Pages/Error.cshtml new file mode 100644 index 0000000..6f92b95 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/Pages/Error.cshtml @@ -0,0 +1,26 @@ +@page +@model ErrorModel +@{ + ViewData["Title"] = "Error"; +} + +

Error.

+

An error occurred while processing your request.

+ +@if (Model.ShowRequestId) +{ +

+ Request ID: @Model.RequestId +

+} + +

Development Mode

+

+ Swapping to the Development environment displays detailed information about the error that occurred. +

+

+ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +

diff --git a/How to/Extract Text/ExtractText/ExtractText/Pages/Error.cshtml.cs b/How to/Extract Text/ExtractText/ExtractText/Pages/Error.cshtml.cs new file mode 100644 index 0000000..c008cae --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/Pages/Error.cshtml.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using System.Diagnostics; + +namespace PDFViewerSample.Pages +{ + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [IgnoreAntiforgeryToken] + public class ErrorModel : PageModel + { + public string? RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + private readonly ILogger _logger; + + public ErrorModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; + } + } + +} diff --git a/How to/Extract Text/ExtractText/ExtractText/Pages/Index.cshtml b/How to/Extract Text/ExtractText/ExtractText/Pages/Index.cshtml new file mode 100644 index 0000000..a61a182 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/Pages/Index.cshtml @@ -0,0 +1,29 @@ +@page "{handler?}" +@model IndexModel +@{ + ViewData["Title"] = "Home page"; +} + +
+ + + + +
+ + \ No newline at end of file diff --git a/How to/Extract Text/ExtractText/ExtractText/Pages/Index.cshtml.cs b/How to/Extract Text/ExtractText/ExtractText/Pages/Index.cshtml.cs new file mode 100644 index 0000000..721e2f7 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/Pages/Index.cshtml.cs @@ -0,0 +1,266 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Caching.Memory; +using Syncfusion.EJ2.PdfViewer; +using Newtonsoft.Json; +using Microsoft.AspNetCore.Mvc.RazorPages; +using System.Reflection; +using System.Net; + +namespace PDFViewerSample.Pages +{ + [IgnoreAntiforgeryToken(Order = 1001)] + public class IndexModel : PageModel + { + + private readonly Microsoft.AspNetCore.Hosting.IHostingEnvironment _hostingEnvironment; + private IMemoryCache _cache; + + public IndexModel(Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment, IMemoryCache cache) + { + _hostingEnvironment = hostingEnvironment; + _cache = cache; + } + + public IActionResult OnPostLoad([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + MemoryStream stream = new MemoryStream(); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = new object(); + if (jsonObject != null && jsonObject.ContainsKey("document")) + { + if (bool.Parse(jsonObject["isFileName"])) + { + string documentPath = GetDocumentPath(jsonObject["document"]); + if (!string.IsNullOrEmpty(documentPath)) + { + byte[] bytes = System.IO.File.ReadAllBytes(documentPath); + stream = new MemoryStream(bytes); + } + else + { + string fileName = jsonObject["document"].Split(new string[] { "://" }, StringSplitOptions.None)[0]; + if (fileName == "http" || fileName == "https") + { + WebClient WebClient = new WebClient(); + byte[] pdfDoc = WebClient.DownloadData(jsonObject["document"]); + stream = new MemoryStream(pdfDoc); + } + else + return this.Content(jsonObject["document"] + " is not found"); + } + } + else + { + byte[] bytes = Convert.FromBase64String(jsonObject["document"]); + stream = new MemoryStream(bytes); + } + } + jsonResult = pdfviewer.Load(stream, jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + public Dictionary JsonConverterstring(jsonObjects results) + { + Dictionary resultObjects = new Dictionary(); + resultObjects = results.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public) + .ToDictionary(prop => prop.Name, prop => prop.GetValue(results, null)); + var emptyObjects = (from kv in resultObjects + where kv.Value != null + select kv).ToDictionary(kv => kv.Key, kv => kv.Value); + Dictionary jsonResult = emptyObjects.ToDictionary(k => k.Key, k => k.Value.ToString()); + return jsonResult; + } + + //Post action for processing the PDF documents. + public IActionResult OnPostRenderPdfPages([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = pdfviewer.GetPage(jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + //Post action for unloading and disposing the PDF document resources + public IActionResult OnPostUnload([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + pdfviewer.ClearCache(jsonObject); + return this.Content("Document cache is cleared"); + } + + //Post action for rendering the ThumbnailImages + public IActionResult OnPostRenderThumbnailImages([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object result = pdfviewer.GetThumbnailImages(jsonObject); + return Content(JsonConvert.SerializeObject(result)); + } + + //Post action for processing the bookmarks from the PDF documents + public IActionResult OnPostBookmarks([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = pdfviewer.GetBookmarks(jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + //Post action for rendering the annotation comments + public IActionResult OnPostRenderAnnotationComments([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = pdfviewer.GetAnnotationComments(jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + //Post action for exporting the annotations + public IActionResult OnPostExportAnnotations([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + string jsonResult = pdfviewer.ExportAnnotation(jsonObject); + return Content(jsonResult); + } + + //Post action for importing the annotations + public IActionResult OnPostImportAnnotations([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + string jsonResult = string.Empty; + object JsonResult; + if (jsonObject != null && jsonObject.ContainsKey("fileName")) + { + string documentPath = GetDocumentPath(jsonObject["fileName"]); + if (!string.IsNullOrEmpty(documentPath)) + { + jsonResult = System.IO.File.ReadAllText(documentPath); + } + else + { + return this.Content(jsonObject["document"] + " is not found"); + } + } + else + { + string extension = Path.GetExtension(jsonObject["importedData"]); + if (extension != ".xfdf") + { + JsonResult = pdfviewer.ImportAnnotation(jsonObject); + return Content(JsonConvert.SerializeObject(JsonResult)); + } + else + { + string documentPath = GetDocumentPath(jsonObject["importedData"]); + if (!string.IsNullOrEmpty(documentPath)) + { + byte[] bytes = System.IO.File.ReadAllBytes(documentPath); + jsonObject["importedData"] = Convert.ToBase64String(bytes); + JsonResult = pdfviewer.ImportAnnotation(jsonObject); + return Content(JsonConvert.SerializeObject(JsonResult)); + } + else + { + return this.Content(jsonObject["document"] + " is not found"); + } + } + } + return Content(jsonResult); + } + + //Post action for downloading the PDF documents + public IActionResult OnPostDownload([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject); + return Content(documentBase); + } + + //Post action for printing the PDF documents + public IActionResult OnPostPrintImages([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object pageImage = pdfviewer.GetPrintImage(jsonObject); + return Content(JsonConvert.SerializeObject(pageImage)); + } + + //Gets the path of the PDF document + private string GetDocumentPath(string document) + { + string documentPath = string.Empty; + if (!System.IO.File.Exists(document)) + { + string basePath = _hostingEnvironment.WebRootPath; + string dataPath = string.Empty; + dataPath = basePath + "/"; + if (System.IO.File.Exists(dataPath + (document))) + documentPath = dataPath + document; + } + else + { + documentPath = document; + } + return documentPath; + } + } + + public class jsonObjects + { + public string document { get; set; } + public string password { get; set; } + public string zoomFactor { get; set; } + public string isFileName { get; set; } + public string xCoordinate { get; set; } + public string yCoordinate { get; set; } + public string pageNumber { get; set; } + public string documentId { get; set; } + public string hashId { get; set; } + public string sizeX { get; set; } + public string sizeY { get; set; } + public string startPage { get; set; } + public string endPage { get; set; } + public string stampAnnotations { get; set; } + public string textMarkupAnnotations { get; set; } + public string stickyNotesAnnotation { get; set; } + public string shapeAnnotations { get; set; } + public string measureShapeAnnotations { get; set; } + public string action { get; set; } + public string pageStartIndex { get; set; } + public string pageEndIndex { get; set; } + public string fileName { get; set; } + public string elementId { get; set; } + public string pdfAnnotation { get; set; } + public string importPageList { get; set; } + public string uniqueId { get; set; } + public string data { get; set; } + public string viewPortWidth { get; set; } + public string viewPortHeight { get; set; } + public string tilecount { get; set; } + public bool isCompletePageSizeNotReceived { get; set; } + public string freeTextAnnotation { get; set; } + public string signatureData { get; set; } + public string fieldsData { get; set; } + public string formDesigner { get; set; } + public string inkSignatureData { get; set; } + public bool hideEmptyDigitalSignatureFields { get; set; } + public bool showDigitalSignatureAppearance { get; set; } + public bool digitalSignaturePresent { get; set; } + public string tileXCount { get; set; } + public string tileYCount { get; set; } + public string digitalSignaturePageList { get; set; } + public string annotationCollection { get; set; } + public string annotationsPageList { get; set; } + public string formFieldsPageList { get; set; } + public bool isAnnotationsExist { get; set; } + public bool isFormFieldAnnotationsExist { get; set; } + public string documentLiveCount { get; set; } + public string annotationDataFormat { get; set; } + public string importedData { get; set; } + } +} \ No newline at end of file diff --git a/How to/Extract Text/ExtractText/ExtractText/Pages/Privacy.cshtml b/How to/Extract Text/ExtractText/ExtractText/Pages/Privacy.cshtml new file mode 100644 index 0000000..46ba966 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/Pages/Privacy.cshtml @@ -0,0 +1,8 @@ +@page +@model PrivacyModel +@{ + ViewData["Title"] = "Privacy Policy"; +} +

@ViewData["Title"]

+ +

Use this page to detail your site's privacy policy.

diff --git a/How to/Extract Text/ExtractText/ExtractText/Pages/Privacy.cshtml.cs b/How to/Extract Text/ExtractText/ExtractText/Pages/Privacy.cshtml.cs new file mode 100644 index 0000000..cd60641 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/Pages/Privacy.cshtml.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace PDFViewerSample.Pages +{ + public class PrivacyModel : PageModel + { + private readonly ILogger _logger; + + public PrivacyModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + } + } + +} diff --git a/How to/Extract Text/ExtractText/ExtractText/Pages/Shared/_Layout.cshtml b/How to/Extract Text/ExtractText/ExtractText/Pages/Shared/_Layout.cshtml new file mode 100644 index 0000000..f1ce8ac --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/Pages/Shared/_Layout.cshtml @@ -0,0 +1,30 @@ + + + + + + @ViewData["Title"] - PDFViewerSample + + + + + + + + + +
+
+ @RenderBody() +
+
+ + + + + + @await RenderSectionAsync("Scripts", required: false) + + + + \ No newline at end of file diff --git a/How to/Extract Text/ExtractText/ExtractText/Pages/Shared/_Layout.cshtml.css b/How to/Extract Text/ExtractText/ExtractText/Pages/Shared/_Layout.cshtml.css new file mode 100644 index 0000000..c187c02 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/Pages/Shared/_Layout.cshtml.css @@ -0,0 +1,48 @@ +/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification +for details on configuring this project to bundle and minify static web assets. */ + +a.navbar-brand { + white-space: normal; + text-align: center; + word-break: break-all; +} + +a { + color: #0077cc; +} + +.btn-primary { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; +} + +.nav-pills .nav-link.active, .nav-pills .show > .nav-link { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; +} + +.border-top { + border-top: 1px solid #e5e5e5; +} +.border-bottom { + border-bottom: 1px solid #e5e5e5; +} + +.box-shadow { + box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); +} + +button.accept-policy { + font-size: 1rem; + line-height: inherit; +} + +.footer { + position: absolute; + bottom: 0; + width: 100%; + white-space: nowrap; + line-height: 60px; +} diff --git a/How to/Extract Text/ExtractText/ExtractText/Pages/Shared/_ValidationScriptsPartial.cshtml b/How to/Extract Text/ExtractText/ExtractText/Pages/Shared/_ValidationScriptsPartial.cshtml new file mode 100644 index 0000000..5a16d80 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/Pages/Shared/_ValidationScriptsPartial.cshtml @@ -0,0 +1,2 @@ + + diff --git a/How to/Extract Text/ExtractText/ExtractText/Pages/_ViewImports.cshtml b/How to/Extract Text/ExtractText/ExtractText/Pages/_ViewImports.cshtml new file mode 100644 index 0000000..51b8015 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/Pages/_ViewImports.cshtml @@ -0,0 +1,4 @@ +@using PDFViewerSample +@namespace PDFViewerSample.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@addTagHelper *, Syncfusion.EJ2 \ No newline at end of file diff --git a/How to/Extract Text/ExtractText/ExtractText/Pages/_ViewStart.cshtml b/How to/Extract Text/ExtractText/ExtractText/Pages/_ViewStart.cshtml new file mode 100644 index 0000000..a5f1004 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/Pages/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +} diff --git a/How to/Extract Text/ExtractText/ExtractText/Program.cs b/How to/Extract Text/ExtractText/ExtractText/Program.cs new file mode 100644 index 0000000..bc275e4 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddRazorPages(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (!app.Environment.IsDevelopment()) +{ + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} + +app.UseHttpsRedirection(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthorization(); + +app.MapRazorPages(); + +app.Run(); diff --git a/How to/Extract Text/ExtractText/ExtractText/Properties/launchSettings.json b/How to/Extract Text/ExtractText/ExtractText/Properties/launchSettings.json new file mode 100644 index 0000000..dbe83ce --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:12333", + "sslPort": 44366 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5059", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7232;http://localhost:5059", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/How to/Extract Text/ExtractText/ExtractText/appsettings.Development.json b/How to/Extract Text/ExtractText/ExtractText/appsettings.Development.json new file mode 100644 index 0000000..770d3e9 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "DetailedErrors": true, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/How to/Extract Text/ExtractText/ExtractText/appsettings.json b/How to/Extract Text/ExtractText/ExtractText/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/How to/Extract Text/ExtractText/ExtractText/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/How to/Extract Text/ExtractText/ExtractText/wwwroot/favicon.ico b/How to/Extract Text/ExtractText/ExtractText/wwwroot/favicon.ico new file mode 100644 index 0000000..63e859b Binary files /dev/null and b/How to/Extract Text/ExtractText/ExtractText/wwwroot/favicon.ico differ diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync.sln b/How to/Find Text Async/FindTextAsync/FindTextAsync.sln new file mode 100644 index 0000000..06c17e9 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34607.79 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FindTextAsync", "FindTextAsync\FindTextAsync.csproj", "{21CCFB52-5EC5-4193-B476-E458596C0C2E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {21CCFB52-5EC5-4193-B476-E458596C0C2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {21CCFB52-5EC5-4193-B476-E458596C0C2E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {21CCFB52-5EC5-4193-B476-E458596C0C2E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {21CCFB52-5EC5-4193-B476-E458596C0C2E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {31245B35-82FC-4C3B-A888-4730D0AD8EE0} + EndGlobalSection +EndGlobal diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/FindTextAsync.csproj b/How to/Find Text Async/FindTextAsync/FindTextAsync/FindTextAsync.csproj new file mode 100644 index 0000000..bd93b42 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/FindTextAsync.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/FindTextAsync.csproj.user b/How to/Find Text Async/FindTextAsync/FindTextAsync/FindTextAsync.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/FindTextAsync.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Error.cshtml b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Error.cshtml new file mode 100644 index 0000000..6f92b95 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Error.cshtml @@ -0,0 +1,26 @@ +@page +@model ErrorModel +@{ + ViewData["Title"] = "Error"; +} + +

Error.

+

An error occurred while processing your request.

+ +@if (Model.ShowRequestId) +{ +

+ Request ID: @Model.RequestId +

+} + +

Development Mode

+

+ Swapping to the Development environment displays detailed information about the error that occurred. +

+

+ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +

diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Error.cshtml.cs b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Error.cshtml.cs new file mode 100644 index 0000000..c008cae --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Error.cshtml.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using System.Diagnostics; + +namespace PDFViewerSample.Pages +{ + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [IgnoreAntiforgeryToken] + public class ErrorModel : PageModel + { + public string? RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + private readonly ILogger _logger; + + public ErrorModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; + } + } + +} diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Index.cshtml b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Index.cshtml new file mode 100644 index 0000000..eb2fff6 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Index.cshtml @@ -0,0 +1,30 @@ +@page "{handler?}" +@model IndexModel +@{ + ViewData["Title"] = "Home page"; +} + +
+ + + + +
+ + \ No newline at end of file diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Index.cshtml.cs b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Index.cshtml.cs new file mode 100644 index 0000000..721e2f7 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Index.cshtml.cs @@ -0,0 +1,266 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Caching.Memory; +using Syncfusion.EJ2.PdfViewer; +using Newtonsoft.Json; +using Microsoft.AspNetCore.Mvc.RazorPages; +using System.Reflection; +using System.Net; + +namespace PDFViewerSample.Pages +{ + [IgnoreAntiforgeryToken(Order = 1001)] + public class IndexModel : PageModel + { + + private readonly Microsoft.AspNetCore.Hosting.IHostingEnvironment _hostingEnvironment; + private IMemoryCache _cache; + + public IndexModel(Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment, IMemoryCache cache) + { + _hostingEnvironment = hostingEnvironment; + _cache = cache; + } + + public IActionResult OnPostLoad([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + MemoryStream stream = new MemoryStream(); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = new object(); + if (jsonObject != null && jsonObject.ContainsKey("document")) + { + if (bool.Parse(jsonObject["isFileName"])) + { + string documentPath = GetDocumentPath(jsonObject["document"]); + if (!string.IsNullOrEmpty(documentPath)) + { + byte[] bytes = System.IO.File.ReadAllBytes(documentPath); + stream = new MemoryStream(bytes); + } + else + { + string fileName = jsonObject["document"].Split(new string[] { "://" }, StringSplitOptions.None)[0]; + if (fileName == "http" || fileName == "https") + { + WebClient WebClient = new WebClient(); + byte[] pdfDoc = WebClient.DownloadData(jsonObject["document"]); + stream = new MemoryStream(pdfDoc); + } + else + return this.Content(jsonObject["document"] + " is not found"); + } + } + else + { + byte[] bytes = Convert.FromBase64String(jsonObject["document"]); + stream = new MemoryStream(bytes); + } + } + jsonResult = pdfviewer.Load(stream, jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + public Dictionary JsonConverterstring(jsonObjects results) + { + Dictionary resultObjects = new Dictionary(); + resultObjects = results.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public) + .ToDictionary(prop => prop.Name, prop => prop.GetValue(results, null)); + var emptyObjects = (from kv in resultObjects + where kv.Value != null + select kv).ToDictionary(kv => kv.Key, kv => kv.Value); + Dictionary jsonResult = emptyObjects.ToDictionary(k => k.Key, k => k.Value.ToString()); + return jsonResult; + } + + //Post action for processing the PDF documents. + public IActionResult OnPostRenderPdfPages([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = pdfviewer.GetPage(jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + //Post action for unloading and disposing the PDF document resources + public IActionResult OnPostUnload([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + pdfviewer.ClearCache(jsonObject); + return this.Content("Document cache is cleared"); + } + + //Post action for rendering the ThumbnailImages + public IActionResult OnPostRenderThumbnailImages([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object result = pdfviewer.GetThumbnailImages(jsonObject); + return Content(JsonConvert.SerializeObject(result)); + } + + //Post action for processing the bookmarks from the PDF documents + public IActionResult OnPostBookmarks([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = pdfviewer.GetBookmarks(jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + //Post action for rendering the annotation comments + public IActionResult OnPostRenderAnnotationComments([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object jsonResult = pdfviewer.GetAnnotationComments(jsonObject); + return Content(JsonConvert.SerializeObject(jsonResult)); + } + + //Post action for exporting the annotations + public IActionResult OnPostExportAnnotations([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + string jsonResult = pdfviewer.ExportAnnotation(jsonObject); + return Content(jsonResult); + } + + //Post action for importing the annotations + public IActionResult OnPostImportAnnotations([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + string jsonResult = string.Empty; + object JsonResult; + if (jsonObject != null && jsonObject.ContainsKey("fileName")) + { + string documentPath = GetDocumentPath(jsonObject["fileName"]); + if (!string.IsNullOrEmpty(documentPath)) + { + jsonResult = System.IO.File.ReadAllText(documentPath); + } + else + { + return this.Content(jsonObject["document"] + " is not found"); + } + } + else + { + string extension = Path.GetExtension(jsonObject["importedData"]); + if (extension != ".xfdf") + { + JsonResult = pdfviewer.ImportAnnotation(jsonObject); + return Content(JsonConvert.SerializeObject(JsonResult)); + } + else + { + string documentPath = GetDocumentPath(jsonObject["importedData"]); + if (!string.IsNullOrEmpty(documentPath)) + { + byte[] bytes = System.IO.File.ReadAllBytes(documentPath); + jsonObject["importedData"] = Convert.ToBase64String(bytes); + JsonResult = pdfviewer.ImportAnnotation(jsonObject); + return Content(JsonConvert.SerializeObject(JsonResult)); + } + else + { + return this.Content(jsonObject["document"] + " is not found"); + } + } + } + return Content(jsonResult); + } + + //Post action for downloading the PDF documents + public IActionResult OnPostDownload([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject); + return Content(documentBase); + } + + //Post action for printing the PDF documents + public IActionResult OnPostPrintImages([FromBody] jsonObjects responseData) + { + PdfRenderer pdfviewer = new PdfRenderer(_cache); + var jsonObject = JsonConverterstring(responseData); + object pageImage = pdfviewer.GetPrintImage(jsonObject); + return Content(JsonConvert.SerializeObject(pageImage)); + } + + //Gets the path of the PDF document + private string GetDocumentPath(string document) + { + string documentPath = string.Empty; + if (!System.IO.File.Exists(document)) + { + string basePath = _hostingEnvironment.WebRootPath; + string dataPath = string.Empty; + dataPath = basePath + "/"; + if (System.IO.File.Exists(dataPath + (document))) + documentPath = dataPath + document; + } + else + { + documentPath = document; + } + return documentPath; + } + } + + public class jsonObjects + { + public string document { get; set; } + public string password { get; set; } + public string zoomFactor { get; set; } + public string isFileName { get; set; } + public string xCoordinate { get; set; } + public string yCoordinate { get; set; } + public string pageNumber { get; set; } + public string documentId { get; set; } + public string hashId { get; set; } + public string sizeX { get; set; } + public string sizeY { get; set; } + public string startPage { get; set; } + public string endPage { get; set; } + public string stampAnnotations { get; set; } + public string textMarkupAnnotations { get; set; } + public string stickyNotesAnnotation { get; set; } + public string shapeAnnotations { get; set; } + public string measureShapeAnnotations { get; set; } + public string action { get; set; } + public string pageStartIndex { get; set; } + public string pageEndIndex { get; set; } + public string fileName { get; set; } + public string elementId { get; set; } + public string pdfAnnotation { get; set; } + public string importPageList { get; set; } + public string uniqueId { get; set; } + public string data { get; set; } + public string viewPortWidth { get; set; } + public string viewPortHeight { get; set; } + public string tilecount { get; set; } + public bool isCompletePageSizeNotReceived { get; set; } + public string freeTextAnnotation { get; set; } + public string signatureData { get; set; } + public string fieldsData { get; set; } + public string formDesigner { get; set; } + public string inkSignatureData { get; set; } + public bool hideEmptyDigitalSignatureFields { get; set; } + public bool showDigitalSignatureAppearance { get; set; } + public bool digitalSignaturePresent { get; set; } + public string tileXCount { get; set; } + public string tileYCount { get; set; } + public string digitalSignaturePageList { get; set; } + public string annotationCollection { get; set; } + public string annotationsPageList { get; set; } + public string formFieldsPageList { get; set; } + public bool isAnnotationsExist { get; set; } + public bool isFormFieldAnnotationsExist { get; set; } + public string documentLiveCount { get; set; } + public string annotationDataFormat { get; set; } + public string importedData { get; set; } + } +} \ No newline at end of file diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Privacy.cshtml b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Privacy.cshtml new file mode 100644 index 0000000..46ba966 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Privacy.cshtml @@ -0,0 +1,8 @@ +@page +@model PrivacyModel +@{ + ViewData["Title"] = "Privacy Policy"; +} +

@ViewData["Title"]

+ +

Use this page to detail your site's privacy policy.

diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Privacy.cshtml.cs b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Privacy.cshtml.cs new file mode 100644 index 0000000..cd60641 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Privacy.cshtml.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace PDFViewerSample.Pages +{ + public class PrivacyModel : PageModel + { + private readonly ILogger _logger; + + public PrivacyModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + } + } + +} diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Shared/_Layout.cshtml b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Shared/_Layout.cshtml new file mode 100644 index 0000000..f1ce8ac --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Shared/_Layout.cshtml @@ -0,0 +1,30 @@ + + + + + + @ViewData["Title"] - PDFViewerSample + + + + + + + + + +
+
+ @RenderBody() +
+
+ + + + + + @await RenderSectionAsync("Scripts", required: false) + + + + \ No newline at end of file diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Shared/_Layout.cshtml.css b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Shared/_Layout.cshtml.css new file mode 100644 index 0000000..c187c02 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Shared/_Layout.cshtml.css @@ -0,0 +1,48 @@ +/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification +for details on configuring this project to bundle and minify static web assets. */ + +a.navbar-brand { + white-space: normal; + text-align: center; + word-break: break-all; +} + +a { + color: #0077cc; +} + +.btn-primary { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; +} + +.nav-pills .nav-link.active, .nav-pills .show > .nav-link { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; +} + +.border-top { + border-top: 1px solid #e5e5e5; +} +.border-bottom { + border-bottom: 1px solid #e5e5e5; +} + +.box-shadow { + box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); +} + +button.accept-policy { + font-size: 1rem; + line-height: inherit; +} + +.footer { + position: absolute; + bottom: 0; + width: 100%; + white-space: nowrap; + line-height: 60px; +} diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Shared/_ValidationScriptsPartial.cshtml b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Shared/_ValidationScriptsPartial.cshtml new file mode 100644 index 0000000..5a16d80 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/Shared/_ValidationScriptsPartial.cshtml @@ -0,0 +1,2 @@ + + diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/_ViewImports.cshtml b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/_ViewImports.cshtml new file mode 100644 index 0000000..51b8015 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/_ViewImports.cshtml @@ -0,0 +1,4 @@ +@using PDFViewerSample +@namespace PDFViewerSample.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@addTagHelper *, Syncfusion.EJ2 \ No newline at end of file diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/_ViewStart.cshtml b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/_ViewStart.cshtml new file mode 100644 index 0000000..a5f1004 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/Pages/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +} diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/Program.cs b/How to/Find Text Async/FindTextAsync/FindTextAsync/Program.cs new file mode 100644 index 0000000..bc275e4 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddRazorPages(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (!app.Environment.IsDevelopment()) +{ + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} + +app.UseHttpsRedirection(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthorization(); + +app.MapRazorPages(); + +app.Run(); diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/Properties/launchSettings.json b/How to/Find Text Async/FindTextAsync/FindTextAsync/Properties/launchSettings.json new file mode 100644 index 0000000..dbe83ce --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:12333", + "sslPort": 44366 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5059", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7232;http://localhost:5059", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/appsettings.Development.json b/How to/Find Text Async/FindTextAsync/FindTextAsync/appsettings.Development.json new file mode 100644 index 0000000..770d3e9 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "DetailedErrors": true, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/appsettings.json b/How to/Find Text Async/FindTextAsync/FindTextAsync/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/How to/Find Text Async/FindTextAsync/FindTextAsync/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/How to/Find Text Async/FindTextAsync/FindTextAsync/wwwroot/favicon.ico b/How to/Find Text Async/FindTextAsync/FindTextAsync/wwwroot/favicon.ico new file mode 100644 index 0000000..63e859b Binary files /dev/null and b/How to/Find Text Async/FindTextAsync/FindTextAsync/wwwroot/favicon.ico differ