Month: February 2019

C++Builder dynamic create & delete HotPDF component instance

This example shows you how to programmatically New and Free a HotPDF object instance with C++Builder.

#include 
#pragma hdrstop

#include "Unit1.h"
#pragma package(smart_init)
#pragma link "HPDFDoc"
#pragma resource "*.dfm"
TForm1 *Form1;

__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{

    THotPDF* HotPDF1 = new THotPDF(this);
    HotPDF1->FileName = "HelloWorld.pdf";
    HotPDF1->AutoLaunch = true;      
    HotPDF1->BeginDoc(false);
    HotPDF1->CurrentPage->PrintText( 10, 10, 0, "Hello World!" );
    HotPDF1->EndDoc();
    HotPDF1->Free(); 	
}

You need to set the include & library path of the project to the directory where HotPDF library files exist.

HotPDF Canvas Draw

This HotPDF Component Sample draw plots with Delphi TCanvas.

program CanvasDraw;
{$APPTYPE CONSOLE}
uses
{$IFDEF VER230} System.SysUtils, System.Classes, Vcl.Graphics, {$ELSE} SysUtils, Classes, Graphics, {$ENDIF} HPDFDoc;

var
   I, Y: Integer;
   HotPDF: THotPDF;

begin
    HotPDF:= THotPDF.Create(nil);
    try
        Randomize;
        HotPDF.AutoLaunch := true;
        HotPDF.FileName := 'CanvasDraw.pdf';
        HotPDF.BeginDoc;                                          // Create PDF file
        HotPDF.Canvas.Font.Size := 14;                            // Set canvas font size
        I :=20;
        Y := 60;
        HotPDF.Canvas.TextOut(10, 30, 'Canvas Rectangles');      //  Print text
        while I <= 700 do
        begin                                                   //  Draw colour
            HotPDF.Canvas.Brush.Color := random($FFFFFF);         //  rectangles
            HotPDF.Canvas.Rectangle(I, Y, I+90, Y + 160);
            Inc(I, 30);
            Inc( Y, 3 );
        end;

        I :=20;
        Y := 350;
        HotPDF.Canvas.TextOut(10, 320, 'Canvas Ellipses');         // Print text
        while I <= 700 do                                       //  Draw colour
        begin                                                   //  ellipses
            HotPDF.Canvas.Brush.Color := random($FFFFFF);
            HotPDF.Canvas.Ellipse(I, Y, I+90, Y + 160);
            Inc(I, 30);
            Inc( Y, 3 );
        end;

        I :=20;
        Y := 680;
        HotPDF.Canvas.TextOut(10, 650, 'Canvas RoundRects');      // Print text
        while I <= 700 do
        begin
            HotPDF.Canvas.Brush.Color := random($FFFFFF);         //  Draw colour
            HotPDF.Canvas.RoundRect(I, Y, I+90, Y + 160, 20, 20); //  roundrects
            Inc(I, 30);                                         
            Inc( Y, 3 );
        end;
        HotPDF.EndDoc;                                            // Close PDF file
    finally
        HotPDF.Free;
    end;
end.