program GeneratingInMemory;

{$APPTYPE CONSOLE}

uses

SysUtils, Graphics, Classes, HPDFDoc;

 

var

HPDF: THotPDF;

MemStream: TMemoryStream;

OutputStream: TFileStream;

begin

HPDF:= THotPDF.Create(nil);

try

MemStream := TMemoryStream.Create;            // إنشاء تدفق الذاكرة

try

HPDF.OutputStream := MemStream;           // تعيين تدفق المخرجات

HPDF.Compression := cmFlateDecode;        // تعيين ضغط flate

 

HPDF.BeginDoc;                                          // بدء إنشاء ملف PDF

HPDF.CurrentPage.TextOut(10, 10, 0, 'Hello World!'); // كتابة النص على الصفحة

HPDF.EndDoc;                                          // إنهاء ملف PDF في الذاكرة

 

MemStream.Position := 0;                 // إعادة تعيين الموضع قبل النسخ إلى تدفق الملف

 

OutputStream := TFileStream.Create( 'Memory.pdf', fmCreate ) ; // إنشاء تدفق ملف المخرجات

try

OutputStream.CopyFrom( MemStream, MemStream.Size );             // نسخ ملف PDF المنشأ من الذاكرة

finally

OutputStream.Free;                                            // تحرير تدفق ملف المخرجات

end;

finally

MemStream.Free;                        // تحرير تدفق الذاكرة

end;

finally

HPDF.Free;

end;

end.