Skip to content

Commit

Permalink
Merge branch 'dev' into dev-DV-4708
Browse files Browse the repository at this point in the history
  • Loading branch information
divyav-aot committed Dec 20, 2023
2 parents f992ba6 + a48441e commit f8a1fe0
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
<PackageReference Include="Syncfusion.HtmlToPdfConverter.QtWebKit.Net.Core" Version="19.1.0.63" />
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="23.1.40" />
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="23.2.7" />
</ItemGroup>

</Project>
38 changes: 9 additions & 29 deletions MCS.FOI.S3FileConversion/MCS.FOI.DocToPDF/DocFileProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="23.1.40" />
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="23.2.7" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />

<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<!--<PackageReference Include="System.Drawing.Common" Version="5.0.2" />-->
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="23.1.40" />
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="23.1.40" />
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="23.2.7" />
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="23.2.7" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="23.1.40" />
<PackageReference Include="Syncfusion.XlsIORenderer.Net.Core" Version="23.1.40" />
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="23.1.40" />
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="23.2.7" />
<PackageReference Include="Syncfusion.XlsIORenderer.Net.Core" Version="23.2.7" />
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="23.2.7" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.3" />
<PackageReference Include="MsgReader" Version="4.5.0" />
<PackageReference Include="Syncfusion.HtmlToPdfConverter.QtWebKit.Net.Core" Version="20.3.0.56" />
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="21.2.9" />
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="23.2.7" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
</ItemGroup>

Expand Down
44 changes: 40 additions & 4 deletions MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MsgReader.Outlook;
using MsgReader.Outlook;
using MsgReader;
using Serilog;
using Syncfusion.HtmlConverter;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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)
Expand Down Expand Up @@ -172,7 +173,42 @@ 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("<img(.|\\n)*cid:" + _inlineAttachment.ContentId + "(.|\\n)*?>");
Match match = regex.Match(bodyreplaced, startAt);
if (match.Success)
{
const float maxSize = 700;
Regex.Match(match.Value, "width=(\"|\')?(?<width>\\d+)(\"|\')?").Groups.TryGetValue("width", out var w);
float width = float.TryParse(w?.Value, out float tempWidth) ? tempWidth : 0;
Regex.Match(match.Value, "height=(\"|\')?(?<height>\\d+)(\"|\')?").Groups.TryGetValue("height", out var h);
float height = float.TryParse(h?.Value, out float tempHeight) ? tempHeight : 0;

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 widthString = string.Empty;
string heightString = string.Empty;
if (width > 0)
{
widthString = " width =\"" + width +"\"";
}
if (height > 0)
{
heightString = " height =\"" + height + "\"";
}
string imgReplacementString = "<img "+ widthString + heightString + " style =\"margin: 1px;\" src=\"data:" + _inlineAttachment.MimeType + ";base64," + Convert.ToBase64String(_inlineAttachment.Data) + "\"/>";
bodyreplaced = regex.Replace(bodyreplaced, imgReplacementString, 1, startAt);
startAt = match.Index + imgReplacementString.Length;
}
foreach (KeyValuePair<MemoryStream, Dictionary<string, string>> attachment in attachmentsObj)
{
if (attachment.Value.ContainsKey("cid") && attachment.Value["cid"] == _inlineAttachment.ContentId)
Expand Down Expand Up @@ -597,4 +633,4 @@ static string RemoveContentBetweenTags(string inputString)
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.8.2.3" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="23.1.40" />
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="23.2.7" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Npgsql" Version="7.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.6.70" />
<PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Linux" Version="21.2.9" />
<PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Windows" Version="21.2.9" />
<PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Linux" Version="23.2.7" />
<PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Windows" Version="23.2.7" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="23.1.40" />
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="23.2.7" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit f8a1fe0

Please sign in to comment.