procedure ConvertReportToValidHTML(ReportId: Integer): Text
var
TempBlob: Codeunit "Temp Blob";
OutStreamVar: OutStream;
InStreamVar: InStream;
ReportAsHTML: Text;
begin
TempBlob.CreateOutStream(OutStreamVar);
Report.SaveAs(ReportId, '', ReportFormat::Html, OutStreamVar);
TempBlob.CreateInStream(InStreamVar);
InStreamVar.ReadText(ReportAsHTML);
exit(ReplaceInvalidHTMLCharacters(ReportAsHTML));
end;
procedure ReplaceInvalidHTMLCharacters(pText: Text): Text
var
lText: Text;
begin
lText := pText;
lText := lText.Replace('&', '&');
lText := lText.Replace('<', '<');
lText := lText.Replace('>', '>');
lText := lText.Replace('"', '"');
lText := lText.Replace(''', '''');
exit(lText);
end;
function DownloadAsDocx(HTMLData,FileName){
var converted = htmlDocx.asBlob(HTMLData);
var reader = new FileReader();
reader.readAsDataURL(converted);
reader.onloadend = function() {
var base64data = reader.result;
saveAs(base64data, FileName);
}
}
local procedure RunReportWithHTMLContent(Base64DOCX: Text)
var
CustomReportLayout: Record "Custom Report Layout";
Base64Convert: Codeunit "Base64 Convert";
OutStreamVar2: OutStream;
DOCXAsTxt: Text;
begin
CustomReportLayout.Get(CustomReportLayout.InitBuiltInLayout(Report::"WHTML HTML Content View", CustomReportLayout.Type::Word.AsInteger()));
CustomReportLayout.Layout.CreateOutStream(OutStreamVar2);
DOCXAsTxt := Base64DOCX.Remove(StrPos(Base64DOCX, Base64DocxAliasLbl), StrLen(Base64DocxAliasLbl));
Base64Convert.FromBase64(DOCXAsTxt, OutStreamVar2);
CustomReportLayout.Modify();
Commit();
CustomReportLayout.RunCustomReport();
CustomReportLayout.Delete();
end;