Get PDF from XData Result is empty

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

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

Result from the Webapplication

Delphi 10.2.3
TMS Web Version
TMS FNC UI Version

//VCL Server
function TBookingService.PrintVoucher(BookingNr: string; BookingEmail :string) : string;
	ls_Result :string;
	ls_PDFResult :string;
	lo_PDFStream  :TStringStream;
	lo_PDFStream := TStringStream.Create;	
	ls_Result := SybDM.PrintVoucher(BookingNr);
	if (ls_Result <> '') then
		ls_Result := TTMSFNCUtils.Encode64(ls_Result, false );
		ls_PDFResult := TTMSFNCUtils.Decode64(ls_Result, false );
	Result := ls_Result;

function PrintVoucher() :string;
var ls_ResponseResult : string;
	ls_PDFData : string;
	lo_PDFData : TBytes;
	ls_FileName :string;
	lo_Response:= Await(XDataWebClient1.RawInvokeAsync('IBookingService.PrintVoucher',[BookingNr,BookingEmail]));
	ls_ResponseResult := string( TJSObject(lo_Response.Result)['value'] );  
	if (ls_ResponseResult <> '') then
		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';

What am i missing?


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.