Forum > LCL
Bug in procedure Image of the Class TJPFpdf
(1/1)
menegaz:
I think I found a bug in the Image of class TJPFpdf. When creating a PDF file, which had images both header and body, when inserting the image in the body, it was also placed in the header. I made some changes to the procedure and the error disappeared.
Original procedure:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- procedure TJPFpdf.Image(vFile: string; vX: double; vY: double; vWidth: double; vHeight: double);var i: integer; img: TJPImageInfo; flag: boolean;begin //Put an image on the page flag := False; if (Length(Self.pImages) > 0) then for i := 0 to Length(Self.pImages) - 1 do begin if (Self.pImages[i].filePath = vFile) then begin flag := True; img := Self.pImages[i]; break; end; end; if not (flag) then begin //First use of image, get info SetLength(Self.pImages, Length(Self.pImages) + 1); Self.pImages[Length(Self.pImages) - 1].imgSource := TMemoryStream.Create; Self.pImages[Length(Self.pImages) - 1] := GetInfoImage(vFile); Self.pImages[Length(Self.pImages) - 1].n := Length(Self.pImages); Self.pImages[Length(Self.pImages) - 1].filePath := vFile; img := Self.pImages[Length(Self.pImages) - 1]; end else //Automatic width or height calculus if (vWidth = 0) then vWidth := StrToFloat(FloatToStrF((vHeight * img.w / img.h), ffNumber, 14, 2, TPDFFormatSetings), TPDFFormatSetings); if (vHeight = 0) then vHeight := StrToFloat(FloatToStrF((vWidth * img.h / img.w), ffNumber, 14, 2, TPDFFormatSetings), TPDFFormatSetings); _out('q ' + FloatToStr(vWidth) + ' 0 0 ' + FloatToStr(vHeight) + ' ' + FloatToStr(vX) + ' -' + FloatToStr(vY + vHeight) + ' cm /I' + IntToStr(Length(Self.pImages)) + ' Do Q');end; //modified procedure: procedure TJPFpdf.Image(vFile: string; vX: double; vY: double; vWidth: double; vHeight: double);var j,i: integer; //modified img: TJPImageInfo; flag: boolean;begin //Put an image on the page flag := False; if (Length(Self.pImages) > 0) then begin for i := 0 to Length(Self.pImages) - 1 do begin if (Self.pImages[i].filePath = vFile) then begin flag := True; img := Self.pImages[i]; j:=i+1; // insert break; end; end; end; if not (flag) then begin //First use of image, get info SetLength(Self.pImages, Length(Self.pImages) + 1); Self.pImages[Length(Self.pImages) - 1].imgSource := TMemoryStream.Create; Self.pImages[Length(Self.pImages) - 1] := GetInfoImage(vFile); Self.pImages[Length(Self.pImages) - 1].n := Length(Self.pImages); Self.pImages[Length(Self.pImages) - 1].filePath := vFile; img := Self.pImages[Length(Self.pImages) - 1]; j:=Length(Self.pImages); //insert end; //else //Automatic width or height calculus if (vWidth = 0) then vWidth := StrToFloat(FloatToStrF((vHeight * img.w / img.h), ffNumber, 14, 2, TPDFFormatSetings), TPDFFormatSetings); if (vHeight = 0) then vHeight := StrToFloat(FloatToStrF((vWidth * img.h / img.w), ffNumber, 14, 2, TPDFFormatSetings), TPDFFormatSetings); _out('q ' + FloatToStr(vWidth) + ' 0 0 ' + FloatToStr(vHeight) + ' ' + FloatToStr(vX) + ' -' + FloatToStr(vY + vHeight) + ' cm /I' + IntToStr(j) + ' Do Q'); //modifiedend;
Is my change correct?
valdir.marcos:
It would be very pleasant, if you could edit your post and put your source code in "[ code=pascal] xxx [ /code]" without double quotation marks and spaces.
menegaz:
Okay, I've already modified the code.
Thank you
valdir.marcos:
Almost. :)
Use two "[ code=pascal] xxx [ /code]" for "original procedure" and for "modified procedure".
menegaz:
Ok. Na próxima vou fazer correto.
abs.
Navigation
[0] Message Index