I've been googling for the past couple days on how to convert mouse coordinates to pdf units & this has proven to be very difficult...or at least I haven't been able to find it. I have an X,Y pixel coordinate and I have to place stamp in a pdf document in that location. I've found out that pdf units are different & start from the bottom.
I've tried;
point=pixel * 96 / 72.....also tried a few other options like pixel * 150/72 & pixel * 72 / 300.
While the last attempt produced my results for the X coordinate my Y is way off. An example I have is;
x:1341
y:294
I can't believe I'm the first to encounter this so I'm hoping someone can help me out.
Thanks for your inquiry. After initial investigation, we have logged an investigation ticket as PDFNEWNET-36812 for your requirements. We will keep you updated about the issue progress via this forum thread.
Moreover you are right that PDF coordinates starts from left bottom(0,0) and right top is (page width, page height). Aspose.Pdf measuring unit is point and where 1 inch = 72 points and 1 cm = 1/2.54 inch = 0.3937 inch = 28.3 points.
Thanks for contacting support and sorry for the delayed response.
The page height and width properties use points as the basic unit, where
1 inch = 72 points and 1 cm = 1/2.54 inch = 0.3937 inch = 28.3 points. When dealing with images, the conversion from point to pixel depends on an image’s DPI (dots per
inch) property. For example, if an image’s DPI is 96 (96 pixels for each
inch), and it is 100 points high, its height in pixels is (100 / 72) *
96 = 133.3. The general formula is: pixels = ( points / 72 ) * DPI.
As per your scenario, you may skip the DPI part and get pixels converted to points using above stated formula.
I have the pixels in the mouse coordinates....X:1341 & Y:294 which places the point in the upper right corner.
I thought the formula was points = pixels/72 * DPI but you have points & pixels switched around a little. I need the point value correct? If I use points=pixels/72 & drop the DPI that puts it at 18 & 4 which is way off. I know that the value needs to be around 300/690 for this particular entry.
In order to calculate the point position inside PDF document based on mouse coordinates, you my consider using following formula. Please note that pdfx is x coordinate inside PDF file and pixelX is mouse X coordinates over screen.
pixelX = (pdfX/72)* DPI
pdfX = pixelX * 72 / DPI
Where DPI is screen resolution and usually its 96 can be calculated programatically.
As you can see by my first post, I've tried your calculation. I am using MVC so I don't have the liberty of using Graphics g = this.CreateGraphics();....or I haven't been able to get it to work on a view.
In my example numbers and using your example...
X = 1341 * 72/96 = 1005.75 which is outside of the page.
Y= 294 * 72/96 = 2.31 which would put it at the bottom of the page.
X;1341, Y294 is a mouse point at the top right of the page.
As you can see, the points are way off. Am I the first to attempt this? I would have thought this would be fairly standard. Should I take a completely different approach? I do see that one of your competitors has this functionality build in;
I was hoping for something similar or a workaround to this. I am trying to create a pdf from items that are added to a canvas which contains the original pdf. I could easily create an image from the canvas & just add the image to a pdf but from my experience the image becomes blurry or distorted when printed. Which is why I wanted to attempt to use the original pdf & add the stamps....but if I cannot place them in the exact location of the mouse coordinates then I will have a major issue.
As you can see by my first post, I’ve tried your calculation. I am using MVC so I don’t have the liberty of using Graphics g = this.CreateGraphics();…or I haven’t been able to get it to work on a view.
In my example numbers and using your example…
X = 1341 * 72/96 = 1005.75 which is outside of the page.
Y= 294 * 72/96 = 2.31 which would put it at the bottom of the page.
X;1341, Y294 is a mouse point at the top right of the page.
As you can see, the points are way off. Am I the first to attempt this? I would have thought this would be fairly standard. Should I take a completely different approach? I do see that one of your competitors has this functionality build in;
I was hoping for something similar or a workaround to this. I am trying to create a pdf from items that are added to a canvas which contains the original pdf. I could easily create an image from the canvas & just add the image to a pdf but from my experience the image becomes blurry or distorted when printed. Which is why I wanted to attempt to use the original pdf & add the stamps…but if I cannot place them in the exact location of the mouse coordinates then I will have a major issue.
Hi Steve,
Thanks for sharing the details.
I
have logged an investigation ticket in our issue tracking system as PDFNEWNET-36826. the development team will investigate this
issue in details and will keep you updated on the status of a correction. <o:p></o:p>
Thanks for your inquiry. I am afraid we have recently noticed the issue and investigation of issue is still pending due to other priority tasks. However, we have requested our development team to investigate it and share their finding at their earliest. We will notify you via this forum thread as soon as we made a significant progress towards issue resolution.
Furthermore, you may also share complete information of the scenario and issue you are facing, by sharing sample PDF document and code snippet. We will test the scenario in our environment and address it accordingly.
Please note that Aspose.PDF HTML5 Editor was just a demonstration and example of how you can use API features in order to display PDF files in HTML Canvas and perform some basic operations over them. As it was not product offered by the Aspose, we have discontinued it and are not maintaining it for further issues and updates.
Usually, the editor application used to convert PDF pages into images and display converted images in HTML Canvas for further operations (e.g. stamping, annotating, commenting, etc.). Since the coordinates were being calculated with respect to rendered image, stamp in output PDF document was expected to be appeared at different coordinates. Please note that this behavior of the application may also be document specific.
We would like to request you to please try specifying desired coordinates for image stamp directly inside PDF using Aspose.PDF API and in case you still face any issue with output PDF document, please let us know by sharing the values of coordinates. We will test the scenario in our environment and address it accordingly.
Would you please confirm if you have tried adding stamp in PDF using Aspose.PDF for .NET Library in a separate program with same parameters.
In case stamp is not appearing at desired position even using Aspose.PDF for .NET separately, please share the sample image file which you are using for stamp. We will test the scenario in our environment and address it accordingly.
We have added an image stamp using above parameters and following code snippet in our environment. For your kind reference, an output PDF is also attached.
string sImageUrl = dataDir + "signature.png";
Document pdfDoc = new Document(dataDir + "86_ebrochure.pdf");
ImageStamp imageStamp = new ImageStamp(sImageUrl);
imageStamp.Height = 60;
imageStamp.Width = 200;
imageStamp.XIndent = 368.7624750499;
imageStamp.YIndent = 335.131782945737;
//add header on all pages
foreach (Page opage in pdfDoc.Pages)
opage.AddStamp(imageStamp);
//save updated document
pdfDoc.Save(dataDir + "86_ebrochure_output.pdf");
Would you please check the output and point out the desired location where you want to display the stamp by sharing a screenshot with some annotations. We will try to add stamp over desired location inside PDF document and share our feedback with you.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.