Get PDF from XData Result is empty

Hello,
i am trying to send one PDF from the XData Server as Encode64 string to the Web Application, but the PDF is empty after download it from the Webbrowser.
The VCL Server part works fine, but the Web part has a Problem.

I already tried to use a different PDF to send, but i get the same result as before.
The Fonts are already loaded
AddFontToCache('fonts\arial.ttf');

Here is a Screenshot from the PDF File which i want to send

Result from the Webapplication

Delphi 10.2.3
TMS Web Version 1.9.2.0
TMS FNC UI Version 3.7.2.0

//VCL Server
function TBookingService.PrintVoucher(BookingNr: string; BookingEmail :string) : string;
var
	ls_Result :string;
	ls_PDFResult :string;
	lo_PDFStream  :TStringStream;
begin		
	lo_PDFStream := TStringStream.Create;	
	ls_Result := SybDM.PrintVoucher(BookingNr);
	if (ls_Result <> '') then
	begin
		ls_Result := TTMSFNCUtils.Encode64(ls_Result, false );
		//OK
		ls_PDFResult := TTMSFNCUtils.Decode64(ls_Result, false );
		lo_PDFStream.WriteString(ls_PDFResult);
		lo_PDFStream.SaveToFile('C:\temp\BookingNr_SRV.pdf');
	end;
	Result := ls_Result;
end;

//Web
function PrintVoucher() :string;
var ls_ResponseResult : string;
	ls_PDFData : string;
	lo_PDFData : TBytes;
	ls_FileName :string;
begin	
	lo_Response:= Await(XDataWebClient1.RawInvokeAsync('IBookingService.PrintVoucher',[BookingNr,BookingEmail]));
	ls_ResponseResult := string( TJSObject(lo_Response.Result)['value'] );  
	if (ls_ResponseResult <> '') then
	begin
		ls_PDFData := TTMSFNCUtils.Decode64(ls_ResponseResult, false );

		Logging('Info','Decode Length: ' + inttostr(Length(ls_PDFData)));
		Logging('Info','Decode Data: ' + ls_PDFData);
		lo_PDFData := BytesOf(ls_PDFData);
		Logging('Info','BytesOf Length: ' + IntToStr(Length(lo_PDFData)));


		ls_FileName := 'Voucher_[BookingNr].pdf';
		Application.DownloadPDFFile(lo_PDFData,ls_FileName,false);
	end;
end;

What am i missing?

Thanks

1 Like

To begin with, do you see any error in the browser console?

Unfortunately there is no Error in the Browser Console.
Here are the Files which are created by the VCL Server and the Web App.
BookingNr_SRV.pdf (2.5 KB)
Voucher_Web.pdf (2.8 KB)

When i open "Voucher_Web.pdf" with Notepad++ the File contains the Content of the Pdf but when i open the pdf with an PDF Viewer it is empty.

What happened if the Function "DownloadPDFFile" fails, is the PDF File empty?

Notepad++ selects the encoding automatically. While the two files look similar when you open them in Notepad++ the VCL version is actually ANSI while the PDF from the WEB app is UTF-8 encoded.

You can start by verifying that ls_ResponseResult a valid base64 encoded PDF. You can run the value of ls_ResponseResult through a decoder: Base64 to PDF | Base64 Decode | Base64 Converter | Base64

Thank you, with your help i was able to fix the Problem.
The Problem was i exported the PDF with FastReport (default ANSI).
Now i'm using the Function "TNetEncoding.Base64.Encode(inStream, outStream)" instead of "TTMSFNCUtils.Encode64(ls_Result, false )"; and it works fine.

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.