Skip to content

Commit

Permalink
Updated CHtmlExporter.cs to use Html exportables namespace.
Browse files Browse the repository at this point in the history
Removed and re-added HtmlToPdfConverter.cs under new namespace.
Added DocX and HtmlToOpenXml.dll package references.
Disabled PDF export checkbox in VhcGui.xaml.cs for VB365 and VBR.
Added CHtmlToDocx.cs for HTML to DOCX conversion.
  • Loading branch information
adamcongdon committed Dec 17, 2024
1 parent 6351ce1 commit 9bf6670
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 13 deletions.
8 changes: 6 additions & 2 deletions vHC/HC_Reporting/Functions/Reporting/Html/CHtmlExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using VeeamHealthCheck.Scrubber;
using VeeamHealthCheck.Shared;
using VeeamHealthCheck.Shared.Logging;
using VeeamHealthCheck.Functions.Reporting.Pdf;
using VeeamHealthCheck.Functions.Reporting.Html.Exportables;

namespace VeeamHealthCheck.Functions.Reporting.Html
{
Expand Down Expand Up @@ -100,6 +100,7 @@ public int ExportHtmlVb365(string htmlString, bool scrub)
if (!scrub && CGlobals.EXPORTPDF)
{
ExportHtmlStringToPDF(htmlString);

}

OpenHtmlIfEnabled(CGlobals.OpenHtml);
Expand Down Expand Up @@ -127,7 +128,7 @@ public int ExportVbrHtml(string htmlString, bool scrub)
//test export to PDF:
if (!scrub && CGlobals.EXPORTPDF)
{
ExportHtmlStringToPDF(htmlString);
ExportHtmlStringToPDF(htmlString);
}

OpenHtmlIfEnabled(CGlobals.OpenHtml);
Expand Down Expand Up @@ -168,6 +169,9 @@ private void ExportHtmlStringToPDF(string htmlString)

pdf.ConvertHtmlToPdf(htmlShowAll, _latestReport.Replace(".html", ".pdf"));
pdf.Dispose();

//var htmlToDocx = new CHtmlToDocx();
//htmlToDocx.ExportHtmlToDocx(htmlShowAll, _latestReport.Replace(".html", ".docx"));
}

public int ExportVbrSecurityHtml(string htmlString, bool scrub)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System;
using System.IO;
using Xceed.Words.NET;
using HtmlToOpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;

namespace VeeamHealthCheck.Functions.Reporting.Html.Exportables
{
internal class CHtmlToDocx
{
public void ExportHtmlToDocx(string htmlContent, string outputPath)
{
// Create a new document
using (var wordDocument = WordprocessingDocument.Create(outputPath, WordprocessingDocumentType.Document))
{
// Add a main document part
var mainPart = wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
var body = new Body();
mainPart.Document.Append(body);

// Set the document to landscape mode
var sectionProperties = new SectionProperties();
var pageSize = new PageSize
{
Width = 16838, // 11.69 inches in twentieths of a point (A4 landscape width)
Height = 11906, // 8.27 inches in twentieths of a point (A4 landscape height)
Orient = PageOrientationValues.Landscape
};
var pageMargin = new PageMargin
{
Top = 720, // 1 inch in twentieths of a point
Right = 720,
Bottom = 720,
Left = 720
};
sectionProperties.Append(pageSize);
sectionProperties.Append(pageMargin);
body.Append(sectionProperties);

// Create a new HtmlConverter
var converter = new HtmlConverter(mainPart);

// Convert the HTML content to DocX format
converter.ParseBody(htmlContent);

// Save the document
mainPart.Document.Save();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using System.IO;
using System.Windows.Controls;

namespace VeeamHealthCheck.Functions.Reporting.Pdf
{
namespace VeeamHealthCheck.Functions.Reporting.Html.Exportables
{
public class HtmlToPdfConverter
{
private IConverter _converter;
Expand Down
2 changes: 1 addition & 1 deletion vHC/HC_Reporting/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"VeeamHealthCheck": {
"commandName": "Project",
"commandLineArgs": "/import",
"commandLineArgs": "/import /pdf",
"remoteDebugEnabled": true,
"authenticationMode": "Windows",
"remoteDebugMachine": "192.168.20.152:4026"
Expand Down
9 changes: 5 additions & 4 deletions vHC/HC_Reporting/Startup/CClientFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ public string ModeCheck()
CGlobals.Logger.Error("No Veeam Software detected. Is this server the VBR or VB365 management server?", false);
return "fail";
}
if (CGlobals.IsVbr)
return title + " - " + VbrLocalizationHelper.GuiTitleBnR;
if (CGlobals.IsVb365)
return title + " - " + VbrLocalizationHelper.GuiTitleVB365;

if (CGlobals.IsVbr && CGlobals.IsVb365)
return title + " - " + VbrLocalizationHelper.GuiTitleBnR + " & " + VbrLocalizationHelper.GuiTitleVB365;
if (!CGlobals.IsVb365 && !CGlobals.IsVbr)
return title + " - " + VbrLocalizationHelper.GuiImportModeOnly;
if (CGlobals.IsVbr)
return title + " - " + VbrLocalizationHelper.GuiTitleBnR;
if (CGlobals.IsVb365)
return title + " - " + VbrLocalizationHelper.GuiTitleVB365;
else
return title;
}
Expand Down
6 changes: 4 additions & 2 deletions vHC/HC_Reporting/VeeamHealthCheck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
<Company>Veeam</Company>
<Authors>AdamC</Authors>
<ApplicationIcon>Health_Check_Icon.ico</ApplicationIcon>
<AssemblyVersion>2.0.0.572</AssemblyVersion>
<AssemblyVersion>2.0.0.588</AssemblyVersion>
<SignAssembly>False</SignAssembly>
<DelaySign>false</DelaySign>
<FileVersion>2.0.0.572</FileVersion>
<FileVersion>2.0.0.588</FileVersion>
<DebugType>full</DebugType>
<SelfContained>true</SelfContained>
<!--These 2 lines are what produce the single file utility. Possibly doesn't work...-->
Expand Down Expand Up @@ -117,6 +117,8 @@
<ItemGroup>
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="DinkToPdf.Standard" Version="1.1.0" />
<PackageReference Include="DocX" Version="3.0.1" />
<PackageReference Include="HtmlToOpenXml.dll" Version="3.2.2" />
<PackageReference Include="Microsoft.Management.Infrastructure" Version="3.0.0" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.4.6" />
<PackageReference Include="Node.js" Version="5.3.0" />
Expand Down
6 changes: 6 additions & 0 deletions vHC/HC_Reporting/VhcGui.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public VhcGui()

SetUi();
pathBox.IsEnabled = false;
//pdfCheckBox.IsEnabled = false;

}
private void SetUi()
Expand All @@ -30,6 +31,11 @@ private void SetUi()


this.Title = _functions.ModeCheck();
if(CGlobals.IsVb365 && CGlobals.IsVbr)
{
pdfCheckBox.IsEnabled = false;
pdfCheckBox.ToolTip = "PDF Export not available when both VB365 & VBR are detected on the same machine.";
}
_functions.PreRunCheck();

SetUiText();
Expand Down
4 changes: 2 additions & 2 deletions vHC/VhcXTests/VhcXTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<AssemblyVersion>1.0.0.296</AssemblyVersion>
<FileVersion>1.0.0.296</FileVersion>
<AssemblyVersion>1.0.0.310</AssemblyVersion>
<FileVersion>1.0.0.310</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 9bf6670

Please sign in to comment.