mPDF - Show background only on odd pages - css-selectors

Using mPDF, I'm trying to apply a background image only on odd pages.
This works (only odd pages will be red):
$pdf->SetDefaultBodyCSS('background', 'red');
$pdf->WriteHTML('test');
$pdf->SetDefaultBodyCSS('background', 'white');
$pdf->AddPage();
$pdf->WriteHTML('test');
But this does not work (background is showing on both page 1 and 2):
$pdf->SetDefaultBodyCSS('background', 'url(\'./pdf-bg.png\')');
$pdf->WriteHTML('test');
$pdf->SetDefaultBodyCSS('background', 'none');
$pdf->AddPage();
$pdf->WriteHTML('test');
What I tried so far:
Using named pages (e.g. #page oddpage), it completely changed the page parameters and broke the layout
Using #page :first, I can't use :first as I need every odd page to have a background, not only the first one
Any clue? Thank you in advance!

I eventually found a workaround, not my favorite solution but it does the job!
$pdf->SetDefaultBodyCSS('background-image', 'pdf-bg.png');
$pdf->SetDefaultBodyCSS('background-image-resize', 6);
$pdf->SetDefaultBodyCSS('background-image-resolution', '300dpi');
$pdf->WriteHTML('test');
$pdf->SetDefaultBodyCSS('background-image', 'pdf-bg-white.png'); // Reset background to a blank page
$pdf->AddPage();
$pdf->WriteHTML('test');
So basically using the background-image CSS property instead of background and resetting the background with a full-white background to emulate a blank page.

Related

Cannot select an md-tab in Protractor

I am trying to use Protractor to write end-to-end tests using Protractor. I've run into an issue where I am unable to click on an Angular Material md-tab item and have it load. Instead, when I click on it, I just get a blank area where the tab content should appear.
I found this GitHub issue that provided some CSS that supposedly fixes the problem, but even with the CSS my tab is still not loading. I have tried clicking the tab in the following ways:
element.all(By.css('md-tab-content')).then (tabs)->
#browser.executeScript("#{tabs[1]}.click();")
#browser.actions().click(tabs[1]).perform()
#tabs[1].click()
browser.actions().mouseMove(tabs[1], {x: -20, y: -20}).mouseDown().perform()
All of these methods result in the same hanging issue. The CSS I added based on the GitHub response is:
md-tabs-canvas {
// Keeps IE11 from making `md-pagination-wrapper` as wide as the page.
align-items: inherit;
md-pagination-wrapper {
width: auto !important;
}
}
If I use browser.sleep(5000) and manually click the tab rather than trying to click the tab through protractor, the tab loads perfectly, and the test continues on as expected.
Does anyone know how I can use protractor to click an md-tab element and have it load the content properly?
I click tab items in my e2e tests without any problems using the following
element(by.css('md-tab-item:nth-child(1)')).click();
I got a great solution here. Just do element(by.cssContainingText('.mat-tab-label', "<Tab Name>")).click();

ng-srcset images initially not displaying in IE11 intermittently

The page loads without any of the images displaying on IE11 only, but refreshes them accordingly when we resize the browser intermittently (1/3 loads). We cannot replicate this with any of the other browsers. srcset works fine by itself with static content.
Here is a Plunker example of it not working in IE11.
Or quick and easy, the actual img html we're using:
<img data-ng-srcset="{{::image.url}}, {{::image.url2x}}" alt="{{::image.name}}"/>
The images or surrounding divs do not have any transitions, shadows or opacity applied.
The html renders fine with angular passing over and rewriting the srcset attribute correctly. The images just do not appear, only the alt tag. Wondering if this could be a call stack issue due to the intermittence of it, maybe a race condition with Picturefill loading before angular finishes a digest or something.
Cheers in advance!
A work around if you use PictureFill in a loop and in a specific case (not on all images of your application), is calling a function that launch PictureFill directly from HTML, after last item loaded (this is not the best practice but fix the IE11 problem) :
<picture><!-- Your image --></picture>
<span ng-if="$last">
{{ controllerAlias.launchPictureFill() }}
</span>
Came across this as a solution: http://tech.endeepak.com/blog/2014/05/03/waiting-for-angularjs-digest-cycle/
var waitForRenderAndDoSomething = function() {
if($http.pendingRequests.length > 0) {
$timeout(waitForRenderAndDoSomething); // Wait for all templates to be loaded
} else {
$window.picturefill();
}
}
$timeout(waitForRenderAndDoSomething);
The only issue that the blog post describes is here, so if anyone has anything better please let me know:
The $http.pendingRequests supposed to be used for debugging purpose only. If angular team decides to remove this, you can implement the same using http interceptors as suggested in this link.

Masonry Views can't load masonry effect in D7

I had installed Masonry Views module, along with Masonry module in my Drupal 7 site.
In my view, I can select format as "Masonry", and had updated the details such as column width.
But the output still displays the view like unfomatted list.
In my status report, it shows
jQuery Masonry 2.1.08
jQuery Update jQuery 1.10.2
My js file is in: www/mydomain/sites/all/libraries/masonry/jquery.masonry.min.js
I had flushed cached, but the masonry effect still doesn't appear. Any idea what's the problem?
Reading your question again I have a silight suspicion what the problem might be: are your content items display literally as a list? Then you might have to adjust their widths first so more than one can fit inside your content container – otherwise they'll be listed as a list.
So for example if your content container is 960px wide, you should add / modify something like this to your theme's stylesheet, adjusted to your personal preferences of course:
for the container:
.my-container-view #content {
width:960px;
}
for the items:
.my-container-view .item {
width:320px;
float:left;
}
The float might be redundant since masonry should take care of that – but this is at least what I have in my stylesheet…

How to render (in pdf) responsive pages in PhantomJS

I'm wondering how to render responsive pages using PhantomJS in pdf format.
I have tried so many responsive pages and found that it is printing the pdf using the print css.
So, if the page includes the print css OR screen only css it will render the pdf same as we found via print command preview (Ctrl + p).
Is there any way OR script by which i can get the pdf as I'm seeing them on web browser?
Attaching the file when i tried to get the pdf from http://getbootstrap.com/examples/jumbotron/.
Also the main issue is not responsive designes, the issue is print css applied over them.
example pdf
jorupp came up with a javascript solution in this gist. It essentially let's you "lock" all the media queries in the document's stylesheets to whatever applies presently, before changing to print mode.
In case the link ever disappears, here's the code:
function process(rule) {
if(rule.cssRules) {
for(var i=rule.cssRules.length-1; i>=0; i--) {
process(rule.cssRules[i]);
}
}
if(rule.type == CSSRule.MEDIA_RULE) {
if(window.matchMedia(rule.media.mediaText).matches) {
rule.media.mediaText = "all";
} else {
rule.media.mediaText = "not all";
}
}
return rule;
}
for(var i=0; i<document.styleSheets.length; i++) {
process(document.styleSheets[i]);
}
This is quite tricky since there is no option to tell PhantomJS to use the screen when rendering as PDF.
You would need to
load all the linked stylesheets that contain a print block with __utils__.sendAJAX,
remove #media print block (this is quite hard with regex because you need to look out for balanced braces, but relatively easy with plain JS),
maybe you even need to rename #media screen to #media print,
remove the linked stylesheet from the document and
add a style element which has the manipulated stylesheet inside (preferable in the same place as the previous stylesheet) to the DOM.
Your page won't look good, because you usually have page breaks and the like with pdf. Also, page width and viewport width are quite hard to get right. Changing the page width doesn't change the viewport, so it won't be the proper responsive that would have with a pixel perfect png. But that is only a solution if you don't need selectable text.

How do I make the whole of a DNN 7 Container/HTML Module a link?

I have a DNN skin that has some nice containers. I can drop an HTML module onto the page and apply the container to it. I can put a link in the content of the HTML Module, but what I would really like to do is make the whole container/module area a link to another page - in effect as if it were a great big button. How do I do this?
Of course as soon as I posted the question I found a way, but would still be interested to know if this is the "right" way or even a "good" way.
My solution was to take a copy of the container .ascx and add an "onlick" to the outer DIV, which in turn uses JQuery to locate the first tag and to navigate to the href.
<div class="Container-1 Container-1-color1"
onclick="window.location.href = $('a:first',this).attr('href')">
Note: Use window.location.href, not JQuery .click() or .trigger('click') as this creates an infinite loop.
I then added some CSS to show that an action was available when the mouse was over the container:
.Container-1:hover
{
opacity:0.8;
filter:alpha(opacity=80); /* For IE8 and earlier */
border:1px solid gray;
}

Resources