You are not logged in.
Pages: 1
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
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
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;
Online
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
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
Pages: 1