Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

BasicPDF

Basic PDF file creation library

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

BasicPDF

Basic PDF file creation library

Sample function:

pascal
procedure TForm1.Button1Click(Sender: TObject);
var
  PDF: TBasicPDF;
begin
  PDF := TBasicPDF.Create;
  try
    PDF.AddText('Hello, World!', 100, 100); // X=100, Y=100 (from top-left)
    PDF.SaveToFile('HelloWorld.pdf');       // coordinates in points (1 point = 1/72 inch)
  finally
    PDF.Free;
  end;
end;

Sample image:

pascal
procedure TForm1.Button2Click(Sender: TObject);
var
  PDF: TBasicPDF;
  Bitmap: TBitmap;
  BitmapData: TBitmapData;
  ImgStream: TMemoryStream;
  I, J, PosX, PosY: Integer;
  Color: TAlphaColor;
  ColorRec: TAlphaColorRec;
begin
  PDF := TBasicPDF.Create;
  Bitmap := TBitmap.Create;
  ImgStream := TMemoryStream.Create;
  try
    Bitmap.LoadFromFile('image.png');

    if Bitmap.Map(TMapAccess.Read, BitmapData) then
    try
      for J := 0 to Bitmap.Height - 1 do
      begin
        for I := 0 to Bitmap.Width - 1 do
        begin
          Color := BitmapData.GetPixel(I, J);
          ColorRec := TAlphaColorRec(Color);
          ImgStream.WriteBuffer(ColorRec.R, 1);
          ImgStream.WriteBuffer(ColorRec.G, 1);
          ImgStream.WriteBuffer(ColorRec.B, 1);
        end;
      end;
    finally
      Bitmap.Unmap(BitmapData);
    end;

    PosX := (595 - Bitmap.Width) div 2;
    PosY := (842 - Bitmap.Height) div 2;

    PDF.AddImageRaw(PosX, PosY, Bitmap.Width, Bitmap.Height, ImgStream);
    PDF.SaveToFile('Image.pdf');
  finally
    ImgStream.Free;
    Bitmap.Free;
    PDF.Free;
  end;
end;