In my laravel 5.7 / bootstrap 4.4 app I use
spatie/browsershot 3.37 and spipu/html2pdf 5.2 to generate pdf file
and for my generated pdf file want I set layout with 100% height and footer and
header like here: https://jsfiddle.net/MadLittleMods/LmYay/
But imported block of code which looks ok on my blade page in browser is invalid in generated
pdf : as all css styles are lost.
by clicking on “To pdf file” content of the page is rendered into pdf file:
Browsershot::html(htmlspecialchars_decode($pdf_content))
->showBackground()
->save($save_to_file);
if($hidden_action== 'upload') {
\Response::download($save_to_file, $filename_to_save, array('Content-Type: application/octet-stream', 'Content-Length: pdf'));
return response()->download($save_to_file, $filename_to_save)->deleteFileAfterSend(true);
}
in my blade file:
#extends($current_admin_template.'.layouts.backend')
#section('content')
#inject('viewFuncs', 'App\library\viewFuncs')
<div id="page-wrapper" class="card">
// THIS PART LOOKS OK IN BROWSER BUT IN GENERATED PDF INVALID AS ALL CSS CLASSES ARE LOST
<div class="flexbox-parent" id="div_invoice_content" style="display: flex;">
<input type="hidden" id="hidden_invoice_no" name="hidden_invoice_no" value="{{$invoice_no}}">
<input type="hidden" id="hidden_invoice_id" name="hidden_invoice_id" value="{{$invoice_id}}">
<div class="flexbox-item header">
Header $invoice_no::{{$invoice_no}}<br>
$invoice_id::{{$invoice_id}}
</div>
<div class="flexbox-item fill-area content flexbox-item-grow">
<div class="fill-area-content flexbox-item-grow">
Content
<br /><br />
Emulates height 100% with a horizontal flexbox with stretch
<br /><br />
This box with a border should fill the blue area except for the padding (just to show the middle flexbox item).
</div>
</div>
<div class="flexbox-item footer">
Footer
</div>
</div>
<form method="POST" action="{{ url('/admin/generate-pdf-by-content') }}" accept-charset="UTF-8" id="form_print_to_pdf_content"
name="form_print_to_pdf_content"
enctype="multipart/form-data">
{!! csrf_field() !!}
<div class="form-row m-3">
...
FORM CONTENT
...
</div>
</section> <!-- class="card-body" -->
</div>
<!-- /.page-wrapper page Content : invoice edit -->
#endsection
{{--#section('head')--}}
{{--#push('scripts')--}}
<style lang="css">
.flexbox-parent
{
height: 842pt !important;
width: 595pt !important;
display: flex;
flex-direction: column;
justify-content: flex-start; /* align items in Main Axis */
align-items: stretch; /* align items in Cross Axis */
align-content: stretch; /* Extra space in Cross Axis */
background: rgba(255, 255, 255, .1);
}
.flexbox-item
{
padding: 8px;
}
.flexbox-item-grow
{
flex: 1; /* same as flex: 1 1 auto; */
}
.flexbox-item.header
{
background: rgba(255, 0, 0, .1);
}
.flexbox-item.footer
{
background: rgba(0, 255, 0, .1);
}
.flexbox-item.content
{
background: rgba(0, 0, 255, .1);
}
.fill-area
{
display: flex;
flex-direction: row;
justify-content: flex-start; /* align items in Main Axis */
align-items: stretch; /* align items in Cross Axis */
align-content: stretch; /* Extra space in Cross Axis */
}
.fill-area-content
{
background: rgba(0, 0, 0, .3);
border: 1px solid #000000;
/* Needed for when the area gets squished too far and there is content that can't be displayed */
overflow: auto;
}
</style>
{{--#endpush--}}
{{--#endsection--}}
#section('scripts')
<link rel="stylesheet" href="{{ asset('/css/gijgo.min.css') }}" type="text/css">
<script src="{{ asset('js/AutoNumeric/autonumeric#4.1.0') }}"></script>
...
#endsection
I tried to put <style block in several places of the page, but in all cases
in generated pdf as all css styles are lost
Which is valid way to use css classes in the generated file?
MODIFIED BLOCK 1:
I created file public/css/flb_layout.css with all flexbox classes definitions and
in my blade file I added asset to this css file:
#section('scripts')
<link rel="stylesheet" href="{{ asset('/css/gijgo.min.css') }}" type="text/css">
<link rel="stylesheet" href="{{ asset('/css/flb_layout.css') }}" type="text/css">
...
and checking source of generated html file I see link to flb_layout.css file:
</footer>
<link rel="stylesheet" href="http://local-boxbooking2.com/css/gijgo.min.css" type="text/css">
<link rel="stylesheet" href="http://local-boxbooking2.com/css/flb_layout.css" type="text/css">
where http://local-boxbooking2.com - is hosting of my local app.
and as result in my browser I see that flexbox layout is rendered ok,
but generating pdf file I see plain html without flexbox classes definitions applied.
Which way is valid ?
MODIFIED BLOCK 2:
I found a hint:
The asset function generates a URL for an asset using the current
scheme of the request (HTTP or HTTPS)
The library you're using launches a puppeteer instance in the
background to capture the PDF.
Instead of generating a URL, try generating an absolute path to the
file on your machine: (obviously you can leave out the mix helper if
you do not use Laravel Mix)
> <link rel="stylesheet" href="{{
> public_path(mix('/path/to/styles.css')) }}" />
So in my blade form I chanhed refering to my css :
<link rel="stylesheet" href="{{ public_path('/css/flb_layout.css') }}">
As result my css classes are not rendered in the page of the browser.
In generated pdf file my css classes are not rendered too.
In my project I use webpack.mix.js with definitions:
const mix = require('laravel-mix');
let current_admin_template= 'Backend';
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/' + current_admin_template + '/backend.scss', 'public/css/' + current_admin_template)
.sass('resources/sass/' + current_admin_template + '/style_lg.scss', 'public/css/' + current_admin_template)
.sass('resources/sass/' + current_admin_template + '/style_md.scss', 'public/css/' + current_admin_template)
.sass('resources/sass/' + current_admin_template + '/style_sm.scss', 'public/css/' + current_admin_template)
.sass('resources/sass/' + current_admin_template + '/style_xs_320.scss', 'public/css/' + current_admin_template)
.sass('resources/sass/' + current_admin_template + '/style_xs_480.scss', 'public/css/' + current_admin_template)
.sass('resources/sass/' + current_admin_template + '/style_xs_600.scss', 'public/css/' + current_admin_template)
.sass('resources/sass/debug.scss', 'public/css' )
;
Can it be used anyway?
Thanks!
It does not work like that in pdf Parser plugin.. give all css inline. NOTE: no files can be read directly.
I failed to add css classes to spipu/html2pdf and had to move into https://github.com/spatie/browsershot
with style definition :
Browsershot::url('https://example.com')
->setOption('addStyleTag', json_encode(['content' => 'body{ font-size: 14px; }']))
->save($pathToImage);
which works ok for me...
Related
I am working on a project. How can I use Javascript to reveal a centered image when clicking inside a box without using a button?
Like this you mean? I used javascript a little, but it works!!!
<!DOCTYPE html>
<html>
<body>
<div style="background-color: red; width: 50px; height: 50px;" onclick="xSignDisplayLetter()" id="one"></div>
<br />
<div style="background-color: red; width: 50px; height: 50px;" onclick="xSignDisplayLetterVerTwo()" id="two"></div>
<br />
<div style="background-color: red; width: 50px; height: 50px;" onclick="revealImg()" id="image"></div>
<script>
function revealImg() {
document.getElementById("image").innerHTML = "<img src='https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png' alt='Image' style='width: 50px; height: 50px;' />"
}
function xSignDisplayLetter() {
document.getElementById("one").innerHTML = "<img src='https://image.freepik.com/free-icon/x-symbol_318-1407.jpg' alt='Image' style='width: 50px; height: 50px;' />"
}
function xSignDisplayLetterVerTwo() {
document.getElementById("two").innerHTML = "<img src='https://d3qdvvkm3r2z1i.cloudfront.net/media/catalog/product/cache/1/image/1800x/6b9ffbf72458f4fd2d3cb995d92e8889/n/o/nope_newthumb.png' alt='Image' style='width: 50px; height: 50px;' />"
}
</script>
</body>
</html>
If you don't know javaScript a little, then there are js tutorials all over the web.
W3Schools is a good idea for short-term tutorials that teach you a lot, and is relatively fun to mess around with.
CodeCademy is a good long-term full code tutorial that will take a few weeks to learn but helps a million via your coding skill. You will need to sign up but it's free and saves all your work (code) when you're done.
You should load the image in your HTML and hide it using a CSS class like hidden. Then you will want to use addEventListener to run a function when the image is clicked, which toggles the visibility of the image. The centering of the image can also be done using CSS.
const blocks = document.querySelectorAll('.block');
blocks.forEach((block) => {
block.addEventListener('click', () => toggleVisibility(block.querySelector('img')));
});
function toggleVisibility(el) {
el.classList.toggle('hidden');
}
.container {
display: flex;
}
.block {
background-color: red;
padding: 10px;
}
.hidden {
display: none;
}
<div class="container">
<div class="block">
<img src="https://www.placehold.it/150x150">
</div>
<div class="block">
<img src="https://www.placehold.it/150x150">
</div>
<div class="block">
<img src="https://www.placehold.it/150x150">
</div>
</div>
add an onclick attribute to your boxes that calls a function that shows a hidden image.
<div onclick="showImages()"></div>
you can add onclick listener to div and in onclick function you can change div's class
<div class="redbox" id="box" onclick="showImage()"></div>
showImage(){
var box =document.getelementbyid("box").
box.classList.remove("redbox");
box.classList.add("image");
}
I am creating a website about UFC and need help with my image positioning I have 3 images and want to place them in a horizontal arrangement across the screen but am having trouble doing this.I have created a div around each of the images to try and position them but cannot seem to get the result that I want, any help would be great.
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="website.html">
<link rel="stylesheet" type="text/css" href="topfightercss.css">
<h1><u>Top Fighters</u></h1>
</head>
<body>
<div id="demetrious">
<img src="dem.png" alt="Demetrious Johnson"> <p> Demetrious Johnson is the
rank 1 pound for pound fighter in UFC,<br>he is from Kentucky USA and is
aged 31 and stands at 5'3 (160cm)<br>he weights 56kg (125lb) and has a reach
of 66" with a leg reach of 34".<br>He has a record of 27 wins 2 losses and 1
draw and is the curent<br> flyweight champion. </p>
</div>
<div id="connor">
<img scr="connor.png" alt="Connor Mcgegor">
</div>
<div id="daniel">
<img scr="daniel.png" alt="Daniel Cormier">
</div>
</body>
</html>
CSS
html {
background: url(pg2background.jpg);
background-attachment: fixed;
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
}
h1 {
color: aqua;
text-align: center;
font-size:24pt;
}
.demetrious {
position: relative;
top: 8px;
left: 12px;
width: 450px;
height: 300px;
opacity: 0.3;
}
p {
color: aliceblue;
}
.connor {
position: center;
top: 8px;
right:12px;
}
.daniel {
position: relative;
}
You can set up a container div with class .container with a fixed width of x pixels, x = 3 * image width, because you have three images. Only use this if you want the images to stay horizontally aligned when the browser window is smaller than the width of 3x
.container{
width: x px;
}
Then give a shared class to your image divs, let's call it .imgClass. Now turn them to float;
.imgClass{
float:left;
}
EDIT: This means your topfightercss.css css file should include something like this:
.container{
width: 300 px; //Three times 100px = 300px
}
.imgClass{
float:left;
width: 100px; //All pictures are 100px wide. Not required.
}
And your html file:
<div class="container">
<div class="imgClass"> <img><p>...</p> </div> <!-- demetrious -->
<div class="imgClass"> <img><p>...</p> </div> <!-- connor -->
<div class="imgClass"> <img><p>...</p> </div> <!-- daniel -->
</div>
I'm building a responsive site and I have an image that I'd like to have a fixed height, but as the window collapses the image remains centred as the container width decreases. I've have tried several things and I have the height fixed but the image doesn't centralise when in a view less than 100% of the image width.
Any help is greatly appreciated.
Thanks
.container {
overflow: hidden;
}
.container img {
width: auto;
height: 550px;
}
<div class="container">
<img src="http://placehold.it/500x550" alt="alt" />
</div>
see here your height is fixed but also responsive . i just give an example image .
add this class into your image class="img-responsive"
.container {
overflow: hidden;
}
.container img {
height: 550px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="container">
<img src="http://media1.santabanta.com/full1/Miscellaneous/Cartoon%20Characters/cartoon-characters-14a.jpg" alt="alt" class="img-responsive" >
</div>
Im fairly new to this so please bear with...
I'm using the tutorial # http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/index.html
to allow the user to select dates from a calendar
however I can't seem to get it working could someone please advise if I am going about this the wrong way...
'jquery.datePicker.js & datePicker.css' can be downloaded at near the top of the page on...
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/index.html
Copy the code in the '•jquery.datePicker.js ' inside my tags in my view
Copy the datePicker.css code into my css file
Paste the following into the top of my view page:
<!-- jQuery -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<!-- required plugins -->
<script type="text/javascript" src="scripts/date.js"></script>
<!--[if IE]><script type="text/javascript" src="scripts/jquery.bgiframe.js"></script><![endif]-->
<!-- jquery.datePicker.js -->
<script type="text/javascript" src="scripts/jquery.datePicker.js"></script>
This does not work...iv tried doing the first demo and replacting the .js data inside my<script> tags with
$(function()
{
$('.date-pick').datePicker();
});
and then adding the following to .css
/* located in demo.css and creates a little calendar icon
* instead of a text link for "Choose date"
*/
a.dp-choose-date {
float: left;
width: 16px;
height: 16px;
padding: 0;
margin: 5px 3px 0;
display: block;
text-indent: -2000px;
overflow: hidden;
background: url(calendar.png) no-repeat;
}
a.dp-choose-date.dp-disabled {
background-position: 0 -20px;
cursor: default;
}
/* makes the input field shorter once the date picker code
* has run (to allow space for the calendar icon
*/
input.dp-applied {
width: 140px;
float: left;
}
could someone please tell me what I am doing wrong?
Resources to add
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/scripts/date.js
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/scripts/jquery.datePicker.js
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/styles/datePicker.css
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/styles/demo.css
<form name="chooseDateForm" id="chooseDateForm" action="#">
<fieldset>
<legend>Test date picker form</legend>
<ol>
<li>
<label for="date1">Date 1:</label>
<input name="date1" id="date1" class="date-pick" /></li>
<li>
<label for="date2">Date 2:</label>
<input name="date2" id="date2" class="date-pick" />
</li>
<li>
<label for="test-select">Test select:</label>
<select name="test-select" id="test-select" style="width: 170px">
<option value="1">Test SELECT </option>
<option value="2">Doesn't shine through</option>
<option value="3">Even in IE</option>
<option value="4">Yay!</option>
</select>
</li>
</ol>
</fieldset>
</form>
Javascript
$('.date-pick').datePicker();
CSS
a.dp-choose-date {
float: left;
width: 16px;
height: 16px;
padding: 0;
margin: 5px 3px 0;
display: block;
text-indent: -2000px;
overflow: hidden;
background: url(http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/images/calendar.png)
no-repeat; }4 a.dp-choose-date.dp-disabled {
background-position: 0 -20px;
cursor: default; } /* makes the input field shorter once the date picker code * has run (to allow space for the calendar icon */
input.dp-applied {
width: 140px;
float: left; }
Check the fiddler i have setup the demo there also remember to check the resources i have added
http://jsfiddle.net/imranpk/DNFuB/4/
Thanks for the reply, i got it going
had to...add the following to my layout page
<script src="#Url.Content("http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/scripts/date.js")" type="text/javascript"></script>
<script src="#Url.Content("http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/scripts/jquery.datePicker.js")" type="text/javascript"></script>
<link href="#Url.Content("http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/styles/datePicker.css")" rel="stylesheet" type="text/css" />
<link href="#Url.Content("http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/styles/demo.css")" rel="stylesheet" type="text/css" />
then in my .cshtml file I added (below) after the editor for ref.
<script>
$("#HolidayDate").addClass('date-pick');
$('.date-pick').datePicker();
</script>
I'm having a issue with the min-height in firefox, I'm trying to put it at 100% but it is not working. In Chrome it works perfectly.
My code is:
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="../css/main.css"/>
</head>
<body>
<div class="main">
<div class="header">Here is the header</div>
<div class="content ">Here is the content</div>
<div class="footer">Here is the footer</div>
</div>
</body>
</html>
And the css file is
.header {
height:160px;
}
.content{
min-height: 100%;
height: auto !important;
height: 100%;
}
.footer{
margin: -215px auto 0 0;
height: 55px;
}
All I'm trying to do is to keep the footer at the bottom of the page, in Chrome it is working, but in firefox it takes no height for the content.
I've been looking for the solution and in many people say to put
#page{min-height:100%;}
html, body{min-height:100%;}
but it makes the same, it still works in chrome but not in firefox.
Can somebody help me?
Thanks
if you're just trying to keep the footer at the bottom you could use
.footer{
position:fixed; /*or absolute, or whatever*/
bottom:0px;
height: 55px;
}