I've got a WinForms application that brings in an image into a picturebox and I allow the user to click on the control to add a "stamp" at that point on the image. When the user is finished, each "stamp" location is stored in an XML for use elsewhere in the application where the stamps are redrawn (as to not alter the original image) in the locations specified beforehand.
Now, my problem is that these locations are in terms of pixels and originally I noticed that certain computers would display the redrawn "stamps" differently than the original computer. I did a little research and found that the DPI settings could help solve this issue. So, I've tried adding code to offset this issue, but it doesn't appear to be working correctly. Here are my steps:
When the form initializes, I grab the current computer's DPI using Me.CreateGraphics().DpiX and Me.CreateGraphics().DpiY. I also grab the original computer's graphics stored in the XML file
For each "stamp" stored in the XML file, I set the desired location in a Point variable by using a similar calculation as this:
New Point(Stamp.X * (dpiX / dpoX), Stamp.Y * (dpiY / dpoY)) where dpi? is the current computer and dpo? is the original computer
Am I going at this the right way, or is there an easier way to tackle this problem?
Related
I'm trying to make an image file from a control using CopyFromScreen, and it fails unless I set the scale to 100%. With a larger scale the image is progressively offset left and up, the further right and down the window is on the screen. (Unfortunately my eyes struggle at 100%)
I initially tried using DrawToBitmap but that fails as there's a rich text box in the control and it's documented that that won't paint.
I've read articles on this forum and followed the suggestion of including the dpiAware setting in the manifest, but that has no effect. I'm no expert and I'm wondering if it's because I only have VS 2012 and my manifest declaration starts with asmv1 rather than asmv3 so I had to amend the example code?
Any suggestions most welcome.
My company licenses both iTextSharp and PdfTools. Trying to figure out the root cause I built Apache's PdfBox: All show the same behavior, so rather than creating two support requests and a post on the PdfBox list I'm trying SO first for the general problem.
For a real world PDF (according to the document's properties it was created by "SAP NetWeaver 740") all extracted text coordinates are way off, while the content is fine. Across all the tools I listed above:
The page size (as in, mediabox and cropbox) is 842.0 x 595.0 - a portrait invoice. My default test word (all are off, but that's the one that caused my investigation) starts at roughly 80% in. All tools report the coordinates of that text with x=778 - outside of the page bounds. The y coordinate seems to be fine though. Probably related, the width is off (too wide by a large margin) while the height is again fine.
Now, maybe the PDF is broken in some way. But then again: The text is rendered fine of course. If I select the text in - say - Acrobat Reader, that works fine (i.e. the selection rectangle matches the text on the screen). And I assume that SAP generates rather bland/unsophisticated documents, tbh.
I guess my question boils down to: Under which circumstances would text appear to be outside of the page's boundaries? What might cause the horizontal position to be totally out of whack (and always too large)?
I'm trying to use an external image on a report in my application. It's a windows application form.
The property EnableExternalImages of localreport is True
The source of image is External
As value i'm trying this. file:///C:\image.png
I can see the image on the report from visual studio designer, but when I run my application I can't see the image on the report but only a red X.
What can I do?
UPDATE
I tried the same on a different computer and it works good. So the problem is with my laptop. Any idea?
I had a similar problem and spent two solid days finding a solution. In my case, I was using Dataset objects to populate the data on the report. So, before I refreshed the report, I saved the image into an array of bytes, then on the report set the image source to "Database", selected the corresponding Dataset object, then chose the column that contained the array of bytes. The images appeared in the report when viewing it in both a ReportViewer object and as a PDF file.
maybe its a permission problem? try from your laptop, put the image in a different location where permission is not needed like in documents folder and see if issue still the same.
What I am ultimately trying to do is to create a grid of images for print that are minor variations of the same thing (different text is all). Looking through online resources I was able to create a script that changes the text and exports all of the images necessary (several hundred). What I am trying to do now is to import all of these images into a new photoshop document and lay them all out in a grid and I can't seem to find any examples of this.
Can anyone point me in the right direction to place a file at a specific coordinate (I'm using CS5 and have the design suite so if there is a way in illustrator to do this quickly...)?
Also, I'm open to other ideas on how to do this (even other programs) easily. It's for labels so the positioning on the sheet has to be pretty precise...
The art layer object has a translate() method that takes delta x and y params. You'll need to open each image, copy it to the target document, get its current location (using artLayer.bounds) and do the math to find the deltas to position it where you want it. Your deltas can be in pixels so you'll get plenty of precision.
Check out your 'JavaScript Scripting Reference' pdf in your Adobe install directory for more details.
Ok I'm marking Anna's response as the answer because though I didn't fully test it, it seems like it should work and answers the original question with jsx. However I'm also leaving my final solution in case anyone else runs across this with the same issue and may prefer this method as well.
What I ended up doing instead is using InDesign. I figured out that it has a grid option that lets you import a number of files and place them all in an equal grid in a single command. This is almost exactly what I was looking for, except that it leaves a small border/margin in between the columns and grids and mine were designed to meet exactly.
I couldn't figure out how to make it not have the border (I have very little experience with InDesign, it may be possible). However I was able to select all my images and scale them uniformly to be the correct size, then I just selected each column and dragged it over to snap to the adjacent column and the same with rows...
I am currently using an excel macro (although I will switch to VB.NET if necessary) to loop through all of the text in a PDF and populate an array with certain portions of the text in the PDF (via the Adobe SDK and getPageNthWord). This part is working just fine, but now what I want goes a step further.
There are certain portions of the PDF where just grabbing the text isn't giving the full picture, and I'd like to see what more I can get. This is exactly the screenshot or snippet I am trying to get:
So, I know that I could use getPageNthWordQuads to find the coordinates for the words "Compliance Warning" and I could figure out a way to find the bottom right of the screen as well, but my problem starts there. After I get those coordinates what would I do with them? Can I zoom in the PDF to only see that portion and then take a screenshot? I already have the code for a screenshot of the activewindow, but I don't know how to scroll or zoom on a PDF.
Any help would be greatly appreciated. A fresh approach would be welcome as well. Thanks!
There are probably a number of approaches that would work - I don't know enough about your environment / constraints to know for sure which would work best. I'm assuming you are talking to Acrobat through OLE here.
1) You can open a window, get its AVPageView and ask it to zoom and move to where you want it to do your thing.
2) You can open a PDF document in one of your own windows using OpenInWindowEx and then grab the contents of that window (the advantage being that this window could be off screen).
3) You can use the DrawEx method (in AcroExch.PDPage) to render a specific portion of a page into your own window and then process that.