-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from SyncfusionExamples/883856-zoom
883856: Sample for how to Restrict Zoom Percentage on Mobile Devices
- Loading branch information
Showing
21 changed files
with
1,022 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
How to/Restrict Zoom Percentage on Mobile Devices/PDFViewerSample/PDFViewerSample.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}") = "PDFViewerSample", "PDFViewerSample\PDFViewerSample.csproj", "{A9DA02D7-13D9-4B59-9F79-746FFB7523C4}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A9DA02D7-13D9-4B59-9F79-746FFB7523C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A9DA02D7-13D9-4B59-9F79-746FFB7523C4}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A9DA02D7-13D9-4B59-9F79-746FFB7523C4}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A9DA02D7-13D9-4B59-9F79-746FFB7523C4}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {98E4A9F1-6F9D-4613-AC9F-C6A3BB511F7D} | ||
EndGlobalSection | ||
EndGlobal |
30 changes: 30 additions & 0 deletions
30
...om Percentage on Mobile Devices/PDFViewerSample/PDFViewerSample/App_Start/BundleConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Web; | ||
using System.Web.Optimization; | ||
|
||
namespace PDFViewerSample | ||
{ | ||
public class BundleConfig | ||
{ | ||
// For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862 | ||
public static void RegisterBundles(BundleCollection bundles) | ||
{ | ||
bundles.Add(new ScriptBundle("~/bundles/jquery").Include( | ||
"~/Scripts/jquery-{version}.js")); | ||
|
||
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( | ||
"~/Scripts/jquery.validate*")); | ||
|
||
// Use the development version of Modernizr to develop with and learn from. Then, when you're | ||
// ready for production, use the build tool at https://modernizr.com to pick only the tests you need. | ||
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( | ||
"~/Scripts/modernizr-*")); | ||
|
||
bundles.Add(new Bundle("~/bundles/bootstrap").Include( | ||
"~/Scripts/bootstrap.js")); | ||
|
||
bundles.Add(new StyleBundle("~/Content/css").Include( | ||
"~/Content/bootstrap.css", | ||
"~/Content/site.css")); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...om Percentage on Mobile Devices/PDFViewerSample/PDFViewerSample/App_Start/FilterConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Web; | ||
using System.Web.Mvc; | ||
|
||
namespace PDFViewerSample | ||
{ | ||
public class FilterConfig | ||
{ | ||
public static void RegisterGlobalFilters(GlobalFilterCollection filters) | ||
{ | ||
filters.Add(new HandleErrorAttribute()); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...oom Percentage on Mobile Devices/PDFViewerSample/PDFViewerSample/App_Start/RouteConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.Mvc; | ||
using System.Web.Routing; | ||
|
||
namespace PDFViewerSample | ||
{ | ||
public class RouteConfig | ||
{ | ||
public static void RegisterRoutes(RouteCollection routes) | ||
{ | ||
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); | ||
|
||
routes.MapRoute( | ||
name: "Default", | ||
url: "{controller}/{action}/{id}", | ||
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } | ||
); | ||
} | ||
} | ||
} |
264 changes: 264 additions & 0 deletions
264
...ercentage on Mobile Devices/PDFViewerSample/PDFViewerSample/Controllers/HomeController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,264 @@ | ||
using Newtonsoft.Json; | ||
using Syncfusion.EJ2.PdfViewer; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Reflection; | ||
using System.Web; | ||
using System.Web.Mvc; | ||
|
||
namespace GettingStartedMVC.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
[System.Web.Mvc.HttpPost] | ||
public ActionResult Load(jsonObjects jsonObject) | ||
{ | ||
PdfRenderer pdfviewer = new PdfRenderer(); | ||
MemoryStream stream = new MemoryStream(); | ||
var jsonData = JsonConverter(jsonObject); | ||
object jsonResult = new object(); | ||
if (jsonObject != null && jsonData.ContainsKey("document")) | ||
{ | ||
if (bool.Parse(jsonData["isFileName"])) | ||
{ | ||
string documentPath = GetDocumentPath(jsonData["document"]); | ||
|
||
if (!string.IsNullOrEmpty(documentPath)) | ||
{ | ||
byte[] bytes = System.IO.File.ReadAllBytes(documentPath); | ||
stream = new MemoryStream(bytes); | ||
} | ||
else | ||
{ | ||
string fileName = jsonData["document"].Split(new string[] { "://" }, StringSplitOptions.None)[0]; | ||
if (fileName == "http" || fileName == "https") | ||
{ | ||
var WebClient = new WebClient(); | ||
byte[] pdfDoc = WebClient.DownloadData(jsonData["document"]); | ||
stream = new MemoryStream(pdfDoc); | ||
} | ||
else | ||
{ | ||
return this.Content(jsonData["document"] + " is not found"); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
byte[] bytes = Convert.FromBase64String(jsonData["document"]); | ||
stream = new MemoryStream(bytes); | ||
|
||
} | ||
} | ||
jsonResult = pdfviewer.Load(stream, jsonData); | ||
return Content(JsonConvert.SerializeObject(jsonResult)); | ||
} | ||
|
||
public Dictionary<string, string> JsonConverter(jsonObjects results) | ||
{ | ||
Dictionary<string, object> resultObjects = new Dictionary<string, object>(); | ||
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<string, string> jsonResult = emptyObjects.ToDictionary(k => k.Key, k => k.Value.ToString()); | ||
return jsonResult; | ||
} | ||
|
||
[System.Web.Mvc.HttpPost] | ||
public ActionResult ExportAnnotations(jsonObjects jsonObject) | ||
{ | ||
PdfRenderer pdfviewer = new PdfRenderer(); | ||
var jsonData = JsonConverter(jsonObject); | ||
string jsonResult = pdfviewer.ExportAnnotation(jsonData); | ||
return Content((jsonResult)); | ||
} | ||
|
||
[System.Web.Mvc.HttpPost] | ||
public ActionResult ImportAnnotations(jsonObjects jsonObject) | ||
{ | ||
PdfRenderer pdfviewer = new PdfRenderer(); | ||
string jsonResult = string.Empty; | ||
var jsonData = JsonConverter(jsonObject); | ||
if (jsonObject != null && jsonData.ContainsKey("fileName")) | ||
{ | ||
string documentPath = GetDocumentPath(jsonData["fileName"]); | ||
if (!string.IsNullOrEmpty(documentPath)) | ||
{ | ||
jsonResult = System.IO.File.ReadAllText(documentPath); | ||
} | ||
else | ||
{ | ||
return this.Content(jsonData["document"] + " is not found"); | ||
} | ||
} | ||
return Content(JsonConvert.SerializeObject(jsonResult)); | ||
} | ||
|
||
[System.Web.Mvc.HttpPost] | ||
public ActionResult ImportFormFields(jsonObjects jsonObject) | ||
{ | ||
PdfRenderer pdfviewer = new PdfRenderer(); | ||
var jsonData = JsonConverter(jsonObject); | ||
object jsonResult = pdfviewer.ImportFormFields(jsonData); | ||
return Content(JsonConvert.SerializeObject(jsonResult)); | ||
} | ||
|
||
[System.Web.Mvc.HttpPost] | ||
public ActionResult ExportFormFields(jsonObjects jsonObject) | ||
{ | ||
PdfRenderer pdfviewer = new PdfRenderer(); | ||
var jsonData = JsonConverter(jsonObject); | ||
string jsonResult = pdfviewer.ExportFormFields(jsonData); | ||
return Content(jsonResult); | ||
} | ||
|
||
[System.Web.Mvc.HttpPost] | ||
public ActionResult RenderPdfPages(jsonObjects jsonObject) | ||
{ | ||
PdfRenderer pdfviewer = new PdfRenderer(); | ||
var jsonData = JsonConverter(jsonObject); | ||
object jsonResult = pdfviewer.GetPage(jsonData); | ||
return Content(JsonConvert.SerializeObject(jsonResult)); | ||
} | ||
|
||
[System.Web.Mvc.HttpPost] | ||
public ActionResult Unload(jsonObjects jsonObject) | ||
{ | ||
PdfRenderer pdfviewer = new PdfRenderer(); | ||
var jsonData = JsonConverter(jsonObject); | ||
pdfviewer.ClearCache(jsonData); | ||
return this.Content("Document cache is cleared"); | ||
} | ||
|
||
[System.Web.Mvc.HttpPost] | ||
public ActionResult RenderThumbnailImages(jsonObjects jsonObject) | ||
{ | ||
PdfRenderer pdfviewer = new PdfRenderer(); | ||
var jsonData = JsonConverter(jsonObject); | ||
object result = pdfviewer.GetThumbnailImages(jsonData); | ||
return Content(JsonConvert.SerializeObject(result)); | ||
} | ||
|
||
[System.Web.Mvc.HttpPost] | ||
public ActionResult Bookmarks(jsonObjects jsonObject) | ||
{ | ||
PdfRenderer pdfviewer = new PdfRenderer(); | ||
var jsonData = JsonConverter(jsonObject); | ||
object jsonResult = pdfviewer.GetBookmarks(jsonData); | ||
return Content(JsonConvert.SerializeObject(jsonResult)); | ||
} | ||
|
||
[System.Web.Mvc.HttpPost] | ||
public ActionResult RenderAnnotationComments(jsonObjects jsonObject) | ||
{ | ||
PdfRenderer pdfviewer = new PdfRenderer(); | ||
var jsonData = JsonConverter(jsonObject); | ||
object jsonResult = pdfviewer.GetAnnotationComments(jsonData); | ||
return Content(JsonConvert.SerializeObject(jsonResult)); | ||
} | ||
|
||
[System.Web.Mvc.HttpPost] | ||
public ActionResult Download(jsonObjects jsonObject) | ||
{ | ||
PdfRenderer pdfviewer = new PdfRenderer(); | ||
var jsonData = JsonConverter(jsonObject); | ||
string documentBase = pdfviewer.GetDocumentAsBase64(jsonData); | ||
return Content(documentBase); | ||
} | ||
|
||
[System.Web.Mvc.HttpPost] | ||
public ActionResult PrintImages(jsonObjects jsonObject) | ||
{ | ||
PdfRenderer pdfviewer = new PdfRenderer(); | ||
var jsonData = JsonConverter(jsonObject); | ||
object pageImage = pdfviewer.GetPrintImage(jsonData); | ||
return Content(JsonConvert.SerializeObject(pageImage)); | ||
} | ||
|
||
private HttpResponseMessage GetPlainText(string pageImage) | ||
{ | ||
var responseText = new HttpResponseMessage(HttpStatusCode.OK); | ||
responseText.Content = new StringContent(pageImage, System.Text.Encoding.UTF8, "text/plain"); | ||
return responseText; | ||
} | ||
|
||
private string GetDocumentPath(string document) | ||
{ | ||
string documentPath = string.Empty; | ||
if (!System.IO.File.Exists(document)) | ||
{ | ||
var path = HttpContext.Request.PhysicalApplicationPath; | ||
if (System.IO.File.Exists(path + "App_Data\\" + document)) | ||
documentPath = path + "App_Data\\" + document; | ||
} | ||
else | ||
{ | ||
documentPath = document; | ||
} | ||
return documentPath; | ||
} | ||
|
||
public ActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
|
||
public ActionResult About() | ||
{ | ||
ViewBag.Message = "Your application description page."; | ||
return View(); | ||
} | ||
|
||
public ActionResult Contact() | ||
{ | ||
ViewBag.Message = "Your contact page."; | ||
return View(); | ||
} | ||
} | ||
|
||
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 string 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; } | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...to/Restrict Zoom Percentage on Mobile Devices/PDFViewerSample/PDFViewerSample/Global.asax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%@ Application Codebehind="Global.asax.cs" Inherits="PDFViewerSample.MvcApplication" Language="C#" %> |
21 changes: 21 additions & 0 deletions
21
...Restrict Zoom Percentage on Mobile Devices/PDFViewerSample/PDFViewerSample/Global.asax.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.Mvc; | ||
using System.Web.Optimization; | ||
using System.Web.Routing; | ||
|
||
namespace PDFViewerSample | ||
{ | ||
public class MvcApplication : System.Web.HttpApplication | ||
{ | ||
protected void Application_Start() | ||
{ | ||
AreaRegistration.RegisterAllAreas(); | ||
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); | ||
RouteConfig.RegisterRoutes(RouteTable.Routes); | ||
BundleConfig.RegisterBundles(BundleTable.Bundles); | ||
} | ||
} | ||
} |
Oops, something went wrong.