I generate a HTML-Page from C#. In the HTML-Page there are a lot of elements. All of them have a absolute position.
One of these elements is a table. This table represents a object that keeps a double[]. Every double value is a new cell in a new row.
I iterate over double[] and create my table:
for (int i = 0; i < dbl.Length; i++)
{
htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Td);
htmlTextWriter.Write(dbl[i]);
htmlTextWriter.RenderEndTag(); // td
htmlTextWriter.RenderEndTag(); // tr
}
If the table has so much elements, that it cross an element that is below this table, I have to be responsive to this issue.
This means, I need to know how many pixels this table is long.
Of course I do know how many cells I generate and I also know BorderSize, Padding, Margin, etc.
But there are two problems. First although I know FontSize, FontFamily, FontWeight, I do not know how to include these information into a mathematical calculation.
Second I think in every browser the actual size is also different. I created a dummy table and recognized, that in one screen height I already have one cell difference between Opera and Firefox.
So I think in C# I am only able to approximate the actual height?!
The next idea I have is to include a JavaScript into my HTML. I've no experience with JavaScript, but my approach would be to find my tables and read out size. Then iterate over all elements and find all overlappings.
My questions are:
Are my consideration true or do I miss some aspects?
Are my approaches the right way (in C# I only will get an
approximated result?!, JavaScript I do not know if it is really
possible what I want to do)
Are there other possibilities I do not see right now?
Hint: Other script languages than JavaSript are not applicable for my solution. JavaScript I only use if really necessary.
I think javascript is the answer, not c#.
http://api.jquery.com/height/
You cannot calculate the height in C#. Please use javascript to do this.
Related
Is there a way to set fixed height of an element? Could be a table, row or section. This element is dynamically generated from database and it can have a variable number of rows. I need to do that, because the section below needs to be in a fixed position for print out. I am using WPF v1.31. I know it is not the latest, but it's an addition to a quite old application.
You can set the height of a Paragraph or a table Row.
I think you cannot set the height of a Table - but that will be the sum of the heights of all rows. Automatic page breaks will make things complicated if a table does not fit a single page.
A Section always starts on a new page.
TextFrame can be used to place text at a fixed position. Depending on the requirements, this could be simple or complicated.
You can prepare a document to let MigraDoc determine sizes and positions. Then you code can decide whether the items with the fixed position will be on the same page or on a new page.
Here is sample code that shows how to show the progress while creating a PDF:
http://forum.pdfsharp.net/viewtopic.php?f=8&t=3172
The same technique can be used to stitch several MigraDoc documents together to create a single PDF. If I understand your requirements correctly, this could be the way to go - without setting the height of any elements.
I am working with Visual Studio 2010 ReportViewer WinForms.
I have been unable to figure out how to fix the rectangle height in a report. I've tried using a table within the rectangle, also a table in a sub report that is placed in the rectangle of the main report with no success.
Basically, I am setting up an invoice-type report that must keep its' form and should not be allowed to grow so that elements are pushed onto a second page.
Both rectangle and tables will always grow vertically based on the content. There is no way to really stop this.
There are a couple of properties that might be able to help you get the correct page breaking in place:
KeepTogether indicates whether to keep all sections of the data region together on pane page.
When set on true and the region is to large to fit the page, this will add a page-break before the start of the region to try and fit as much as possible on a single page.
So if you wish for the region to start at the initial location but break afterwards, make sure this is to false.
PageBreak has the parameter BreakLocation which can be used to determine a fixed place to add a page-break. You can set it on Start, End, StartAndEnd or Between.
You could split your report in fixed pages and use these to add standard page-breaks in the desired (fixed) locations.
These properties alone might not be enough to get your desired result. Especially when working with tables it is hard to add a page-break after a fixed amount of rows.
It is hard to give you a detailed description of a possible approach with the amount of information you gave me, but here is some general advice.
You should split your data in the correct intervals before sending the datasource to the reporter. You can for example use grouping to place them in the correct intervals and add page-breaks based on the grouping.
Another solution is to add them in separate containers, this will require you to have enough spare data regions at your disposal. If there are too many you can always hide the empty ones based on an expression set for the Hidden property.
It won't be easy to set this up correctly so that it can dynamically grow. It takes a lot of puzzling from your end but pretty much any layout should be possible to achieve.
I wish I could give you a more specific solution to your problem and am willing to help you further if you give me an example to work with. But ultimately this is something you should be able to achieve on your own.
I’m trying to calculate the width and height of child Layouts/Views based on the dimensions
of the ViewGroup that contains them.
I’m trying to factor in each childs’s margin value, but cannot seem to get this quite right.
I’ve tried every conversion under the sun (dip, sp, px, in, mm), but still come to the same conclusion, which is that margin values get converted to a much smaller pixel value than any of the other dimensional values
(ie, width & height).
I need this conversion factor. I’ve tried many things to calculate it (Context.Resources.DisplayMetrics - Density, DensityDpi, ScaledDensity), but haven’t been successful.
I don't believe that this conversion factor can be taken or derived from any values available at runtime,
and so was wondering if maybe someone knew what it was (or maybe where to find or calculate it).
To give some context, I'm implementing a custom calendar which contains a 5x7 grid of child-layout's (LinearLists), where each child has margins surrounding them.
The outer-most view is a RelativeLayout, which has a width and height of W and H respectively, and the margin width is M. Therefore, you'd think that
CELL_WIDTH = W/7 - M*7
CELL_HEIGHT = H/5 - M*5
However the margin width factors M*7 and M*5 end up being much too large, causing the overall grid to be smaller than the parent view (which is a problem, b/c I need to fill it).
I've tried a ton of different conversion techniques from posts here and elsewhere with no success. I'm convinced that there is some conversion factor that android uses to internally store the margin values (which I'm assuming is in pixels). It is this conversion factor I'm after (unless of course someone knows of a better/correct way to perform the calculation that I'm attempting here).
Here are the links I've tried, and I even converted one of the Java solutions to C# and am currently using it (though it did not solve this particular problem for me, it helped to shed a lot of light on it, and is helping elsewhere):
How to parse a dimension string and convert it to a dimension value
Oh my God I'm an idiot!
I've been tooling around for so long that I wasn't even considering the equation as being flawed.
For each cell size, I should only shave off 1 margin width/height, not all of them, which the current equation is doing.
So, the correct equations are:
CELL_WIDTH = W/7 - M
CELL_HEIGHT = H/5 - M
Ugh, I feel silly.
I set up a draw rectangle to draw simple formatted text first aligned to the left as
*item 1
[1]Something
content
[2]Something else
<a> subsomething else
content
<b> another subsomething else
content
*item 2
The end.
and I would also like it to automatically create a new column (after checking for the longest string in the first column [drawn stuff on the left hand side]) to draw the rest into it.
In order to keep track of the paddings and itemized sections and subsections, I think of using a stack which I can push and pop the current and next positions needed to draw a text line each time I leave a content. Yet, I can't figure out how to jump back to a certain subsection position because stack doesn't offer an inline sub-scripting method.
Then I look into a hash-map (in C# I have tried Dictionary) to keep track of it and to access the value via specific key. For that I also use a external global variable to maintain the number of subsections the user may have entered and increase one each time a new subsection is created; and the float value is used to store the x-coordinate value for the drawstring to be done. This is complicated to me at least at present when I don't really have a nerve to go into it anymore. I can only receive false simulated outcomes.
So I am asking for an easier approach to tackle this problem, which I think is simple to many of you sure experiencing the same situation. I am desperately looking forward to seeing a short easy method to do this.
Draw formatted text using ..
..whatever works. I suggest a JLabel, which will render (simple) HTML/CSS formatted content.
See LabelRenderTest.java for an example.
I'm trying to figure out if it's possible to calculate the area of a HTML element on a website? In pixels, as a percentage or whatever.
My first thoughts have been to make the assumption that the element is 100% in width and height, and then try to retrieve the size through a mapping between the HTML and CSS.
So if there's a width/height attribute in the referenced CSS-file I could possibly say that
the body element is covered by a column that takes 25% of the area (everything is based on your screen resolution of course - and I'm still trying to figure out how I'd be able to do this programmatically).
Or whether I should render the website and do my calculations based on an image with the most common screen resolution at the time).
Are there any more possible solutions?
(Currently I'm trying to solve this in Perl, but I suppose any language that's got a library for this purpose would be appreciated to know about!)
EDIT: I need to retrieve the visual area for every single element on a page.
For example; if there are elements on top of the <body> element, that covers it visually, I want to exclude that area from the <body>'s and so on. A simple raytracing to find the visible area for every element on a page.
EDIT: Let's say we exclude JavaScript - any other approaches possible?
Personally, I would use jQuery - even if you don't use a library, your best bet will be a JavaScript solution.
var $elt = $('#some-element-id'),
height = $elt.height(),
width = $elt.width(),
area = height * width; // contains the area in px^2
http://api.jquery.com/height and http://api.jquery.com/width
This is such a simple problem I don't think JQuery is necessary if you are not already using it.
Try running this:
<div id="myParent">
What's up?
<div id="myDiv">Hello there!</div>
</div>
With
var myDiv = document.getElementById("myDiv");
alert(myDiv.offsetHeight);
alert(myDiv.offsetWidth);
var myParent = myDiv.parentNode;
alert(myParent.offsetHeight);
alert(myParent.offsetWidth);
Divide resulting widths to get % of space the element takes in it's parent, or simply use the absolute pixel values.
I would recommend using jQuery to do it if possible.
alert('Size: ' + $('li').size());
http://api.jquery.com/size/
Would it be feasible to use javascript? If so you can get the width/height with something like this:
document.getElementById(YourElementsId).style.height;
document.getElementById(YourElementsId).style.width;
However this does depening on how the elements are sytled in the first place. Another option would be
document.getElementById(YourElementsId).clientHeight;
document.getElementById(YourElementsId).clientWidth;