I'm trying to print some A5 pages from a C# application but I'm getting unexpected results. The output is vertically offset by about 110mm so the output starts halfway down the page and is offset horizontally by about 20mm. The output starts off the left hand side of the page (so it's hard to measure the exact offset). The output is also clipped horizontally and vertically.
For example, a
dc.DrawRectangle (0, 0, 100, 100)
draws a box halfway down the page and half the box is missing due to being off the left hand edge. The size seems OK though.
I must be missing something really obvious but I can't quite see it myself. Does anyone know what might be causing these offsets?
This may provide a hint:
// Rectangle describes page minus margins.
Rect rectPage = new Rect(marginPage.Left, marginPage.Top,
dlg.PrintableAreaWidth - (marginPage.Left + marginPage.Right),
dlg.PrintableAreaHeight - (marginPage.Top + marginPage.Bottom));
// Draw rectangle to reflect user's margins.
dc.DrawRectangle(null, pn, rectPage);
From : Charles Petzold's Apps = Code With Markup
Related
I have a pdf that I want to grab a specific piece of info from.
My issue isn't how do I get it, my issue is I'm not under standing the coordinates of the rectangle.
I get the x,y, height & width, but not as it related to the actual page.
lets say for arguments sake I have a business letter with the date to the far right and address to far left. How do I grab the date?
ex:
(space space space space space space space space ) 01/02/2017
Mr Jones
some Address
blah, blah, blah.
Dear....
When ever I have tried to reference where I think the date should be, I end up with an empty value.
Thanks for any thoughts and or suggestions.
This is just one of the tries:
Rectangle rect = new Rectangle(96, 822, 72, 8);
This is harder than you might think.
Content isn't just placed on a page.
It's placed on a box on a page.
Both the content, the box, and the page are allowed to have custom transformations, and rotations.
And then of course there is the issue of how the coordinate system is defined. The origin usually lies in the bottom left corner. But this is again something that can be configured.
I would debug your problem by implementing a simple class that extends SimpleTextExtractionStrategy. In the method eventOccurred you should see events passing by of type TextRenderInfo. Those events contain the text being rendered and the bounding box. Print out the text, and its corresponding bounding box. Then at least you know where iText thinks your content is.
I really don't get how to adjust the right settings for printing.
Using OriginAtMargins makes my margins work, but Margin(0, 0, 0, 0) goes outside the paper size (which is 302x700), and drawing a rectangle using the PageBounds sets it in the center, with I estimate to have 1-inch margins, and the MarginBounds sets in at the center of the PageBounds which also has a 1-inch margins. And most of the time, the preview is very different from the printed one, especially at the margins.
When I'm not using OriginAtMargins, the PageBounds is the same as the paper size, and the MarginsBounds is set at the center with 1-inch margins. The problem here is that although the preview shows the contents nicely, the right side of the document is being cut off when printed, so I had to adjust the rectangle.
Overall, I can hard-code the "just right" sizes of the rectangle/margin, but there will be too much unnecessary estimates and trial-and-error.
My question is: What are the proper settings for printing? So that the preview and the printed is in sync, and what you coded is what you see, especially in sizes
I have a fragment for more options in my app that I want mostly hidden except for one small rectangle that says "Pull up for more options". This rectangle is parked at the bottom of the screen. When the user pulls it up, it then pops up from the bottom but NOT taking over the full screen, only about 1/3rd of the bottom. Just enough to show some of the options (checkboxes).
I am doing this and have it working by setting the TranslationY setting of the options fragment layout, which is in a FrameLayout container by the way, so that it is at the bottom of the screen and just shows my "Pull up for more options" text.
Then, when they pull up on that, I have some motion events to bring it up to where I want.
Here is the issue, I can get it working just fine on one display using hard coded TranslationY settings. For example, on a Galaxy S2 which has a density of 1.5 (HDPI 240) and a screen of 480x800, these are my hard coded values that work. I had to find them just by playing around with the numbers.
int trackOptionsHome = 650; //Parked at bottom of screen.
int trackOptionsExtended = 450; //Extended out where I want it to.
Again, with those hard coded values on the S2, it works fine and the way I want. However, if I now try a different device that is STILL HDPI (1.5/240) except the screen size is 480x640 (3.5in), it does not display properly which is to be expected. So then I implemented something like this:
float trackOptionsHome = ((dMetrics.HeightPixels / dMetrics.Density) + 120);
float trackOptionsExtended = ((dMetrics.HeightPixels / dMetrics.Density) - 100);
This was to try to take into account for different display density and sizes. I was then trying to do math at the end of each to position my fragment where I want it. However, I am getting inconsistent results and the numbers are still arbitrary. I have to find them by playing around.
This raises two questions:
1. How do I make sure I get the results I want on DIFFERENT display densities, which is not even the issue I am having at the moment since I have the same density.
2. How do I scale properly for the different size screens, which appears to be my immediate problem.
For math purposes at the moment (I can adjust as needed after I get an answer) let's say I want 50px of the fragment showing from the bottom when it is in the home position and 300px showing up from the bottom when extended.
What is the correct way to do this?
Thanks!
Mike
I'm working on a Winforms app that contains a large map image (5500px by 2500px). I've set it up so the map starts in full size, but the user can zoom out to a few different scales to see more of the map. The user is able to drag the map around to shift what they are looking at (like Google Maps, Bing Maps, Civilization, etc.).
When the map is full sized (scale = 1.0), I am able to prevent the user from scrolling past the borders of the image. I do this by calculating if they are trying to move past 0, or past the image width - current window size, similar to this:
if (_currHScroll <= 0) {
_currHScroll = 0;
}
This all works just fine. But, when I zoom out on the map (thus, making the image smaller), the limits for the bottom and right of the map break down. I know why this happens--because the Transform that is performed basically "compresses" the map a little bit, and so what used to be a 5000 px image is now smaller, depending on the scale. But, my limiters are based on the image size.
So, the user can scroll past the end of the map, and just sees white space. Worse things happen, I realize, but if possible I'd like to keep them from doing that.
I'm sure there is a straight-forward way to do this, but I haven't figured it out yet. I've tried simply multiplying my calculation by the scale, but that didn't seem to work (seems to under-estimate the size initially, then over-estimate on the smallest sizes). I've tried calculating the transform location of the bottom right of the image, and using that, but it turns out, that number is inverted, and I can't find what it relates to.
I'm including my transform point method here. It works just fine. It tells me, regardless of zoom level, what pixel was clicked on the original image. Thus, if someone clicks on point 200, 200 but the image is scaled at .5, it will show something like 400,400 as what was clicked (but, as I said, I don't think the scale value is a multiplier--using this just for demonstration purposes).
public Point GetTransformedPoint(Point mousePoint) {
Matrix clickTransform = _mapTransform.Clone();
Point[] xPoints = { new Point(mousePoint.X, mousePoint.Y) };
clickTransform.Invert();
clickTransform.TransformPoints(xPoints);
Debug.Print("Orig: {0}, {1} -- Trans: {2}, {3}", mousePoint.X, mousePoint.Y, xPoints[0].X, xPoints[0].Y);
return xPoints[0];
}
Many thanks in advance. I'm sure it's something relatively easy that I'm overlooking, but after several hours, I'm just not finding it.
If i understand right, you can calculate the maximum with your method GetTransformedPoint by using width and height from your Image as Point. The result can then be used inside your check...
And by the way, you are right, the scale value is a multiplier used as a factor. The only thing is, you have to cast the result to an integer.
Above is the image i am using. What i am trying to achieve is removing the red portion of the border from the image. How can I achieve this programmatically in windows phone? I found WriteableBitmapExtensions.Crop() method, but I am confused with the arguments (how i can find the x,y position of the image, as well as the size and the width?)
Also another issue I am facing is: I will get the images with differently sized borders, so I can't hardcode the x or y values.
Can anyone suggest a solution, or guide me to solve the issue?
This is not such a trivial thing and you haven't shared any code with us, so I can give you a few suggestions. Every WriteableBitmap has width and height defined. You should be able to access it via
wb.PixelWidth;
wb.PixelHeight;
where wb is your WriteableBitmap (the picture)
Having said that, it's trivial to crop a WriteableBitmap using WriteableBitmapEx library
var croppedBmp = wb.Crop(10, 10, 300, 220);
If your wb was 320x240 and the border was of width 10, then the above Crop call will do the trick - you will take the inner rectangle starting from point (10,10) and ending at (310, 230)
Now to your second issue - not knowing the width of the border. It would help if you know that
Border is of the same thickness on every side of the picture
Border is always in one color only
Assuming that's true, you could think of a simple algorithm (that may not be correct every time, but you can test it and adjust) which would take a few random points, for example
(0,randNumber < wb.PixelHeight), (randNumber < wb.PixelWidth, 0), (wb.PixelWidth, randNumber < wb.PixelHeight), (randNumber < wb.PixelWidth, wb.PixelHeight)
and then move towards the inner part of the picture as long as the neighbour pixel is the same color as the starting pixel. The more points you take randomly, the better chances you have of getting it right. The obvious problem with this is that it may happen that something on the picture is the same color as the border (exactly the same) which will make it seem like the border is wider than it really is. That's why you should take more points.
If you showed some code, I'd be happy to expand the answer.