You are not logged in.
Pages: 1
Hello:
My software need convet some jpg file to a pdf file,i try it to use the code:
procedure TForm1.Button2Click(Sender: TObject);
var
testpdf:TPdfDocumentGDI;
begin
testpdf:=TPdfDocumentGDI.Create;
try
testpdf.NewDoc;
try
testpdf.AddPage;
image1.Picture.LoadFromFile('c:\pictest.jpg'); //Image1: TImage;
testpdf.VCLCanvas.Draw(0,0,image1.Picture.Graphic);
finally
testpdf.SaveToFile('test.pdf');
end;
finally
testpdf.Free;
end;
end;
but i don't know the way is correct?
btw: should write more example to show how to use the componet
Offline
Sounds fine to me.
What's your problem with the above code?
You'd better use StretchDraw instead of Draw to force the dimension of the picture on the page.
Jpg files can have diverse dpi.
You can set some value to the ForceJPEGCompression property, in order to compress the image inside the pdf as jpeg, if you want to save some space.
If you leave the ForceJPEGCompression property to its default value (i.e. 0), it will embed the jpg as bitmap with deflate compression, which will create bigger pdf files.
Offline
I modify the code :
procedure TForm1.Button2Click(Sender: TObject);
var
testpdf:TPdfDocumentGDI;
tmprect:TRect;
begin
testpdf:=TPdfDocumentGDI.Create;
try
testpdf.NewDoc;
try
testpdf.AddPage;
image1.Picture.LoadFromFile('c:\pictest.jpg'); //Image1: TImage;
testpdf.ForceJPEGCompression:=30;
tmprect.Left:=0;
tmprect.Top:=0;
tmprect.Bottom:=image1.Height;
tmprect.Right:=image1.Width;
testpdf.VCLCanvas.StretchDraw(tmprect,image1.Picture.Graphic);
finally
testpdf.SaveToFile('test.pdf');
end;
finally
testpdf.Free;
end;
end;
the file of test.pdf isn't correct(The size of test.pdf is only 1k and Adobe Reader 9 can't open test.pdf);
Offline
Pages: 1