Author |
Topic |
|
zerob
167 Posts |
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 ); |
|
xequte
38627 Posts |
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
|
|
|
zerob
167 Posts |
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?). |
|
|
zerob
167 Posts |
Posted - Dec 03 2024 : 17:00:10
|
Where ppt := ImageEnView1.PdfViewer.ScrToPage( X, Y, True ); |
|
|
xequte
38627 Posts |
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
|
|
|
|
Topic |
|
|
|