ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 PDF coordinates

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
zerob Posted - Dec 02 2024 : 03:32:33
Hi Nigel
Im a bit lost on how to work with PDF coordinates.
I wanted to place something on a PDF on MouseDown or simply x pixels or CM in the PDF.

I tried different things:
"PdfViewer.ScrToPage"
Tried to to a x = x y = PdfViewer.PageHeight- y;
PdfViewer.YScr2Page(y);
PdfViewer.PageHeight - PdfViewer.YScr2Page(y)
y / 72
y * 72

Im completely confused and have already looked at the help (which talks about some ominous "adobe points" and some functions, and at the demos, but nothing helped.
With all tricks i either get it completely off, or really near the cursor, or only moving a few pixels, even with large mouse movements, somehow stuck to the same area.

How do i exactly get a mousedown point to the pdf and how do i get a measured lets say 15 cm from the top and left to the pdf?

So in one case i can place something exactly by mouse and in another case i can measure in real world, my A4 paper and decide to put something in 15cm top 15cm left and get that on printing. So how to convert the MouseDown x,y value or some random predefined pixel value (50 pixels in) or some real world CM (centimeters) on the PDF?

In working with ImageEn and digging through demo's and code completion while exploring the possibilities of ImageEn in different areas, i every now and then encounter functions that aren't in the helpfile like these for example:
ImageEnView1.PdfViewer.YScr2Page
ImageEnView1.PdfViewer.XScr2Page
Are these and others not to use and "hidden" on purpose, or did such functions just slip through the helpfile generation?

And also the Help entry for AddImage has a bug adding f and Y to the code:
ImageEnView1.PdfViewer.Objects.AddImage( f100, 800Y, 200, 200, dlgOpenImage.Filename );
8   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Dec 05 2024 : 19:18:24
Hi

I'm not seeing that here, but I expect it will be occurring the PDFium calls (loading a small image like that is unlikely to be slow).



Nigel
Xequte Software
www.imageen.com
zerob Posted - Dec 05 2024 : 06:35:01
Oh, i didn't notice that the image wasn't really square.
I did load a transparent image before and because it was hard to position (to see if the code works),
i filled it with red and renamed it to "square.png".
I overlooked the non square part ;-)

Is the 2-3 second delay from clicking till the image appears some internal PDF Engine stuff that is slow, or do i do something wrong?

Thank you very much.
xequte Posted - Dec 04 2024 : 23:15:55
Hi

The issue here is that you have set MaintainAspectRatio=True, so although the size is specified as 200x200, to maintain the aspect ratio of your non-square image, it is output at 200x176, i.e. away from the cursor.

It works correctly if you don't enable MaintainAspectRatio:

ImageEnView1.PdfViewer.Objects.AddImage(ppt.X,ppt.Y-200,200,200,'.\square.png', False);


To MaintainAspectRatio, what is needed is to offset the Y by the height of the *scaled* image:

procedure TForm1.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
const
  Display_Width  = 200;
  Display_Height = 200;
var
  clickPos: TDPoint;
  bmp: TIEBitmap;
  sz: TPoint;
begin
  clickPos := ImageEnView1.PdfViewer.ScrToPage( X, Y, True );
  bmp := TIEBitmap.Create( '.\square.png' );

  // What size is it when scaled?
  sz := GetImageSizeWithinArea( bmp.Width, bmp.Height, Display_Width, Display_Height );

  ImageEnView1.PdfViewer.Objects.AddImage( clickPos.X, clickPos.Y - sz.Y, Display_Width, Display_Height, bmp );
  bmp.Free();
end;


Nigel
Xequte Software
www.imageen.com
zerob Posted - Dec 04 2024 : 02:59:24
It still is not touching the cursor but moved too far below the cursor.
Im sending you a demo by mail.
xequte Posted - Dec 03 2024 : 17:42:43
Hi

What is the size of your image?

This works fine for me:

// Add an image wherever user clicks on a PDF page (position image so click position is at the top-left)
procedure TfrmMain.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  clickPos: TDPoint;
  bmp: TIEBitmap;
begin
  clickPos := ImageEnView1.PdfViewer.ScrToPage( X, Y, True );
  bmp := TIEBitmap.Create( 'D:\pix100x100.bmp' );
  ImageEnView1.PdfViewer.Objects.AddImage( clickPos.X, clickPos.Y - bmp.Height, bmp.Width, bmp.Height, bmp );
  bmp.Free();
end;


Nigel
Xequte Software
www.imageen.com
zerob Posted - Dec 03 2024 : 17:00:10
Where ppt := ImageEnView1.PdfViewer.ScrToPage( X, Y, True );
zerob Posted - Dec 03 2024 : 16:56:47
Thanks for the code.
When i do the following code, then the square.png is correct on the X position, but the Y position is facing upward.
When i try to make it facing downward by adding the height, it isn't touching the cursor, but it is far away on the Y axis.
ImageEnView1.PdfViewer.Objects.AddImage(ppt.X,ppt.Y,200,200,'.\square.png'); // facing up and right from the cursor
ImageEnView1.PdfViewer.Objects.AddImage(ppt.X,ppt.Y - 200,200,200,'.\square.png'); // try to face down and right like normal on windows but it isn't touching the cursor on the Y axis but is farther down (about 31 pixels?).
xequte Posted - Dec 02 2024 : 19:12:18
Hi

Did you try the demo:

\Demos\Testing\PDF\PDFPageObjects\PDFPageObjects.dpr

PDF points are values in the range (0,0) to (PageWidth, PageHeight). The values are Bottom-Up, so (0,0) is the bottom-left of the page, and (PageWidth, PageHeight) is the top-right of the page

See the examples at:

https://www.imageen.com/help/TIEPdfViewer.ScrToPage.html

// Add a spot wherever user clicks on a PDF page
procedure TfrmMain.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
const
  Spot_Size         = 20;
  Spot_Border_Color = clBlack;
  Spot_Border_Size  = 2;
  Spot_Fill_Color   = clRed;
  Spot_Opacity      = 255;
var
  clickPos: TDPoint;
  obj: TPdfObject;
begin
  clickPos := ImageEnView1.PdfViewer.ScrToPage( X, Y, True );

  // Center ellipse over click position
  obj := ImageEnView1.PdfViewer.Objects.AddEllipse( clickPos.X - Spot_Size div 2, clickPos.Y - Spot_Size div 2, Spot_Size, Spot_Size );

  obj.StrokeColor := TColor2TRGBA( Spot_Border_Color, Spot_Opacity );
  obj.PathStrokeWidth := Spot_Border_Size;
  obj.FillColor := TColor2TRGBA( Spot_Fill_Color, Spot_Opacity );
  obj.PathFillMode := pfAlternate; // Ensure path is filled
end;


Nigel
Xequte Software
www.imageen.com