enter image description here
I use puppeteer for generate an invoice PDF.
I have a template that is render with nunjucks, I set the content with the puppeteer page function setContent
I have defined a header and a footer, same thing I generate the template with nunjucks
When I render the PDF (await page.pdf(...)) the scale of the header and the footer are larger than the content. The font-scale is 12px and it's larger on the header/footer, same thing for the margin.
Anyone alreay have the issue ? How to fix it ?
I want to have the same scale on header/footer than the content
Here some code:
const html = nunjucks.render(QUOTE_TPL, { $t: i18n.__, quote: foundQuote, linesByPages, keys, fullWidthHeader, currency: '', format: formatPrice, moment, pdf: true, headless_mode });
const footerHtml = nunjucks.render(QUOTE_FOOTER, { $t: i18n.__, quote: foundQuote })
const headerHtml = nunjucks.render(QUOTE_HEADER, { $t: i18n.__, quote: foundQuote, moment })
// Convert HTML quote to PDF
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.emulateMediaType('print')
await page.setContent(html);
const filePath = path.resolve('./tmp/' + file_name + new Date().getTime() +'.pdf');
await page.pdf({
path: filePath,
format: 'A4',
displayHeaderFooter: true,
headerTemplate: headerHtml,
footerTemplate: footerHtml,
margin: {
bottom: '80px',
top: foundQuote.style.header.height + 80 + 'px',
}
});
await browser.close();
And here an example of the header template:
<div style="
-webkit-print-color-adjust:exact;
width: 100%;
max-width: 21cm;
position: relative;
background: #00c1af;
padding: 0;
">
{% if quote.display_rules.title != null %}
<div class="invoice-title {{quote.display_rules.title}}" style="
font-family: 'Roboto', sans-serif !important;
font-weight: bold !important;
color: #212529 !important;
position: absolute;
-webkit-font-smoothing: antialiased !important;
-moz-osx-font-smoothing: grayscale !important;
-webkit-print-color-adjust: exact !important;
font-smooth: always !important;
font-size: 15px;
top: 2cm;
right: 2cm;
">
{{ quote.title }}
</div>
{% endif %}
<div class="invoice-header" style="
background: #ffff00;
width: 100%;
margin: 0;
padding: 0 1.9cm);
">
{% if (quote.style and quote.style.header and quote.style.header.image) or (quote.company_logo) %}
<div class="logo-wrapper {{fullWidthHeader}}" style="height:{{quote.style.header.height }}px;margin:{{quote.style.header.margin}}px">
{% if headless_mode !== 'true' %}
{% if quote.company_logo %}
<img class="logo" src="{{ quote.company_logo }}" alt="" style="position: relative; width: auto;height: 100%;max-height: 100%;"/>
{% else %}
<img class="logo" src="{{ quote.style.header.image }}" alt="" style="position: relative; width: auto;height: 100%;max-height: 100%;"/>
{% endif %}
{% endif %}
</div>
{% endif %}
<div class="invoice-name" style="
font-family: 'Roboto', sans-serif !important;
color: #212529 !important;
-webkit-font-smoothing: antialiased !important;
-moz-osx-font-smoothing: grayscale !important;
-webkit-print-color-adjust: exact !important;
font-smooth: always !important;
font-weight: bold !important;
font-size: 15px;
">
<span>
{{ $t('documents.' + (quote.language or 'fr-FR') + '.' + quote.name.trim()) }} {{ quote.number }}
</span>
<span class="invoice-date">
{{ $t("documents." + (quote.language or 'fr-FR') + ".from") }} {{ moment(quote.date).format($t("date." + (quote.language or 'fr-FR') + ".format")) }}
</span>
</div>
</div>
</div>
Related
I need a timer in my store, therefore I have taken from the internet a code. Only unfortunately this code is not in the middle or top but at the bottom, under the footer. can someone help me to have the timer on top or in the middle?
{% if end_date != blank %}
<div class="timer">
{% if title != blank %}
<h4 class="timer__title">{{ title }}</h4>
{% endif %}
<div class="timer-display">
<div class="timer-block">
<span class="timer-block__num js-timer-days">00</span>
<span class="timer-block__unit">Days</span>
</div>
<div class="timer-block">
<span class="timer-block__num js-timer-hours">00</span>
<span class="timer-block__unit">Hours</span>
</div>
<div class="timer-block">
<span class="timer-block__num js-timer-minutes">00</span>
<span class="timer-block__unit">Minutes</span>
</div>
<div class="timer-block">
<span class="timer-block__num js-timer-seconds">00</span>
<span class="timer-block__unit">Seconds</span>
</div>
</div>
</div>
<style>
/* styles for timer */
.timer {
background: #f6fafd;
padding: 10px;
margin: 10px 0;
}
.timer--expired {
display: none;
}
.timer__title {
#extend .paragraph;
text-align: center;
}
.timer-display {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
margin-top: 5px;
}
.timer-block {
position: relative;
width: 25%;
padding: 0 10px;
&:not(:last-child):after {
content: ':';
position: absolute;
right: 0;
top: 3px;
}
}
.timer-block__num,
.timer-block__unit {
display: block;
text-align: center;
}
</style>
<script type="text/javascript">
var second = 1000,
minute = second * 60,
hour = minute * 60,
day = hour * 24;
var countDown = new Date('{{- end_date -}}').getTime(),
x = setInterval(function() {
var now = new Date().getTime(),
distance = countDown - now;
document.querySelector('.js-timer-days').innerText = Math.floor(distance / (day)),
document.querySelector('.js-timer-hours').innerText = Math.floor((distance % (day)) / (hour)),
document.querySelector('.js-timer-minutes').innerText = Math.floor((distance % (hour)) / (minute)),
document.querySelector('.js-timer-seconds').innerText = Math.floor((distance % (minute)) / second);
}, second)
</script>
{% endif %}
i want it in the middle or in the top
How its look now
Ive trided to change the code but nothing work
The part of the page which displays the card logo is from the the following HTML. When searching through the project folder, I don't find this anywhere. I tried to look this up in the Edit Code section of the Shopify admin, but didn't find. All I need to do is replace the default logos with a single custom logo that I have. The image following the code shows that I part I am looking for the code for.
<div id="trust-badge-content-div" class="trust-badge-preview trust-badge-product" data-trustbadge-specificity="1" data-hc-insertion-order="0" style="box-sizing: border-box; text-align: center; width: 100%; margin: 15px 0px;"><div class="tb-text-div" style="display: inline-block; font-size: 12px;"><div class="tb-text" style="color: rgb(0, 0, 0); font-size: 15px; font-weight: normal; text-align: center;">Secure checkout with major credit cards including these and more.</div><div class="tb-badge-div"><div class="tb-badge" style="width: 65px; display: inline-block; margin: 0px 7px; vertical-align: top;"><img class="tb-svg" src="https://hektorcommerce.com/apps/trustbadge/svg_images/?image=122-american-express" alt="American Express" style="width: 50px; height: 50px;"></div><div class="tb-badge" style="width: 65px; display: inline-block; margin: 0px 7px; vertical-align: top;"><img class="tb-svg" src="https://hektorcommerce.com/apps/trustbadge/svg_images/?image=120-discover" alt="Discover" style="width: 50px; height: 50px;"></div><div class="tb-badge" style="width: 65px; display: inline-block; margin: 0px 7px; vertical-align: top;"><img class="tb-svg" src="https://hektorcommerce.com/apps/trustbadge/svg_images/?image=129-visa" alt="Visa" style="width: 50px; height: 50px;"></div><div class="tb-badge" style="width: 65px; display: inline-block; margin: 0px 7px; vertical-align: top;"><img class="tb-svg" src="https://hektorcommerce.com/apps/trustbadge/svg_images/?image=108-master-card-1" alt="MasterCard" style="width: 50px; height: 50px;"></div></div></div></div>
To better help you, please share the name of the theme you use.
In general, the option to show or hide cards is on the footer or on the theme settings. Go to theme / customize and search for the option to hide credit cards in these two places.
UPDATE: on theme prestige the option is on footer.
after find the option on customize (footer section) go to edit code
sections/footer (around line 156 depending your previous customizetions) you'll find this:
{%- if section.settings.show_payment_methods -%}
<!-- change the content of this if -->
{%- capture payment_methods -%}
{%- for type in shop.enabled_payment_types -%}
<li class="HorizontalList__Item">{{ type | payment_type_svg_tag }}</li>
{%- endfor -%}
{%- endcapture -%}
{%- if payment_methods != blank -%}
<ul class="Footer__PaymentList HorizontalList">
{{ payment_methods }}
</ul>
{%- endif -%}
{%- endif -%}
While I am open to any solution, counting tables, Bootstrap and Flexbox, a purely CSS solution using just div elements is greatly appreciated.
HTML
<div class="sentence-summary">
<div class="stat bookmarked">
<i class="fas fa-bookmark"></i>
<span class="count">999</span>
</div>
<div class="stat upvotes">
<i class="fas fa-thumbs-up"></i>
<span class="count">999</span>
</div>
<div class="stat downvotes">
<i class="fas fa-thumbs-down"></i>
<span class="count">999</span>
</div>
<div class="main">
<p>{{ $sentence->body }}</p>
</div>
</div>
SCSS
.sentence-summary {
div {
display: inline-block;
}
.stat {
width: 40px;
text-align: center;
span {
display: block;
font-size: 10px;
}
&.bookmarked {
background-color: red;
}
&.upvotes {
background-color: blue;
}
&.stat.downvotes {
background-color: pink;
}
}
.main {
background-color: green;
}
}
Current Result
Desired Result
I would recommend using a grid layout for this. You can specify that the first three columns (stats) should be 40px wide. And then use '1fr' to say that the 'main' sections should take up the remaining space. Using a grid means that the heights will stay the same.
You can use 'grid-column-gap' to specify the amount of space you would like between each column. Something like this:
.sentence-summary {
display: grid;
grid-template-columns: 40px 40px 40px 1fr;
column-gap: 5px;
grid-auto-rows: 40px;
}
Make sure you use the appropriate browser prefixes as this syntax isn't supported by all browsers. I usually use this auto-prefixer.
Update: Adding grid-auto-rows: 40px; makes sure your 'stats' stay square!
So, I have a project that I've taken on that already has a slick carousel, not familiar with drupal or bootstrap, but from what I can see the current follows documentation. The carousel is triggered upon the breakpoint (as confirmed by the carousel arrows that appear at the breakpoint), However the carousel is not horizontal and the arrows do not work. Please advise.
app.js
explore: function explore() {
$('.explore-carousel').slick({
autoplay:true,
mobileFirst:true,
infinite: false,
dots: false,
slidesToShow: 2,
slidesToScroll: 1,
prevArrow: $('.explore-prev'),
nextArrow: $('.explore-next'),
responsive: [{
breakpoint: 500,
settings: {
slidesToShow: 1
}
}]
});
},
exploreResize: function exploreResize(carousel) {
// https://github.com/kenwheeler/slick/issues/3282
$(window).on('load resize orientationchange', function () {
$(carousel).each(function () {
var $carousel = $(this);
if ($(window).width() > 768) {
if ($carousel.hasClass('slick-initialized')) {
$carousel.slick('unslick');
}
} else {
if (!$carousel.hasClass('slick-initialized')) {
CB.carousel.explore(carousel);
}
}
});
});
},
explore.twig
<section class="explore">
<a class="explore-prev"><img src="../lib/img/icon-carousel-arrow-left.svg"></a>
<a class="explore-next"><img src="../lib/img/icon-carousel-arrow-right.svg"></a>
<div class="explore-carousel grid-x grid-container align-center">
{% for block in entry.exploreMatrix.all() %}
{% set image = block.icon.one() %}
{% set link = block.linkUrl.one() %}
{% set length = loop.length %}
{% set col = 12/length %}
<div class="cell small-12 large-{{ col ? col : 4 }}">
<a class="explore--link" href={{ link.url }}>
<div class="outline">
<img class="explore-image" src="{{ image ? image.url : '' }}">
<div class="hover--container">
<div class="hr"></div>
<h3 class="hover--text">{{ block.linkText }}<span class="button-icon"> {% include 'includes/svg/cta-arrow' %}</span></h3>
</div>
</div>
</a>
</div>
{% endfor %}
</section>
css
.explore {
margin-top: 80px;
#include mq($small) {
margin-top: 0;
}
position: relative;
.explore-prev {
#extend .PrevArrow;
}
.explore-next {
#extend .NextArrow;
}
.explore-carousel {
display: flex;
#include h-padding(rem-calc(50));
// padding-left: rem-calc(50);
// padding-right: rem-calc(50);
#include mq($medium) {
// padding-left: initial;
// padding-right: initial;
#include h-padding(initial);
}
.explore--link {
width: 100%;
}
.outline {
position: relative;
width: rem-calc(250);
border-radius:50%;
transition: all .3s;
margin: 0 auto;
#include spacer(50px, 50px);
&.hover {
background: $offWhite;
}
#include mq($medium) {
width: rem-calc(300);
}
.hover--container {
transition: all .3s;
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
bottom: 5%;
text-align: center;
opacity: 0;
.hover--text {
margin-top:rem-calc(10);
font-size: rem-calc(22);
color: $clay;
letter-spacing: -1px;
}
}
.explore--image {
width: rem-calc(250);
margin: 0 auto;
#include mq($medium) {
width: rem-calc(300);
}
}
}
.hover {
.hover--container {
transition: all .3s;
opacity: 1;
}
}
}
}
Not sure about the 'not horizontal' issue, but i recommend you to remove all css and run slick carousel in a sandbox. When done, add your CSS code.
CSS overrides can be painfull with slick.
About the arrows, i guess you need to register as string HTML markup. Like this:
prevArrow:'<div> my custom prev arrow </div>'
I am trying to make a nice layout of items in a grid using a bin packing algorithm like packery or masonry. I Already have isotope installed so will use the packery plugin for that.
If you look at the example here http://codepen.io/desandro/pen/vdwmb this is exactly the kind of thing I need, but the problem I think I'm going to face is the content of the items are via a CMS.
<h1>Isotope - packery layout mode</h1>
<div class="grid">
<div class="grid-item grid-item--width2"></div>
<div class="grid-item grid-item--height2"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item grid-item--width2 grid-item--height2"></div>
<div class="grid-item grid-item--width2"></div>
<div class="grid-item grid-item--width2"></div>
<div class="grid-item grid-item--height2"></div>
<div class="grid-item"></div>
<div class="grid-item grid-item--width2"></div>
<div class="grid-item grid-item--height2"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
</div>
* { box-sizing: border-box; }
body { font-family: sans-serif; }
/* ---- grid ---- */
.grid {
background: #DDD;
max-width: 1200px;
}
/* clear fix */
.grid:after {
content: '';
display: block;
clear: both;
}
/* ---- .grid-item ---- */
.grid-item {
float: left;
width: 100px;
height: 100px;
background: #0D8;
border: 2px solid #333;
border-color: hsla(0, 0%, 0%, 0.7);
}
.grid-item--width2 { width: 200px; }
.grid-item--height2 { height: 200px; }
$('.grid').isotope({
layoutMode: 'packery',
itemSelector: '.grid-item'
});
Possibly more of a maths question, but Im assuming for packery to work the items all have to be of a size in relation to each other, ie in the example above all the items are multiples of the smallest item.
Is this assumption correct, and is there anything else i need to consider?