Header using Itext - html

ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(headerContent,headerFont) ,document.right() - 300, document.top() + 5, 0);
I have this line of code.For A4 papersize I get the header at the center of the page but for A3,A2,A1 I get it to the left of the page.What should I do so that I get it to the center of the page for all papersize(A4,A3,A2,A1).

You should use (document.left() + document.right()) / 2 for the x value.
As for the y value, you should use document.top() - (headerFont.getSize() * 1.5f). As far as I know document.top() + 5 results in adding text in the invisible area above the actual page.

Related

Incorrect display of TEXT in SVG

The code that generates SVG:
"<text x=\"" + (Width / 2) + "\" y=\"18\" width=\"30\" text-anchor=\"middle\" font-weight=\"Bold\" font-family=\"Simplex\" font-size=\"7\">" + "123" + "</text>"
The code is looped so it displays repeatedly
What's wrong with this text?
Conclusions:
centers the first digit
other elements start at the beginning of the element
When I remove the text-anchor, it changes a little but it still displays incorrectly
The problem is probably division by 2 (Width / 2)
You get a floating point value, which means that the separator is , instead of . in String Value
Use:
(Width / 2).ToString("0.00", CultureInfo.InvariantCulture)

Changing label height property dynamically

I have a line of code:
Label11.Style["Height"] = (Label11.Height.Value + 15).ToString() + "px";
I populate the Label with text, each time I'm doing it I would like to increase the height of the Label by 15 px.
After the first populate it works fine (Height = 30), but after that it didn't change.
What am I doing wrong?
Finally, I managed to find the solution:
Label11.Height = new Unit((int)Label11.Height.Value + 15);

Using matchbox to insert PDF in text flow Yes or No?

I am using matchbox to insert images into text_flow which is working nicely, I need to do the same with small PDF charts - before I go down this path just wondering if its even possible ....Yes / No ?
sure, instead of fitting the image you just have to use the PDF page afterwards. So when you go the way of the following PDFlib Cookbook sample http://www.pdflib.com/pdflib-cookbook/text-output/wrap-text-around-images/ (case 4) but just place a PDI page instead of the fit_image():
x1 = p.info_matchbox(matchboxnames[m][0], i, "x1");
y1 = p.info_matchbox(matchboxnames[m][0], i, "y1");
width = p.info_matchbox(matchboxnames[m][0], i, "width");
height = p.info_matchbox(matchboxnames[m][0], i, "height");
p.fit_pdi_page(page, x1, y1,
"boxsize {" + width + " " + height +
"} fitmethod meet position=center");

Set the content of PDF to center

I am generating dynamic multicell with string. Like A, B, C etc. I want to center those multicell on the page. I need to make the $pdf->SetMargins() dynamic, which means it will automatically center itself when the content is loaded. This is a code I tried but something is wrong.
$pdfWidth = 210;
col = 9; // This is dynamic so it can be any value from 5-20;
$mar = (($pdfWidth + ($col * 8)) /2)/2;
$pdf->SetMargins($mar,0,0);
I'm not sure why you're dividing by 2 twice. If you take the total width of the page, minus the content and divide that by two you have your desired margin already. Also, don't forget to set the override parameter in SetMargins() to 'true'.
$pdfWidth = 210;
$col = 9;
$mar = (($pdfWidth - ($col*8)) /2); //Only one division by 2 is required
$pdf->SetMargins($mar,0,0, true); //the 'true' is necessary or it won't override the default margins
//VERY IMPORTANT that you set all the above BEFORE adding the page!
$pdf->AddPage();
//Content of page
Now any MultiCell with cell width of 8, as you provided in the example, should be perfectly centered on the page.

How do I get <pre style="overflow: scroll; height : 150px" > to display at particular scroll line?

I need for the code section shown in pre to point to a particular line number. If there are 100 lines in pre I want what is shown to be line 51 for right in the center of the 150px box.
Try this (for 10 lines):
<pre style="width: 300px; height: 10pc; overflow-y: scroll;">
1
2
3
4
5
6
7
8
9
10
11
12
</pre>
Note "pc" instead "px"
You can do this using scrollTop in jQuery:
$("#code").scrollTop(topPosition);
where scrollPosition is "the number of pixels that are hidden from view above the scrollable area".
The difficulty is working out what this value should be. If you know the height of each line (which you can set using font-size in CSS, you could use:
topPosition = lineHeight * (lineNumber - 1);
But then you want the specified line to be in the middle of the container, so perhaps:
topPosition = lineHeight * (lineNumber - 1) - 70;
if (topPosition < 0) topPosition = 0;
I would play around with this and see if you can make it work. :)
To achieve that, you need a fixed line height for your pre element. For 150px height I suggest 15px for line-height and 11px for font-size. This will ensure 10 lines in your scrollable area.
The rest is some math and using scrollTop property.
example:
function goToLine(centeredLine){
var pre = document.getElementById('scrollablePre');
pre.scrollTop = (centeredLine - 5) * 15;
};