Laravel wkhtmltopdf - text in the bottom of the last page - php
I'm generating an invoice PDF using laravel snappy wkhtmltopdf
and I'm tring to add some text in the bottom of the last page,
now i already have a footer-html with the number of the page.
I tried to show the content only in the last page with this way:
<!DOCTYPE html>
<div id="footer_text">
{!! nl2br($footer_text) !!}
</div>
<div class="pagination"><span id='page'></span> of <span id='topage'></span></div>
<script>
function remove(id) {
var elem = document.getElementById(id);
return elem.parentNode.removeChild(elem);
}
var vars={};
var x=window.location.search.substring(1).split('&');
for (var i in x) {
var z=x[i].split('=',2);
vars[z[0]] = unescape(z[1]);
}
document.getElementById('page').innerHTML = vars.page;
document.getElementById('topage').innerHTML = vars.topage;
if( vars.page != vars.topage && vars.topage > 1){
document.getElementById('footer_text').innerHTML = '';
remove('footer_text');
}
if(vars.topage == 1){
document.getElementById('pages').innerHTML = '';
}
</script>
and it does show me the text only in the last page BUT in the previous pages I have a big white space, here is a screenshot:
page number 1:
page number 2:
I feel like i tried everything, please help me
There is no issue with your script it might be some style issue. As you are removing footer_text in all previous pages and showing only on last page and this is somehow creating too much space. Check your CSS there must be margin-bottom or padding-bottom which is creating too much space. Enjoy!
Late to the party but looks like the ID footer_text will be set multiple times and ID's should be unique so I guess it would have worked if you used a class instead and getElementsByClassName
The footer height can't be dynamic on a different page when using Wkhtmltopdf. It's always with a static height. If this is your footer.html you have to add to your style:
body {height: 70px /for example/; position: relative;}
so you can align bottom (with position:absolute; bottom:0;) you #footer_text and content. But still, have some white space on all prev pages.
In the PDF generators, the footer content area is independent of the body content.
Related
How to reload block in Magento?
I'm working on a module for Christmas on Magento. Each day a pop-up appears on the index page of the website. This pop-up will contain an image and a link. To load the pop-up, I define what css to use (module.phtml): <?php $today = explode(".",date("d.m.y")); $month = $today[1]; $day = $today[0]; $file = 'POP UP '.$day.'.jpg'; $class = 'block block-AdventCalendar'.$day; ?> <div class="<?php echo $class ?>"> </div> Example in the CSS file (app-base.css): .block-AdventCalendar1 { background-image: url('../images/popupAdvent/POP UP 1.jpg'); background-size: 100% 100%; color: #fff; margin: 0; height:350px; width :700px; } This code works fine, but when the day changes Magento loads the wrong CSS class. To display the correct image I must clear the Magento cache each day. However, when I modify something in the phtml file, the changes are displayed immediately, only the inline CSS is not reloaded. Does anybody have an idea to force the phtml to load the right css?
Try to use this: Mage::app()->cleanCache(); To clear the Magento cache after your code loads.
You could also try a JavaScript alternative: <script> var dateObj = new Date(); var month = dateObj.getUTCMonth() + 1; //months from 1-12 var day = dateObj.getUTCDate(); var element = document.getElementById('your_div_id'); if (element) { element.className += element.className ? ' block-AdventCalendar'+day : 'block-AdventCalendar'+day; } </script> Add this after the div you want to add the class to. Also, give your div a unique ID ( <div id="your_div_id">...</div> )
The problem is not due to the CSS. If I alter it or the phtml, all change are immediate. Only the div class stay unchanged <div class="<?php echo $class ?>">
How to make PHP loop refresh when clicking class tag
Okay so I have this portfolio page where I display a couple of thumbnails, and you can order it by tags, so for example like this: year 1 And this works fine. However, my thumbnails display at three on a row, so only the first two should have a right margin, the third one no margin. I used PHP to do this which works fine. if ($result=$link->query($query)) { for ($i=1; $i <= $result->num_rows; $i++) { $row= $result->fetch_assoc(); $id = $row['number']; $title = $row['title']; $bgthumbnail = $row['thumbnail']; if($i%3 == 0){ echo " <div class=\"thumbnail\"> <a href=\"portfoliodetail.php?id=$id\"> <div class=\"thumbnailOverview noMargin\" style=\"background: url('images/portfolio/thumbnails/$bgthumbnail'); background-position: center center;\"> <div class=\"latestWorkTitle\">$title</div> </div> </a> </div> "; } else { echo " <div class=\"thumbnail\"> <a href=\"portfoliodetail.php?id=$id\"> <div class=\"thumbnailOverview\" style=\"background: url('images/portfolio/thumbnails/$bgthumbnail'); background-position: center center;\"> <div class=\"latestWorkTitle\">$title</div> </div> </a> </div> "; } } $result->close(); } However, when I click a tag, the margin doesn't update. So when a thumbnail was given no margin in the overview because it was the third one in row, when it displays first because of a chosen tag, it also receives no margin. Of course this is because nothing "refreshes" or something, but I was wondering if there is an "easy" way to fix this problem? To make the PHP loop run again or something?
You must to set/remove noMargin class name via javascript: $('.year-clicker').click(function (event) { event.preventDefault(); var year = $(event.currentTarget).data('year'); $('.thumb').hide().removeClass('noMargin').filter('.year' + year).show(); $('.thumb:visible').each(function (i, e) { if ((i + 1) % 3 == 0) { $(e).addClass('noMargin'); } }); return false; }); Try out this jsfiddle http://jsfiddle.net/xgE3K/1/
unless your "tags" are recalling the page - so that the php is re-executed - you probably want to look at javascript (or possibly ajax) to do the reformatting of the layout. Depending on the quantity of thumbnails and the variety of tags, you might use the php to create a div (with a relevant id and a style="" attribute) for each of the different filter tags - containing the layout of the thumbnails for that tag (so you can ensure your layout is fine for each view). i.e. repeat your code above enclosed by a unique div tag for each view. Make the default view div visible (style="display: block") and the others hidden (style="dsplay: none"). Then have a javascript function that is executed on any tag click. This will make the relevant div visible and the rest hidden, by changing their style value as above. Uses a bit more memory, but your switching between views will be quicker than doing a reload. Despite all this, I think it's cleaner and more scalable to recall the page with the relative filter (depending on the tag) then you will have more control over the layout.
make a css style of a text when a user firts visit my web site
I have a web site. Here in my home page there is a content "My dummy text ". which is placed in ul li a tag. ie <ul><li><a>My dummy text</a></li></ul> i want to make this text should highlighted in blue when someone first lands on the home page. other wise it's must be in white. Does any one know how to do this ? mine is a php web site Thanks in advance
Just to add a little onto the cookie method I suggest adding a class to the <body> tag so that if in the future you want to do more you could do it without having to modify the PHP. For example: <?php function dejavu() { $class = ''; if($_COOKIE['beenHereBefore']) { $class .= 'beenHereBefore'; } else { $class .= 'firstTimeHere'; setcookie("beenHereBefore", true); } return $class; } ?> <body class="<?php echo dejavu(); ?>"> One thing that you want to take into account though is that if a user clears their cookies then it will act as though they are visiting the site for the first time; so I suggest, if possible store it in their user profile if one exists. So then in your CSS you can do the following: ul li a {color: white;} .firstTimeHere ul li a {color: blue;}
I dont see any code so..here is my theoritical explaination as well... 1 Use Cookies. 2 HTML5 Cache..You can use localstorage to do that as well
you can use cookie set default 0 if someone loaded the page than change cookie to 1 otherwise 0 . <ul> <li> <a <?php if($_COOKIE["status"] == 0){style="color:blue;"} ?>>My dummy text</a> </li> </ul>
Use: $(window).ready(function(){ // do your CSS stuff here ... }); Or use : $(document).ready(function(){ // do your CSS stuff here ... }); Check this link : http://api.jquery.com/ready/
I advise you to do it using jquery to check if you are in the home page Assume your home page is called : index.php Like this : if(window.location.href.indexOf("index.php") > -1) { $('#ulid li').css('color', 'red'); } else $('#ulid li').css('color', 'black'); Give your ul an ID and assume you want to highlight using red and your original text color was black No need to use Cookies you can do this trick using jquery very easily .
Echoing out JavaScript with nested quotes from a PHP script onto an HTML page?
I've been trying for about two hours to get the following code stored in a PHP string and then echoed out as JavaScript on a webpage: <div id="reply-box" style="display: block; width:100%;float:right;"> <script type="text/javascript" src="http://example.com/public/js/3rd_party/ckeditor/ckeditor.js"></script> <script type="text/javascript"> /* Dynamic items */ CKEDITOR.config.IPS_BBCODE = {"acronym":{"id":"8","title":"Acronym","desc":"Allows you to make an acronym that will display a description when moused over","tag":"acronym","useoption":"1","example":"[acronym='Laugh Out Loud']lol[/acronym]","switch_option":"0","menu_option_text":"Enter the description for this acronym (EG: Laugh Out Loud)","menu_content_text":"Enter the acronym (EG: lol)","single_tag":"0","optional_option":"0","image":""},"ads1":{"id":"46","title":"ads1","desc":"","tag":"ads1","useoption":"0","example":"","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"background":{"id":"27","title":"Background-color","desc":"Adds a background color behind the text","tag":"background","useoption":"1","example":"[background=red]Red background behind this text[/background]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"entry":{"id":"35","title":"Blog Entry Link","desc":"This tag provides an easy way to link to a blog entry.","tag":"entry","useoption":"1","example":"[entry=100]Click me![/entry]","switch_option":"0","menu_option_text":"Entry ID","menu_content_text":"Text to display","single_tag":"0","optional_option":"0","image":""},"blog":{"id":"34","title":"Blog Link","desc":"This tag provides an easy way to link to a blog.","tag":"blog","useoption":"1","example":"[blog=100]Click me![/blog]","switch_option":"0","menu_option_text":"Blog ID","menu_content_text":"Text to display","single_tag":"0","optional_option":"0","image":""},"code":{"id":"13","title":"Code","desc":"Allows you to enter general code","tag":"code","useoption":"0","example":"[code]$text = 'Some long code here';[/code]","switch_option":"0","menu_option_text":"","menu_content_text":"Code","single_tag":"0","optional_option":"0","image":""},"extract":{"id":"33","title":"Extract Blog Entry","desc":"This will allow users to define an extract for an entry. Only this piece of the entry will be displayed on the main blog page and will show up in the RSS feed.","tag":"extract","useoption":"0","example":"[extract]This is an example![/extract]","switch_option":"0","menu_option_text":"","menu_content_text":"Blog entry extract","single_tag":"0","optional_option":"0","image":""},"hr":{"id":"12","title":"Horizontal Rule","desc":"Adds a horizontal rule to separate text","tag":"hr","useoption":"0","example":"[hr]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"html":{"id":"15","title":"HTML Code","desc":"Allows you to enter formatted/syntax-highlighted HTML code","tag":"html","useoption":"0","example":"[html]<div class='outer'>\n <p>Hello World</p>\n </div>[/html]","switch_option":"0","menu_option_text":"","menu_content_text":"HTML Code","single_tag":"0","optional_option":"0","image":""},"imgr":{"id":"39","title":"Image","desc":"Displays linked images, floating to the right","tag":"imgr","useoption":"0","example":"[imgr]http://www.google.com/intl/en_ALL/images/logo.gif[/imgr]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"jump":{"id":"45","title":"jump","desc":"","tag":"jump","useoption":"0","example":"","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"media":{"id":"32","title":"Media","desc":"Allows a user to post media content from certain common media sites","tag":"media","useoption":"1","example":"[media]http://www.youtube.com/watch?v=YqqLx-2vUr0[/media]","switch_option":"0","menu_option_text":"Dimensions (Flash Only)","menu_content_text":"Media URL","single_tag":"0","optional_option":"1","image":""},"member":{"id":"31","title":"Member","desc":"Given a member name, a link is automatically generated to the member's profile","tag":"member","useoption":"1","example":"[member=admin] runs this site.","switch_option":"0","menu_option_text":"Member Name","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"page":{"id":"38","title":"Multi-Page Articles","desc":"This tag can be used to create multi-page articles. Page links are automatically added based on the number of times this tag is used, and the content is hidden until you reach the specified \"page\".","tag":"page","useoption":"0","example":"Content 1\n[page]\nContent 2\n[page]\nContent 3","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"overline":{"id":"42","title":"Overlined Text","desc":"Makes the text overlined","tag":"overline","useoption":"0","example":"[overline]This text is underlined[/overline]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"php":{"id":"14","title":"PHP Code","desc":"Allows you to enter PHP code into a formatted/highlighted syntax box","tag":"php","useoption":"0","example":"[php]$variable = true;\n\nprint_r($variable);[/php]","switch_option":"0","menu_option_text":"","menu_content_text":"PHP Code","single_tag":"0","optional_option":"0","image":""},"post":{"id":"6","title":"Post Link","desc":"This tag provides an easy way to link to a post.","tag":"post","useoption":"1","example":"[post=1]Click me![/post]","switch_option":"0","menu_option_text":"Enter the Post ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"pre":{"id":"43","title":"pre","desc":"","tag":"pre","useoption":"0","example":"","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"spoiler":{"id":"7","title":"Spoiler","desc":"Spoiler tag","tag":"spoiler","useoption":"0","example":"[spoiler]Some hidden text[/spoiler]","switch_option":"0","menu_option_text":"","menu_content_text":"Enter the text to be masked","single_tag":"0","optional_option":"0","image":""},"sql":{"id":"16","title":"SQL Code","desc":"Allows you to enter formatted/syntax-highlighted SQL code","tag":"sql","useoption":"0","example":"[sql]SELECT p.*, t.* FROM posts p LEFT JOIN topics t ON t.tid=p.topic_id WHERE t.tid=7[/sql]","switch_option":"0","menu_option_text":"","menu_content_text":"SQL Commands","single_tag":"0","optional_option":"0","image":""},"tab":{"id":"48","title":"tab","desc":"adds a tab (twelve spaces)","tag":"tab","useoption":"0","example":"[tab]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"tex":{"id":"41","title":"tex","desc":"LaTeX","tag":"tex","useoption":"0","example":"","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"topic":{"id":"5","title":"Topic Link","desc":"This tag provides an easy way to link to a topic","tag":"topic","useoption":"1","example":"[topic=1]Click me![/topic]","switch_option":"0","menu_option_text":"Enter the topic ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"twitter":{"id":"36","title":"Twitter","desc":"A tag to link to a user's twitter account","tag":"twitter","useoption":"0","example":"[twitter]userName[/twitter]","switch_option":"0","menu_option_text":"","menu_content_text":"Twitter Username","single_tag":"0","optional_option":"0","image":"twitter.png"},"xml":{"id":"17","title":"XML Code","desc":"Allows you to enter formatted/syntax-highlighted XML code","tag":"xml","useoption":"0","example":"[xml]<outer>\n <inner>\n <tag param='1'>Test</tag>\n </inner>\n</outer>[/xml]","switch_option":"0","menu_option_text":"","menu_content_text":"XML Code","single_tag":"0","optional_option":"0","image":""}}; CKEDITOR.config.IPS_BBCODE_IMG_URL = "http://example.com/public/style_extra/bbcode_icons"; CKEDITOR.config.IPS_BBCODE_BUTTONS = []; /* Has to go before config load */ var IPS_smiley_path = "http://example.com/public/style_emoticons/default/"; var IPS_smiles = {"total":20,"count":20,"emoticons":[{"src":"mellow.png","text":":mellow:"},{"src":"dry.png","text":"<_<"},{"src":"smile.png","text":":)"},{"src":"wub.png","text":":wub:"},{"src":"angry.png","text":":angry:"},{"src":"sad.png","text":":("},{"src":"unsure.png","text":":unsure:"},{"src":"wacko.png","text":":wacko:"},{"src":"blink.png","text":":blink:"},{"src":"sleep.png","text":"-_-"},{"src":"rolleyes.gif","text":":rolleyes:"},{"src":"huh.png","text":":huh:"},{"src":"happy.png","text":"^_^"},{"src":"ohmy.png","text":":o"},{"src":"wink.png","text":";)"},{"src":"tongue.png","text":":P"},{"src":"biggrin.png","text":":D"},{"src":"laugh.png","text":":lol:"},{"src":"cool.png","text":"B)"},{"src":"ph34r.png","text":":ph34r:"}]}; var IPS_remove_plugins = []; var IPS_hide_contextMenu = 0; var IPS_rclick_contextMenu = 0; /* Has to go after */ /* Load our configuration */ CKEDITOR.config.customConfig = 'http://example.com/public/js/3rd_party/ckeditor/ips_config.js'; </script> <input type='hidden' name='isRte' id='isRte_editor_4fe2476d708e8' value='1' /> <textarea id="ipb_editor" name="Post" class='ipsEditor_textarea input_text'></textarea> <p class='desc ipsPad' style='display: none' id='editor_html_message_editor_4fe2476d708e8'></p> <script type="text/javascript"> ipb.textEditor.initialize('editor_4fe2476d708e8', { type: 'full', height: 200, minimize: 0, bypassCKEditor: 0, delayInit: 0, isHtml: 0, isRte: 1, isTypingCallBack: '', ips_AutoSaveKey: '', ips_AutoSaveData: [] } ); </script> </div> I've tried escaping quotes using several different JavaScript and PHP methods, but no matter what I try I can't get it echoed out without either breaking the page or the editor not working. Does anyone know of a way to get this code stored in a string in a manner that can be then echoed out onto the page as working JavaScript?
Try: <?php ob_start(); ?> <div id="reply-box" style="display: block; width:100%;float:right;"> <script type="text/javascript" src="http://example.com/public/js/3rd_party/ckeditor/ckeditor.js"></script> <script type="text/javascript"> .... your HTML/Javascript </script> </div> <?php $string = ob_get_contents(); ob_end_clean(); ?> I don't have your javascript libs but it appears to show up fine when I echo out $string. PHP is basically copying all of the display content to a buffer and instead of rendering the page, we copy it to a variable.
$variable = <<<END xxx xxx xxx END; echo $variable; Make sure you have END; on it's own line WITHOUT whitespace before it. Hope have helped!
CSS / Javascript Dropdown Navigation Fix Needed for IE
An ex developer of ours when working on one of our first versions of our internal PHP framework integrated the dropdown element of main navigation using javascript and I need to get a fix applied for IE8 which is causing the dropdown to appear offset even though using CSS displays fine in Firefox / Chrome. The site in question is http://www.benchmemorials.co.uk/ In the event there is sub menu items from the main navigation that use a dropdown, javascript is called to display this I believe (below)... <script type="text/javascript"> $(document).ready(function() { var position = $('#link_why-buy-from-us').offset(); $('.dropdown').css(position); $('#link_why-buy-from-us').mouseover(function() { $('.dropdown').show(); }); $('.dropdown').mouseover(function() { $('.dropdown').show(); }); $('.dropdownstyle').mouseover(function() { $('.dropdown').show(); }); $('#link_why-buy-from-us').mouseleave(function() { $('.dropdown').hide(); }); $('.dropdown').mouseleave(function() { $('.dropdown').hide(); }); $('.dropdownstyle').mouseleave(function() { $('.dropdown').hide(); }); }); </script> I'm not too hot on javascript but from what I gather, I presume the above is instructing the drop down to appear below the 'Why Buy from Us' top navigation menu item. As I mention, this is working as expected in Firefox/Chrome. However, the issue appears to be the fact that somewhere along the line, inline CSS is being generated dynamically for the dropdown class - this is dynamically generating style="top: 61px; left: 964px; display: none;" Every file on the server has been searched and nowhere is this specified, my only guess is that the javascript above is somehow creating this line of CSS which is therefore preventing me from altering the position of the dropdown in the IE only stylesheet to fix the display in IE8. The rest of the code for the dropdown menu from the php file is below:- <div class="dropdown"><div class="dropdownstyle"> <?php mysql_select_db($database_config, $config); $query_sub_pages = "SELECT * FROM `pages` WHERE site_id = '".$current_site_id."' AND menu_location = 'sub' ORDER BY `order` ASC"; $sub_pages = mysql_query($query_sub_pages, $config) or die(mysql_error()); $row_sub_pages = mysql_fetch_assoc($sub_pages); $totalRows_sub_pages = mysql_num_rows($sub_pages); $current_sub_link = 0; do { $current_sub_link = $current_sub_link + 1; ?> <p<?php if ($current_sub_link != $totalRows_sub_pages) {echo ' style="margin-bottom: 10px;"';}; ?>><a class="sub_link" href="<?php echo $site_base.$row_sub_pages['page_location']; ?>"><?php echo $row_sub_pages['page_display_name']; ?></a></p><?php //if ($current_sub_link != $totalRows_sub_pages) {echo '<br />';}; ?> <?php } while ($row_sub_pages = mysql_fetch_assoc($sub_pages)); ?> </div> </div> As you can see, there is no inline CSS applied to .dropdown. All CSS from the sylesheets can be viewed if you inspect element in browser. Please could anyone advise how or if it is possible to prevent this dynamic CSS positioning from being generated or an alternative / easier method of ensuring the dropdown appears consistently across all browsers including IE? Thanks in advance.
The positioning is done by this code: var position = $('#link_why-buy-from-us').offset(); $('.dropdown').css(position); It takes the position of #link_why-buy-from-us relative to the document, and adds it to the .dropdown element. I don't know if you're familiar with jQuery, but the code above is written using that JavaScript library. For more documentation about .offset(), look here: http://api.jquery.com/offset/