Watermark: Positioning an image

  • Hello,
    We're having troubles with positioning an watermark image in a specific X & Y coordenates. We're tryng to get the coordenates from the cursor position using the GetYPositionTw, GetXPositionTw and using this information to set the Canvas.StretchDraw to print the image, but is not working. The image is not at the exactly position, and there are some randomic results.
    Please, help us! We need an example!

  • Thank you, Julian, for your help, but i guess my explanation was not good. In fact, what we're trying to do is:

    Based on a position of a word inside the text, we're positioning the cursor exactly at the first letter of this word and getting the X & Y coordenates based on the functions GetYPositionTw and GetXPositionTw. Then, we put the following code in the event OnPaintPage:


    With this code, we're having troubles positioning the image. Sometimes the image is in the correct place, sometimes not. What we have to do to put the image always at the correct place?

    • Offizieller Beitrag

    Hi,

    I see this code:

    y := round(topMargin * 37.15) + round(WPTwipsToCentimeter (WPRichText1.GetYPositionTw) * 0.5);
    x := round((leftMargin * 37.15));

    This does not look right for two reasons.

    a) You should keep the topMargin in twips and calculate the y like this:
    y := MulDiv( topMargin + twipspos, yres, 1440)

    b) WPRichText1.GetYPositionTw makes no sense here. The position of the cursor is absolutely random when this event is triggered.

    If you need to place an image at a certain position you need to store that position with the image, use its position in place of 'twipspos' in the formula above. You will also need to store the page number and find the image for tbne correct page.

    Better use WPTools 5 - it has a very stable support for images placed at a fixed position on a page and that can be also moved interactively - and flickerfree..

    Julian

  • Thank you, Julian! It works very well! Now we got the correct result and our users are very thankful! We're using WPTools since 2K year and there's nothing better in the world to RTF edition. Your component is fantastic and we like to give you congratulations for this great work. Now, we are not using the Microsoft Word in our company 'cause we developed an entire editor based on WPTools, with almost every functions of the Microsoft product! We're showing your solution to many others companies, and we're always asked about a version of WPTools for JAVA. Are you thinking about that?

    Thanks,
    Rodrigo