#1 2016-09-14 14:41:16

aforsprl
Member
Registered: 2016-09-09
Posts: 3

bitmaps or jpg images

Hi Folks.

I recently started to use the Synopse pdf engine. As far as text is concerned, so far so good. Problems arise when I try to put some image files into the pdf document either bmp's or jpg's.
In fact I cannot fix which is the right sequence of procedures or functions to use.
The second problem concerns the different pixel density between the images and the pdf canvas (either the canvas or the VCLCanvas).
An answer will be appreciated, thanks.

Antonio.

Offline

#2 2016-09-14 16:20:52

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: bitmaps or jpg images

How do you create the pdf?
From a VCL TCanvas / TMetatfileCanvas ?
Directly from TSynPDF Canvas?

Offline

#3 2016-09-15 08:16:50

aforsprl
Member
Registered: 2016-09-09
Posts: 3

Re: bitmaps or jpg images

Hi.
There are the two code snippets:
1. pdfdocument.Canvas
procedure ...
var
  lPdf   : TPdfDocument;
  bmp: TBitmap;
  wNom: PDFString;
  wBox: TPdfBox;
begin
  lPdf := TPdfDocument.Create;
  try
    lPdf.Info.Subject := 'test document PDF';
    lPDF.Canvas.SetFont('Helvetica',10.0,[fsItalic]);
    lPdf.Canvas.BeginText;
    lPdf.Canvas.TextOut(100, 450,  '100,450 et la troisième zone Helvetica');
    lPdf.Canvas.EndText;
    ....
    bmp := TBitmap.Create;
    try
      bmp.LoadFromFile('c:\Data\David\Files\Petit sigle.bmp');
      wBox.Left := 250;
      wBox.Top := 620;
      wBox.Width := bmp.Width;
      wBox.Height := bmp.Height;
      wNom := lPdf.CreateOrGetImage(bmp, @wBox, nil);
      lPdf.Canvas.DrawXObject(250, 620, wBox.Width, wBox.Height, wNom);
    finally
      bmp.Free;
    end;
    if EFileName.FileName <> EmptyStr then
      lPdf.SaveToFile(EFileName.FileName);
  finally
    lPdf.Free;
  end;
---
All texts using the Canvas.TextOut works fine. The output from the bitmap is rubbish.

2. TVclCanvas:
procedure ...
var
  MyX, MyY: Integer;
  MyString: String;
  lPdf   : TPdfDocumentGDI;
  lPage  : TPdfPage;
  Top, Left: Integer;
  wFontSize: Integer;
  bmp: TBitmap;
begin
  lPdf := TPdfDocumentGDI.Create;
  try
    lPdf.ScreenLogPixels := 600;
    lPage := lPDF.AddPage;
    // à 6 ligne/in 600 / 6 = 100 dpi/ligne
    wFontSize := lPDF.VCLCanvas.Font.Size;
    lPdf.VCLCanvas.Brush.Style := bsClear;
    lPdf.VCLCanvas.Font.Name := 'Arial';
    lPdf.VCLCanvas.Font.Pitch:= fpDefault;
    MyString := Format('100,100 texte de la première ligne, interligne:%d, fontsize:%d', [il, lPDF.VCLCanvas.Font.Size]);
    ....
    MyX := 100;
    MyY := 100;
    lPdf.VCLCanvas.TextOut(MyX, MyY, Mystring);
    bmp := TBitmap.Create;
    try
      bmp.LoadFromFile('c:\Data\David\Files\Petit sigle.bmp');
      Top := 200;
      Left := 200;
      lPdf.VCLCanvas.Draw(Top, Left, bmp);
    finally
      bmp.Free;
    end;
    if EFileName.FileName <> EmptyStr then
      lPdf.SaveToFile(EFileName.FileName);
  finally
     lPdf.Free;
  end;
----
In this case the bitmap is rendered but the image size does not look the original bitmap sizes, maybe some scale factor
I wonder if some stretching can be done in a rectangle.
Another strange behaviour in this case, is that when the pdf is saved, the main form of the program is altered in position and size !!
I imagine that the canvas of the main form it altered in some way. The main window moves as the Top value changes

Antonio.

Offline

#4 2016-09-15 11:09:54

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: bitmaps or jpg images

1. Please do not post huge code in the forum directly, as stated by the forum rules.
Use an online site like PasteBin or similar.

2. Following lines may change your main form size...

      Top := 200;
      Left := 200;

Offline

#5 2016-09-15 12:11:48

aforsprl
Member
Registered: 2016-09-09
Posts: 3

Re: bitmaps or jpg images

I'm really confused.
I didn't notice that those variables without named reference are relative to the main form, the implicit object.
Sorry for this, please be indulgent cool
VclCanvas plays very nicely. With a look at the code itself, I've seen that the VclCanvas plays with the TGraphic component. My stretch problem is solved too.
Thanks a lot.

Antonio.

Offline

Board footer

Powered by FluxBB