PhantomJS: place div element on bottom part of a page - css

I am using jsreport with PhantomJS for making reports for bills/invoices.
I need to place a div element on the bottom part of some pages. It is the part of a bill that the cashier of a bank can cut with a scissor.
I tried different ways with CSS to do it but when jsreport renders, the result is not what I expect.
These two examples show what I need:
One page:
Two pages:
I made a very basic example here if someone wants to edit it:
https://playground.jsreport.net/studio/workspace/rJRuPJkfW/57

The javascript based solution:
You can find out the full height of the single page. You can also find out the real height of the document. These two values helps you to calculate the bottom of the last page. Then you can absolute position the cut area to the last page using js.
<script>
// magical page size number was only estimated based on very long pdf
// it differs based on the recipe and platform used to render
// windows phantomjs 1.9.8 = 1274
// linux/osx phantomjs 1.9.8 = 989
var pageSize = 1274
// the size of the area you want to cut
var cutDivHeight = 200
var numberOfPages = Math.ceil(document.height / pageSize)
// run debug to see the values
console.log(numberOfPages * pageSize - document.height)
// find out if the extra div fits to the last page space
if (numberOfPages * pageSize - document.height < cutDivHeight) {
numberOfPages++
}
// add the cut area
var watermark = document.createElement('div');
watermark.innerHTML = "CUT ME"
watermark.style.top = (numberOfPages * pageSize) - cutDivHeight
watermark.style.height = cutDivHeight + 'px'
watermark.style.width = '100%'
watermark.style['background-color'] = 'red'
watermark.style.position = 'absolute'
document.body.appendChild(watermark)
</script>
Demo here
https://playground.jsreport.net/studio/workspace/BJEMYu3bb/36

i think that you can achieve the desired design customizing the phantomjs footer with a fixed size and custom html, and adding custom page margins.
you can see a live example here: https://playground.jsreport.net/studio/workspace/BJEMYu3bb/31
take a closer look at the template's phantom options and the logic inside the footer to only be printed in the last page, also i'm not sure that it is going to work when you have content that move to another page maybe there is some kind of workaround that you will need to apply to have everything in place, but anyway this is a start.

Related

How to get boostrap content to be enclosed in two column with the browser's height

I'm having a problem that seems pretty common but with a slight twist.
I'm using bootstrap for my web application. The main layout/master page has a top bar (for actions) and a left side navigation bar (for navigation between the pages of the application, of course). So, the page's content is always in the "bottom-right" part of the screen (if I can say, although that "bottom-right" cover about 80% of the screen).
Now, for one page only, I want the content to be enclosed in a two column layout with independent scroll bars. On the left side, I want to display a task list and on the right side, I want to display boxes (two boxes wide) for my employees with their already assigned tasks. I want to be able to navigate in my task list independently from my employees list.
Here is a very basic mock-up (I know, it's ugly) of what I'm trying to accomplish : https://drive.google.com/file/d/0BwbWwcCjL9EJT1B5MlFMQVh0UnM/view?usp=sharing
Is it even possible to accomplish this when bootstrap is involved? Right now, my task list and my employees list extend on many page length (4-5 at least). I want them to be contained within the browser window and have an independent scroll bar for each list so I can drag a task from the top of the list to the bottom employee (as an example), which is now impossible.
Thanks
Finally, I've found a solution. I had tried to use the "scroll" class, but I had forgotten to use a "max-height". Now, I use the following code :
$(document).ready(function() {
ResizeListsSoTheyFitInScreen();
});
$(window).resize(function () { ResizeListsSoTheyFitInScreen(); });
function ResizeListsSoTheyFitInScreen() {
var windowHeight = $(window).height();
var taskListTop = $('#TaskList').offset().top;
$('#TaskList').css('max-height', (windowHeight - taskListTop) + 'px');
var employeeListTop = $('#EmployeeList').offset().top;
$('#EmployeeList').css('max-height', (windowHeight - employeeListTop) + 'px');
}
It works fine, though I'm not 100% sure it's the best solution because I have to account for the bottom margin and such on my own. If you have a better solution, I'm open to it.
Thanks a lot

Detect if Dojox Mobile ToolBarButton is visible

I've got a ToolBarButton floating right within a heading similar to the example given on the documentation for dojox.mobile.heading ( http://dojotoolkit.org/reference-guide/1.9/dojox/mobile/Heading.html ):-
<div data-dojo-type="dojox/mobile/Heading" data-dojo-props='label:"Voice Memos"'>
<span data-dojo-type="dojox/mobile/ToolBarButton" data-dojo-props='label:"Speaker"'></span>
<span data-dojo-type="dojox/mobile/ToolBarButton" data-dojo-props='label:"Done",defaultColor:"mblColorBlue"' style="float:right;"></span>
</div>
Produces:
My issue is that while this is fine with a short title (e.g. Voice Memos as above), for longer titles on smaller width devices the toolbarbutton on the right is sacrificed and not shown at all.
I'd like to show something on the page if that isn't visible. Is it possible to detect the visibility of the right-floated toolbarbutton and if it isn't visible add something further down the page (e.g. a link)? And if so, how would I do it?
Using Dojox Mobile 1.9.2
One way to go would be to set the label by code, using a long or a shortened text depending on the actual screen size. Here's a rough implementation:
var heading = registry.byId("heading");
var adjustLabel = function() {
var dim = common.getScreenSize(); // dojox/mobile/common
var label = dim.w > 350 ? // adjust the value as needed
"This is quite a long label" : "Short label";
heading.set("label", label);
heading.resize();
}
adjustLabel();
connect.subscribe("/dojox/mobile/resizeAll", function(){
adjustLabel();
});
Live here: http://jsfiddle.net/adrian_vasiliu/3p64t/ (you can test it by resizing the right-side pane: the label adjusts itself automatically; the same would happen on a phone or tablet upon orientation change).
That said, I do not reproduce (with Dojo 1.9.2) the fact that, with your code as-is, the button on the right is not shown. You can try it here: http://jsfiddle.net/adrian_vasiliu/QYjY5/. I also tested it outside of jsfiddle by adding your piece of HTML into dojox/mobile/test_Heading.html - and it behave the same in Chrome/Windows, Chrome/Android and Safari/iOS.

Adjust iframe height automatically according to page-content : height varying with search result from same page

Initially the following page has a fixed height with a form:
http://arms.aero/gmg/ftrack/ftrack.aspx
when search is done the height of this page varies according to the reach-result.
Now I have to display this page as inner content from another page (its a php page) – so that the varying heights adjust automatically according to its page content.
I have tried with an iframe feature like this http://host.sonspring.com/iframe/ .
But the problem is - it is using different pages to adjust iframe heights, and mine is only one page (initial content and content with search result).
Please help me find a solution.
Try this, you can change for even when you want.
$('#iframe').live('mousemove', function (event) {
var theFrame = $(this, parent.document.body);
this.height($(document.body).height() - 350);
});

resize a div after setting innerHTML with mootools

I am using mootools 1.2 in a simple page. There's a div that displays a form (call it formdiv) that gets submitted via JS/ajax. The ajax request returns some data "confirmation message".
However, the formdiv div starts out maybe 500px high to accomodate the form elements. When the ajax request returns a variable-length return data ("confirmed for submission!") the div stays 500px high, leaving a lot of extra space.
My question is, is there a way to snap the div back to fit the new content after updating the content using innerHTML?
Thanks
EDITED: to add that the data returned by the Ajax call could be variable length-- so I can't assume it'll be a certain height and then reset the div to that height.
If your div starts off with predefined height using CSS then all you should do is set its height to auto or clearing styles altogether when they were set inline.
Check this JSFiddle (it works with jQuery here, but that doesn't matter when it comes to browser rendering div in question)
Okay I realize that this is like a year late but I came across this question while attempting to find a script to do just this. This was a great starting point but I felt like I should share the method I choose to use:
Get the current actual height of $('element').
h.before = $('element').getSize().y;
Fx.Morph can't handle setting the height to 'auto' so first you must set height: 'auto' on $('element') (in case it hasn't been already) and then set the html to the new content. This will allow you to get the new content's height.
$('element').setStyle('height', 'auto');
$('element').set('html', "Some other content.<br/>Very short.");
h.after = $('element').getSize().y;
Reset the height and then start the Fx.Morph with h.after.
$('element').setStyle('height', h.before);
var myEffect = new Fx.Morph('element', {
onComplete: function() {
$('test').setStyle('height', 'auto');
}
});
myEffect.start({'height': h.after});
You can check out the full code here: http://jsfiddle.net/cd4R9/
Please understand this is method is very basic and a lot would have to be done to make this site-ready. For example if your $('element') has padding, you will have to account for it or use the CSS property box-sizing: border-box;. Hope this helps.

Center on anchored image after jump?

When I jump to an anchor tag in on a wide (4000px) page, the anchored image is horizontally aligned to the right. How can I get it to align to the center? I have tried several things but none seem to work. Since I am new here I am not allowed to post the code, so I hope I was clear enough.
Thanks for your help,
Robert C.
The issue arises because the browser will do the least amount of scrolling required to bring the anchored element into view. Thus, if it is off to the right of the viewable area, when the anchor tag is clicked, it will simply scroll far enough to the right to reveal the whole element.
You could fix this behavior with javascript if that is an option. You won't be able to center it on #anchor click with straight CSS.
Here is a "solution" using jQuery. I have "solution" in quotes because it may introduce more problems than you want. For instance, without further JS the back button won't work to go to the previous link. But this does center the item given your sample code.
Just add this to the page you linked above before the closing <head> tag:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("a[href^=#]").click(function(e){
var id = $(this).attr('href').substr(1),
$target = $('*[name=' + id + '] img'),
$window = $(window),
offset = $target.offset();
var left = offset.left - ($window.width() / 2) + ($target.width() / 2 );
var top = offset.top - ($window.height() / 2) + ($target.height() / 2);
$('html,body').scrollTop(top).scrollLeft( left);
e.preventDefault(); // Keep the browser from trying
});
});
</script>
It will find all a tags with internal links (href starts with #). Then it finds the target that has that name, and grabs the child img tag. Then it gets the dimensions of the img element and the window element. Does some math with the img elements offset, and scrolls it into center.

Resources