ALCodeSamples icon indicating copy to clipboard operation
ALCodeSamples copied to clipboard

PDF to Bigtext Covert..

Open srinivasdes opened this issue 8 years ago • 1 comments

Hi ,

We usually had a function in CAL to convert Report PDF file to bigtext with .net variables. But as we know .net variable is not recognized with in AL.

Here is our existing function. Can someone help me to convert this function in AL

local procedure ConvertPDF2BigText(PdfFileName : Text[1024];var ReportWIthBigText : BigText); var Convert : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Convert"; Path : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.Path"; File : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.File"; FileAccess : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.FileAccess"; FileMode : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.FileMode"; MemoryStream : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.MemoryStream"; FileStream : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.FileStream"; begin FileMode := 4; FileAccess := 1; FileStream := File.Open(PdfFileName, FileMode, FileAccess); MemoryStream := MemoryStream.MemoryStream(); MemoryStream.SetLength(FileStream.Length); FileStream.Read(MemoryStream.GetBuffer(), 0, FileStream.Length); ReportWIthBigText.ADDTEXT(Convert.ToBase64String(MemoryStream.GetBuffer())); MemoryStream.Close(); MemoryStream.Dispose(); FileStream.Close(); FileStream.Dispose(); File.Delete(PdfFileName); end;

srinivasdes avatar Feb 05 '18 12:02 srinivasdes

My recommendation: do not use a file for report output. Instead use the function Report.SaveAs and let it stream the output to an OutStream of the BLOB field of the TempBlob table. Then use the ToBase64String method on the TempBlob table.

Then you get something like this:

TempBlob.Blob.CreateOutStream(OutStr);
Report.SaveAs(ReportId, Parameters, ReportFormat::Pdf, OutStr, RecRef);
Base64String := TempBlob.ToBase64String

RecRef should of course contain the record that must be printed.

The Parameters argument of Report.SaveAs is a string containing XML. You can get this by running the command Parameters := Report.RunRequestPage(ReportId,Parameters);

ajkauffmann avatar Feb 12 '18 23:02 ajkauffmann