From 74a29e4b4fe0557669376a137d40827a07c9cdf2 Mon Sep 17 00:00:00 2001 From: nkan-aot <96087745+nkan-aot@users.noreply.github.com> Date: Thu, 7 Dec 2023 10:31:00 -0800 Subject: [PATCH 1/5] update logic for side by side images and replace entire img tag --- .../MCS.FOI.MSGToPDF/MSGFileProcessor.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs b/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs index d0e0bb009..d218a706b 100644 --- a/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs +++ b/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs @@ -1,4 +1,4 @@ -using MsgReader.Outlook; +using MsgReader.Outlook; using MsgReader; using Serilog; using Syncfusion.HtmlConverter; @@ -140,6 +140,7 @@ public MSGFileProcessor(Stream sourceStream) inlineAttachments.Add(_attachment); } } + var startAt = 0; foreach (var inlineAttachment in inlineAttachments.OrderBy(m => m.GetType().GetProperty("RenderingPosition").GetValue(m, null))) { if (rtfInline) @@ -172,7 +173,14 @@ public MSGFileProcessor(Stream sourceStream) else if (htmlInline) { var _inlineAttachment = (Storage.Attachment)inlineAttachment; - bodyreplaced = Regex.Replace(bodyreplaced, "src=\"cid:" + _inlineAttachment.ContentId, "style=\"max-width: 700px\" src=\"data:" + _inlineAttachment.MimeType + ";base64," + Convert.ToBase64String(_inlineAttachment.Data)); + Regex regex = new Regex(""); + Match match = regex.Match(bodyreplaced, startAt); + if (match.Success) + { + string imgReplacementString = ""; + bodyreplaced = regex.Replace(bodyreplaced, imgReplacementString, 1, startAt); + startAt = match.Index + imgReplacementString.Length; + } foreach (KeyValuePair> attachment in attachmentsObj) { if (attachment.Value.ContainsKey("cid") && attachment.Value["cid"] == _inlineAttachment.ContentId) @@ -597,4 +605,4 @@ static string RemoveContentBetweenTags(string inputString) } } -} \ No newline at end of file +} From d5e37cd6717e1e456762fea190f55429d6a974c2 Mon Sep 17 00:00:00 2001 From: nkan-aot <96087745+nkan-aot@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:16:57 -0800 Subject: [PATCH 2/5] add back scaling logic for html inline imgs --- .../MCS.FOI.MSGToPDF/MSGFileProcessor.cs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs b/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs index d218a706b..8c09100ac 100644 --- a/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs +++ b/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs @@ -149,7 +149,7 @@ public MSGFileProcessor(Stream sourceStream) { var _inlineAttachment = (Storage.Attachment)inlineAttachment; if (_inlineAttachment.OleAttachment) - { + { bodyreplaced = ReplaceFirstOccurrence(bodyreplaced, rtfInlineObject, ""); foreach (KeyValuePair> attachment in attachmentsObj) { @@ -177,7 +177,24 @@ public MSGFileProcessor(Stream sourceStream) Match match = regex.Match(bodyreplaced, startAt); if (match.Success) { - string imgReplacementString = ""; + const float maxSize = 700; + Regex.Match(match.Value, "width=(\"|\')?(?\\d+)(\"|\')?").Groups.TryGetValue("width", out var w); + float width = float.Parse(w.Value); + Regex.Match(match.Value, "height=(\"|\')?(?\\d+)(\"|\')?").Groups.TryGetValue("height", out var h); + float height = float.Parse(h.Value); + if (width > maxSize && width >= height) + { + float scale = maxSize / width; + width = (int) (width * scale); + height = (int) (height * scale); + } + if (height > maxSize) + { + float scale = maxSize / height; + width = (int) (width * scale); + height = (int) (height * scale); + } + string imgReplacementString = ""; bodyreplaced = regex.Replace(bodyreplaced, imgReplacementString, 1, startAt); startAt = match.Index + imgReplacementString.Length; } From 02c5ed999717aa002c3ad96df7f7810f2b8c74b9 Mon Sep 17 00:00:00 2001 From: nkan-aot <96087745+nkan-aot@users.noreply.github.com> Date: Fri, 8 Dec 2023 12:01:44 -0800 Subject: [PATCH 3/5] fix minor spacing issue between images --- MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs b/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs index 8c09100ac..69fbb0235 100644 --- a/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs +++ b/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs @@ -149,7 +149,7 @@ public MSGFileProcessor(Stream sourceStream) { var _inlineAttachment = (Storage.Attachment)inlineAttachment; if (_inlineAttachment.OleAttachment) - { + { bodyreplaced = ReplaceFirstOccurrence(bodyreplaced, rtfInlineObject, ""); foreach (KeyValuePair> attachment in attachmentsObj) { @@ -194,7 +194,7 @@ public MSGFileProcessor(Stream sourceStream) width = (int) (width * scale); height = (int) (height * scale); } - string imgReplacementString = ""; + string imgReplacementString = ""; bodyreplaced = regex.Replace(bodyreplaced, imgReplacementString, 1, startAt); startAt = match.Index + imgReplacementString.Length; } From 0e1c56e14010a26c8725abb53c30f33f1ffb7fa1 Mon Sep 17 00:00:00 2001 From: divyav-aot Date: Fri, 15 Dec 2023 17:27:38 -0500 Subject: [PATCH 4/5] document comments fixes and package upgrades --- .../MCS.FOI.CalendarToPDF.csproj | 2 +- .../MCS.FOI.DocToPDF/DocFileProcessor.cs | 38 +++++-------------- .../MCS.FOI.DocToPDF/MCS.FOI.DocToPDF.csproj | 6 +-- .../MCS.FOI.ExcelToPDF.csproj | 6 +-- .../MCS.FOI.MSGToPDF/MCS.FOI.MSGToPDF.csproj | 2 +- .../MCS.FOI.PptToPDF/MCS.FOI.PPTToPDF.csproj | 2 +- .../MCS.FOI.S3FileConversion.csproj | 6 +-- 7 files changed, 21 insertions(+), 41 deletions(-) diff --git a/MCS.FOI.S3FileConversion/MCS.FOI.CalendarToPDF/MCS.FOI.CalendarToPDF.csproj b/MCS.FOI.S3FileConversion/MCS.FOI.CalendarToPDF/MCS.FOI.CalendarToPDF.csproj index 339216474..c10eb90d1 100644 --- a/MCS.FOI.S3FileConversion/MCS.FOI.CalendarToPDF/MCS.FOI.CalendarToPDF.csproj +++ b/MCS.FOI.S3FileConversion/MCS.FOI.CalendarToPDF/MCS.FOI.CalendarToPDF.csproj @@ -11,7 +11,7 @@ - + diff --git a/MCS.FOI.S3FileConversion/MCS.FOI.DocToPDF/DocFileProcessor.cs b/MCS.FOI.S3FileConversion/MCS.FOI.DocToPDF/DocFileProcessor.cs index 748f8f9db..6bb8eba48 100644 --- a/MCS.FOI.S3FileConversion/MCS.FOI.DocToPDF/DocFileProcessor.cs +++ b/MCS.FOI.S3FileConversion/MCS.FOI.DocToPDF/DocFileProcessor.cs @@ -43,42 +43,22 @@ public DocFileProcessor(Stream SourceStream) { using (WordDocument wordDocument = new WordDocument(SourceStream, Syncfusion.DocIO.FormatType.Automatic)) { + wordDocument.RevisionOptions.CommentDisplayMode = CommentDisplayMode.ShowInBalloons; wordDocument.RevisionOptions.CommentColor = RevisionColor.Blue; - foreach(var entity in wordDocument.ChildEntities) + + using (DocIORenderer renderer = new DocIORenderer()) { - if(entity.GetType().FullName == "Syncfusion.DocIO.DLS.WSection") - { - Syncfusion.DocIO.DLS.WSection _wsection = (Syncfusion.DocIO.DLS.WSection)entity; - - foreach (IWTable table in _wsection.Tables) - { - table.TableFormat.IsAutoResized = false; - table.TableFormat.WrapTextAround = true; - } - - } + using PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument); + //Save the PDF file + //Close the instance of document objects + pdfDocument.Save(output); + pdfDocument.Close(true); + converted = true; } - using (Stream wordstream = new MemoryStream()) - { - wordDocument.Save(wordstream, wordDocument.ActualFormatType); - - //Creates an instance of DocIORenderer. - using (DocIORenderer renderer = new DocIORenderer()) - { - - using PdfDocument pdfDocument = renderer.ConvertToPDF(wordstream); - //Save the PDF file - //Close the instance of document objects - pdfDocument.Save(output); - pdfDocument.Close(true); - converted = true; - - } - } } } catch (Exception e) diff --git a/MCS.FOI.S3FileConversion/MCS.FOI.DocToPDF/MCS.FOI.DocToPDF.csproj b/MCS.FOI.S3FileConversion/MCS.FOI.DocToPDF/MCS.FOI.DocToPDF.csproj index 25e0301a2..2c4b45afd 100644 --- a/MCS.FOI.S3FileConversion/MCS.FOI.DocToPDF/MCS.FOI.DocToPDF.csproj +++ b/MCS.FOI.S3FileConversion/MCS.FOI.DocToPDF/MCS.FOI.DocToPDF.csproj @@ -7,7 +7,7 @@ - + @@ -15,8 +15,8 @@ - - + + diff --git a/MCS.FOI.S3FileConversion/MCS.FOI.ExcelToPDF/MCS.FOI.ExcelToPDF.csproj b/MCS.FOI.S3FileConversion/MCS.FOI.ExcelToPDF/MCS.FOI.ExcelToPDF.csproj index 3caac2185..51173238b 100644 --- a/MCS.FOI.S3FileConversion/MCS.FOI.ExcelToPDF/MCS.FOI.ExcelToPDF.csproj +++ b/MCS.FOI.S3FileConversion/MCS.FOI.ExcelToPDF/MCS.FOI.ExcelToPDF.csproj @@ -6,9 +6,9 @@ enable - - - + + + diff --git a/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MCS.FOI.MSGToPDF.csproj b/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MCS.FOI.MSGToPDF.csproj index f1479f1ec..92be8d41c 100644 --- a/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MCS.FOI.MSGToPDF.csproj +++ b/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MCS.FOI.MSGToPDF.csproj @@ -14,7 +14,7 @@ - + diff --git a/MCS.FOI.S3FileConversion/MCS.FOI.PptToPDF/MCS.FOI.PPTToPDF.csproj b/MCS.FOI.S3FileConversion/MCS.FOI.PptToPDF/MCS.FOI.PPTToPDF.csproj index 8092e8b24..234c8f398 100644 --- a/MCS.FOI.S3FileConversion/MCS.FOI.PptToPDF/MCS.FOI.PPTToPDF.csproj +++ b/MCS.FOI.S3FileConversion/MCS.FOI.PptToPDF/MCS.FOI.PPTToPDF.csproj @@ -10,7 +10,7 @@ - + diff --git a/MCS.FOI.S3FileConversion/MCS.FOI.S3FileConversion/MCS.FOI.S3FileConversion.csproj b/MCS.FOI.S3FileConversion/MCS.FOI.S3FileConversion/MCS.FOI.S3FileConversion.csproj index 05e23eb45..3b897ce04 100644 --- a/MCS.FOI.S3FileConversion/MCS.FOI.S3FileConversion/MCS.FOI.S3FileConversion.csproj +++ b/MCS.FOI.S3FileConversion/MCS.FOI.S3FileConversion/MCS.FOI.S3FileConversion.csproj @@ -33,14 +33,14 @@ - - + + - + From 27301837991c70727777570936f61f4a3182d674 Mon Sep 17 00:00:00 2001 From: divyav-aot Date: Mon, 18 Dec 2023 15:43:05 -0500 Subject: [PATCH 5/5] msg exception related to embed files fixed --- .../MCS.FOI.MSGToPDF/MSGFileProcessor.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs b/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs index 69fbb0235..43afdb81a 100644 --- a/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs +++ b/MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs @@ -124,7 +124,7 @@ public MSGFileProcessor(Stream sourceStream) var _attachment = (Storage.Attachment)attachment; if (htmlInline) { - if (!String.IsNullOrEmpty(_attachment.ContentId) && bodyreplaced.Contains(_attachment.ContentId)) + if (!String.IsNullOrEmpty(_attachment.ContentId) && (bodyreplaced.Contains(_attachment.ContentId) || _attachment.Hidden)) { inlineAttachments.Add(_attachment); } @@ -179,9 +179,10 @@ public MSGFileProcessor(Stream sourceStream) { const float maxSize = 700; Regex.Match(match.Value, "width=(\"|\')?(?\\d+)(\"|\')?").Groups.TryGetValue("width", out var w); - float width = float.Parse(w.Value); + float width = float.TryParse(w?.Value, out float tempWidth) ? tempWidth : 0; Regex.Match(match.Value, "height=(\"|\')?(?\\d+)(\"|\')?").Groups.TryGetValue("height", out var h); - float height = float.Parse(h.Value); + float height = float.TryParse(h?.Value, out float tempHeight) ? tempHeight : 0; + if (width > maxSize && width >= height) { float scale = maxSize / width; @@ -194,7 +195,17 @@ public MSGFileProcessor(Stream sourceStream) width = (int) (width * scale); height = (int) (height * scale); } - string imgReplacementString = ""; + string widthString = string.Empty; + string heightString = string.Empty; + if (width > 0) + { + widthString = " width =\"" + width +"\""; + } + if (height > 0) + { + heightString = " height =\"" + height + "\""; + } + string imgReplacementString = ""; bodyreplaced = regex.Replace(bodyreplaced, imgReplacementString, 1, startAt); startAt = match.Index + imgReplacementString.Length; }