Why does TCPDF put text on following page? - tcpdf

When I set
$pdf = new dmdpdf("P", "IN","USLETTER", true, 'UTF-8', true); // US Letter page size
and say
$pdf->text (1.0,10.3,'Test');
the text is printed at the top of the next page.
However, if I say
$pdf = new dmdpdf("P", "IN", "USLEGAL", true, 'UTF-8', true); // US Legal page size
The text is printed exactly where I want it, within the margin of a USLetter page.
I can work around this be setting the page as USLEGAL but I am wondering if I am missing something. For the sake of purity, I'd like to do it without a fiddle.

US Letters are 11 inches tall.
The default page break margin is 20 mm from the bottom of the page, which would be 0.73 inches. 11-0.73 = 10.27. That puts your test text just beyond that automatic break position, so it triggers the automatic page break.
Set your page break margin to something smaller (or disable it entirely). If this is for a footer, consider using a custom footer instead.
I'm not familiar with dmdpdf but if it's a thin wrapper around TCPDF use setAutoPageBreak
/**
* Enables or disables the automatic page breaking mode. When enabling, the second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.
* #param $auto (boolean) Boolean indicating if mode should be on or off.
* #param $margin (float) Distance from the bottom of the page.
* #public
* #since 1.0
* #see Cell(), MultiCell(), AcceptPageBreak()
*/
public function SetAutoPageBreak($auto, $margin=0)

Related

Embed Codenameone Youtube Video

I've been trying to embed a youtube video within a codename one application. When I run the simulator for both Android and iOS it looks fine, but when I actually run the application on my Galaxy S7, nothing shows. I've tried using both BrowserComponent and WebBrowser and neither work. My code is below:
Form hi = new Form("Hi World", BoxLayout.y());
Display display = Display.getInstance();
BrowserComponent browser = new BrowserComponent();
//WebBrowser browser = new WebBrowser();
String videoUrl = "https://www.youtube.com/embed/r6VO3zaBJGY";
int videoWidth = (int) ((double) display.getDisplayWidth());
int videoHeight = (int) ((double) videoWidth*0.5625);
String integrationCode= "<iframe src=\"" +videoUrl+"\" frameborder=\"0\" width=\"" + videoWidth + "\" height=\"" + videoHeight + "\" allow=\"autoplay; encrypted-media\" allowfullscreen></iframe>";
browser.setPage(integrationCode, null);
browser.getAllStyles().setPadding(0, 0, 0, 0);
browser.getAllStyles().setMargin(0, 0, 0, 0);
Container browserContainer = new Container(new BorderLayout(CENTER_BEHAVIOR_CENTER));
browserContainer.add(CENTER, browser);
hi.add(browserContainer);
hi.show();
There are two mistakes in the code: BoxLayout and CENTER_BEHAVIOR_CENTER.
The reason this won't work has to do with the way layouts work. Layout managers use the preferred size to give components the right size. BrowserComponent doesn't have a proper preferred size as the rendering of HTML is asynchronous and it's pretty flexible to begin with. In this case you used two layout managers that respect preferred size. They get a size that amounts to zero and place the browser component appropriately...
BoxLayout.Y_AXIS needs the preferred height and CENTER_BEHAVIOR_CENTER needs the preferred size to position the component in the center.
The typical workaround is to use a regular BorderLayout which defaults to the scaled behavior. This stretches the center component to take up available space. Notice you need to set it on the Form itself as it has a hardcoded size of the entire screen. The center location ignores the preferred size and gives the component the full size.
It also solves another problem. Form is scrollable by default on the Y axis. Scrollability for Codename One components and native widgets (e.g. web) can collide so by using the border layout you implicitly disable scrolling which in this case might provide superior UX.
Note that you can get the code above to work by overriding calcPreferredSize() in BrowserComponent and returning the size you want for the component. I don't think this will result in a good UX because of scrollability issues.

reduce empty space at the top of presentation

I'd really like to be able to decrease the amount of padding at the top of all my level 2 reveal.js slides (version 2.6.2). It doesn't appear to be possible to customise this with CSS because the offset is a negative number calculated dynamically.
e.g. in http://fommil.github.io/scalax14/#/5/1 I would like to reclaim at least 200 pixels at the top. The top parameter is currently being calculated to be -350px but I'd really rather it was closer to -500px.
Is there a way to do this with config?
Reveal keeps the aspect ratio of the resolution you entered in the config.
If you want your slides to have less padding, there are multiple ways:
disable centering:
center: true, // add this in init or config
slides get positioned at the top of the page, and all the padding happens at the bottom
use a 4:3 format for your slides
width: 1024, // add this in init or config
height: 768,
this will move all padding to sides of the page (well, assuming the browser window is not resized) as long as the page ratio is wider than 4:3
create fully responsive slides:
var resizeSlide = function() {
Reveal.configure({
width: window.innerWidth,
height: window.innerHeight
});
}
setInterval(resizeSlide, 1000);
you will then need to make your slides responsive to changes in slide format, but this will make them utilize the full page for the presentation.
I'm using setInterval and not onResize because onResize just don't work on mobile and some browser/os combination (i.e. chrome on windows 8.1 when using keyboard shortcut and desktop hotspots to resize the window)

How to set the width of a textbox, depending on a specific format string?

I have a TextBox that uses a specific format string to display its content. The width of the box is set to take exactly the amount of space that is needed to display the text. For this purpose I use the width that the formatted text would have:
box.width = new FormattedText(
String.Format(Format, value),
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface("Arial"),
8,
Brushes.Black).Width;
When doing this the textbox almost has the right width. But I still need to add an offset of 12, otherwise the area of the text would be cropped by some pixels:
I got the number 12 by try-and-error. So two questions arise:
Why do I need this offset, were does the lost width go to (whitespace and border?)?
Is there a better approach to get the right offset than to just guess it?

Vaadin CropField addon selected image

The purpose of CropField is to get only selected part of the image. Which method does that? getImageResource() returns the whole image.
The second question is - is it possible to set a cropfield with a predetermined selected area? I've set minimal and maximal values of width and height to the same number so that selection area is always the same. However, user have to click on the cropfield in order to see it.
I have not used this addon.
The purpose of CropField is to get only selected part of the image
Actually, I think this statement is wrong; according to the description of the addon it
shows a single image and overlays it with capabilities to select, transform and move a cropping area within it.
i.e. it allows you to manipulate a selection area : it does not actually perform the cropping itself. I guess this could be done using serverside java (or an external tool).
For what it's worth, I agree that the name of the addon suggests that it does do the cropping itself.
As for setting a selection area, the javadoc of the CropField addon shows how to do this setValue(VCropSelection value)
/**
* Vaadin component that shows an image with an overlayed cropping
* functionality. The current selection can be set and get via
* setValue()/getValue() of {#link AbstractField}. The type of that value has to
* be {#link VCropSelection}. Usually, the selection will not be changed to a
* <i>null</i> value. Instead, it will be an empty selection (check with
* {#link VCropSelection#isEmpty()}).
*
* #author Eric Seckler
*/

Automatic Paging based on Content Area / Resolution - Telerik Grid

I am trying to accomplish something and I am not sure if it is completely possible.
I have a Telerik MVC Grid using ASP.NET MVC.
The default paging size for the grid is 10, however I want to be able to adjust the size the page (the number of rows) based on the size of the user's resolution. Is this possible?
Thanks,
Paul
It is definitely possible.
I created a solution that accomplishes the same thing - however you will have to tinker with it to get the proper height of your grid on it's own (excluding any menus/headers/footers etc.)
These steps should get you there:
Firstly - you will need to add an "onLoad" event to your MVC Grid:
.ClientEvents(events =>events.OnLoad("onLoad"))
Next - Create a Javascript event to handle the "onLoad" in your $(document).ready():
function onLoad(e)
{
//Bread and Butter will go here.
}
Finally - the last step will be to calculate the space that is not taken up by the grid (Firebug can be helpful) and tinker with it until your "formula" works out in most browsers:
function onLoad(e)
{
//Gets the height of the Window. ($(window).height())
//Subracts the height of any menus/headers/footers (in this case 275)
//Then divide by our "magic number" which you will need to tinker with
//to determine how the grid looks in different browsers. (in this case 28)
var height = Math.floor(($(window).height()-275)/28);
var grid = $("#YourGrid").data("tGrid");
grid.pageSize = height;
}
Formula :
$(window).height() - [Occupied Space] / [Magic Number]
[Occupied Space] - Total CSS Height of all objects above the Grid.
[Magic Number] - You will have to play with this one and try it out on
different browsers until you get the expected results.
That should automatically adjust your your number of rows based on your window height.The only tricky part is figuring out your own "formula" using the amount of occupied space and then picking a magic number to divide by.
Hope this helps!

Resources