Skip to content

Commit

Permalink
Merge pull request #678 from bcgov/test-marshal-DV-4708-revert
Browse files Browse the repository at this point in the history
Test marshal dv 4708 revert
  • Loading branch information
divyav-aot authored Dec 22, 2023
2 parents 3efbe06 + 23d0be0 commit 2206fa8
Show file tree
Hide file tree
Showing 20 changed files with 121 additions and 295 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>
106 changes: 43 additions & 63 deletions MCS.FOI.S3FileConversion/MCS.FOI.DocToPDF/DocFileProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

using Serilog;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIORenderer;
using Syncfusion.Pdf;

Expand Down Expand Up @@ -41,55 +41,35 @@ public DocFileProcessor(Stream SourceStream)
{
try
{
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)
{
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 (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;

}
}
}
using (WordDocument wordDocument = new WordDocument(SourceStream, Syncfusion.DocIO.FormatType.Automatic))
{

wordDocument.RevisionOptions.CommentDisplayMode = CommentDisplayMode.ShowInBalloons;
wordDocument.RevisionOptions.CommentColor = RevisionColor.Blue;
wordDocument.RevisionOptions.ShowMarkup = RevisionType.Deletions | RevisionType.Insertions;

using (DocIORenderer renderer = new DocIORenderer())
{
using PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument);
//Save the PDF file
//Close the instance of document objects
pdfDocument.Save(output);
pdfDocument.Close(true);
converted = true;

}

}
}
catch (Exception e)
{
string errorMessage = $"Exception occured while coverting a document file, exception : {e.Message}";
message = $"Exception happened while accessing File, re-attempting count : {attempt} , Error Message : {e.Message} , Stack trace : {e.StackTrace}";
Log.Error(message);
Console.WriteLine(message);
if (attempt == FailureAttemptCount)
{
throw new Exception(errorMessage);
if (attempt == FailureAttemptCount)
{
throw new Exception(errorMessage);
}
Thread.Sleep(WaitTimeinMilliSeconds);
}
Expand All @@ -104,28 +84,28 @@ public DocFileProcessor(Stream SourceStream)
throw;
}
return (converted, output);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (this.SourceStream != null)
{
this.SourceStream.Close();
this.SourceStream.Dispose();
}

if (output != null) output.Dispose();
// free managed resources
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (this.SourceStream != null)
{
this.SourceStream.Close();
this.SourceStream.Dispose();
}

if (output != null) output.Dispose();
// free managed resources
}

}
}
}
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
36 changes: 32 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 Down Expand Up @@ -177,7 +177,35 @@ public MSGFileProcessor(Stream sourceStream)
Match match = regex.Match(bodyreplaced, startAt);
if (match.Success)
{
string imgReplacementString = "<img style=\"max-width: 700px\" src=\"data:" + _inlineAttachment.MimeType + ";base64," + Convert.ToBase64String(_inlineAttachment.Data) + "\"/>";
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;
}
Expand Down Expand Up @@ -605,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
4 changes: 2 additions & 2 deletions api/reviewer_api/models/DocumentMaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ def getdocumentproperty(cls, ministryrequestid, deleted):
documentmasters = []
try:
sql = """select dm.documentmasterid, dm.processingparentid, d.documentid, d.version,
dhc.rank1hash, d.filename, d.pagecount, d.attributes, dm.parentid from "DocumentMaster" dm,
dhc.rank1hash, d.filename, d.pagecount, dm.parentid from "DocumentMaster" dm,
"Documents" d, "DocumentHashCodes" dhc
where dm.ministryrequestid = :ministryrequestid and dm.ministryrequestid = d.foiministryrequestid
and dm.documentmasterid = d.documentmasterid
and d.documentid = dhc.documentid order by dm.documentmasterid;"""
rs = db.session.execute(text(sql), {'ministryrequestid': ministryrequestid})
for row in rs:
if (row["processingparentid"] is not None and row["processingparentid"] not in deleted) or (row["processingparentid"] is None and row["documentmasterid"] not in deleted):
documentmasters.append({"documentmasterid": row["documentmasterid"], "processingparentid": row["processingparentid"], "documentid": row["documentid"], "rank1hash": row["rank1hash"], "filename": row["filename"], "pagecount": row["pagecount"], "documentattribute": row["attributes"], "parentid": row["parentid"], "version": row["version"]})
documentmasters.append({"documentmasterid": row["documentmasterid"], "processingparentid": row["processingparentid"], "documentid": row["documentid"], "rank1hash": row["rank1hash"], "filename": row["filename"], "pagecount": row["pagecount"], "parentid": row["parentid"], "version": row["version"]})
except Exception as ex:
logging.error(ex)
db.session.close()
Expand Down
15 changes: 6 additions & 9 deletions api/reviewer_api/resources/foiflowmasterdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,11 @@ def post():
)

documentobjs = []
documentids = [documentinfo["file"]["documentid"] for documentinfo in data["documentobjs"]]
documents = documentservice().getdocumentbyids(documentids)
for documentinfo in data["documentobjs"]:
filepath = "/".join(documentinfo["file"]["filepath"].split("/")[4:])
if documentinfo["file"]["processedfilepath"]:
filepath = "/".join(documentinfo["file"]["processedfilepath"].split("/")[4:])
filepath = "/".join(documents[documentinfo["file"]["documentid"]].split("/")[4:])
filename, file_extension = os.path.splitext(filepath)
if file_extension in FILE_CONVERSION_FILE_TYPES:
filepath = filename + ".pdf"

documentinfo["s3url"] = s3client.generate_presigned_url(
ClientMethod="get_object",
Params={
Expand Down Expand Up @@ -315,9 +312,9 @@ def post(ministryrequestid):
# for save/put - stitch by division
div["s3path_save"] = s3path_save
for doc in div["documentlist"]:
filepathlist = doc["filepath"].split("/")[4:]
if doc["processedfilepath"]:
filepathlist = doc["processedfilepath"].split("/")[4:]
realfilepath = documentservice().getfilepathbydocumentid(doc["documentid"])
# filepathlist = doc["filepath"].split("/")[4:]
filepathlist = realfilepath.split("/")[4:]

# for load/get
filepath_get = "/".join(filepathlist)
Expand Down
Loading

0 comments on commit 2206fa8

Please sign in to comment.