You are not logged in.
Pages: 1
I guess the bitmap should not be drawn at all... what do you think?
In my case, I do have such a bitmap that contains information I need on the pdf (might seem silly, but that's how it is, and I have to work with that). So just not drawing is not an option for me.
AFAIR it is because PDF boxes coordinates expect that.
I'll try to look further into that later this week, it seems a bit peculiar.
Hi,
after having used SynPDF for years without any issues, I stumbled upon a small problem today which leads to corrupted PDFs. I found out what's happening, but not sure about the proper solution.
So basically, my application tried to create a pdf that contains a Bitmap with a height of 1 pixel. In the procedure TPdfEnum.DrawBitmap, the bitmap size R is rescaled to variable Box in the function BoxI/RectI. But this rescaling results in a height of 0, which then leads to a corrupted PDF file (often, the PDF ends up corrupt, and if not, it usually does not continue drawing any elements that were added after the bitmap).
1. Why are both the right and bottom coordinates for variable Box shifted by -1 in function RectI?
2. Maybe there should be some error handling when height or width of the variable Box is 0, or the bitmap should not be drawn at all?
See the code section below. variable ClipRc is checked if it's actually a valid rectangle, but variable Box is not.
// draw the bitmap on the PDF canvas
with Canvas do begin
R := Rect(xd, yd, wd+xd, hd+yd);
NormalizeRect(R);
Box := BoxI(R,true);
ClipRc := GetClipRect;
if (ClipRc.Width>0) and (ClipRc.Height>0) then
Doc.CreateOrGetImage(B, @Box, @ClipRc) else // use cliping
Doc.CreateOrGetImage(B, @Box, nil);
// Doc.CreateOrGetImage() will reuse any matching TPdfImage
// don't send bmi and bits parameters here, because of StretchDIBits above
end;
Hi MtwStark,
Thanks for your fixes. I have used my workaround for years now, but I'll look into this when I get the chance.
Hi Tom,
sorry for my delayed answer.
Yeah I noticed that problem, that's why i mentioned it works for a single clipping rectangle only. I couldn't figure out yet how to resolve that issue unfortunately.
Well right after I posted the above message, I guess I found part of the bug. I made a quick fix that works, at least for a single clipping rectangle.
In SynPdf.pas in the function EnumEMFFunc, change the EMR_INTERSECTCLIPRECT statement:
EMR_INTERSECTCLIPRECT:
begin
ClipRgn := e.IntersectClipRect
(e.Canvas.BoxI(PEMRIntersectClipRect(r)^.rclClip,
true), ClipRgn);
e.Canvas.Clip;
with e.Canvas.BoxI(PEMRIntersectClipRect(r)^.rclClip, true) do
e.Canvas.Rectangle(Left, Top, Width, Height);
e.Canvas.EoClip;
end;
Furthermore, I noticed a bug in TPdfCanvas.EoClip, instead of upper case W, lower case w should be added to the stream, so:
procedure TPdfCanvas.EoClip;
begin
if FContents <> nil then
// FContents.Writer.Add('W*'#10);
FContents.Writer.Add('w*'#10);
end;
Hi,
I'm getting great results with this library, it made generating a Pdf really easy. But I also noticed that clipping for EMF is not supported. So far I managed to get around with a hack, but now I'm looking for a proper solution.
Would be great to see an update on that soon.
Cheers
Pages: 1