|
15 | 15 | using System.Net; |
16 | 16 | using System.Net.Http; |
17 | 17 | using System.Net.Http.Headers; |
| 18 | +using System.Text.RegularExpressions; |
18 | 19 | using System.Web; |
19 | 20 | using System.Web.Http; |
20 | 21 | using System.Web.Http.Cors; |
@@ -286,6 +287,11 @@ public HttpResponseMessage SaveFile(EditDocumentRequest postedData) |
286 | 287 | saveOptions.EnablePagination = true; |
287 | 288 | } |
288 | 289 |
|
| 290 | + if (saveOptions is PresentationSaveOptions) |
| 291 | + { |
| 292 | + saveOptions.SlideNumber = postedData.getPageNumber() + 1; |
| 293 | + } |
| 294 | + |
289 | 295 | using (FileStream outputStream = File.Create(tempPath)) |
290 | 296 | { |
291 | 297 | editor.Save(htmlContentDoc, outputStream, saveOptions); |
@@ -670,16 +676,43 @@ private LoadDocumentEntity LoadDocument(string guid, string password) |
670 | 676 | PresentationEditOptions presentationEditOptions = new PresentationEditOptions(); |
671 | 677 | // Specify slide index from original document. |
672 | 678 | editOptions.SlideNumber = i; // Because index is 0-based, it is 1st slide |
673 | | - EditableDocument slideBeforeEdit = editor.Edit(presentationEditOptions); |
674 | | - |
675 | | - // Get document as a single base64-encoded string, where all resources (images, fonts, etc) |
676 | | - // are embedded inside this string along with main textual content |
677 | | - string allEmbeddedInsideString = slideBeforeEdit.GetEmbeddedHtml(); |
678 | | - PageDescriptionEntity page = new PageDescriptionEntity(); |
679 | | - page.SetData(allEmbeddedInsideString); |
680 | | - page.number = i + 1; |
681 | | - loadDocumentEntity.SetPages(page); |
682 | | - slideBeforeEdit.Dispose(); |
| 679 | + using (EditableDocument slideBeforeEdit = editor.Edit(editOptions)) |
| 680 | + { |
| 681 | + // Get document as a single base64-encoded string, where all resources (images, fonts, etc) |
| 682 | + // are embedded inside this string along with main textual content |
| 683 | + string allEmbeddedInsideString = slideBeforeEdit.GetEmbeddedHtml(); |
| 684 | + PageDescriptionEntity page = new PageDescriptionEntity(); |
| 685 | + if (allEmbeddedInsideString.IndexOf(".slide", StringComparison.Ordinal) > -1) |
| 686 | + { |
| 687 | + // TODO: extract from controller |
| 688 | + string regex = @"\.slide.{(.*?)}"; |
| 689 | + Match match = Regex.Match(allEmbeddedInsideString, regex, RegexOptions.IgnoreCase); |
| 690 | + if (match.Success) |
| 691 | + { |
| 692 | + string rules = match.Groups[1].Value.Trim().TrimEnd(';'); |
| 693 | + Dictionary<string, string> keyValuePairs = rules.Split(';') |
| 694 | + .Select(value => value.Split(':')) |
| 695 | + .ToDictionary(pair => pair[0].Trim(), pair => pair[1].Trim()); |
| 696 | + |
| 697 | + if (keyValuePairs.ContainsKey("height")) |
| 698 | + { |
| 699 | + string height = string.Empty; |
| 700 | + keyValuePairs.TryGetValue("height", out height); |
| 701 | + page.height = Convert.ToDouble(height.Replace("pt", "").Replace("px", "")); |
| 702 | + } |
| 703 | + |
| 704 | + if (keyValuePairs.ContainsKey("width")) |
| 705 | + { |
| 706 | + string width = string.Empty; |
| 707 | + keyValuePairs.TryGetValue("width", out width); |
| 708 | + page.width = Convert.ToDouble(width.Replace("pt", "").Replace("px", "")); |
| 709 | + } |
| 710 | + } |
| 711 | + } |
| 712 | + page.SetData(allEmbeddedInsideString); |
| 713 | + page.number = i + 1; |
| 714 | + loadDocumentEntity.SetPages(page); |
| 715 | + } |
683 | 716 | } |
684 | 717 | } |
685 | 718 | } |
|
0 commit comments