i use barryvdh/laravel-dompdf in laravel 5.5 and bootstrap css (renamed to pdf.css with small adjustments) to generate a report in pdf
this is my header from the report view calling the css:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link href="{{public_path('css/pdf.css') }}" rel="stylesheet" type="text/css" />
</head>
<body>
my controller:
public function infor(News $news)
{
...
PDF::setOptions(['dpi' => 150, 'defaultFont' => 'sans-serif']);
$pdf = PDF::loadView('admin.news_events.pdf');
return $pdf->stream('pdfview.pdf');
}
Expected view (html5):
view generated in pdf :,(
How could I solve this?
You have to put all css file in style tag to launch your code
barryvdh/laravel-dompdf does not support boostrap yet.
Quoting the author:
I highly doubt that DomPDF can handle Bootstrap correctly.
If you need better pdf, try: https://github.com/barryvdh/laravel-snappy
That used Webkit to render pdf.
See more about the issue here
I had the same issue, all I did was create another blade file, copied bootstrap.css contents into it (between style tags) , then included it (the file with the css) in the file I wanted to print
Change your file path to this, if CSS and images are not inside the public directory.
<img src="{{ base_path().'/location/to/image/image.png' }}" />
<link rel="stylesheet" type="text/css" href="{{ base_path().'/location/css/bootstrap.min.css' }}">
You should use another version of bootstrap. because i tested it with bootstrap 3 and it's not working but it works with version 4 of the framework.
Related
enter image description hereI added a css link to my php file, but it won't show the changes.
My css file is named register.css and my php file is named register.php.
<?php
include("includes/config.php");
include("includes/classes/Account.php");
include("includes/classes/Constants.php");
$account = new Account($con);
include("includes/handlers/register-handler.php");
include("includes/handlers/login-handler.php");
function getInputValue($name) {
if(isset($_POST[$name])) {
echo $_POST[$name];
}
}
?>
<html>
<head>
<title>Welcome to Napster!</title>
<link rel="stylesheet" type="text/css" href="assets/css/register.css"/>
</head>'
My css file is in assets file which is in same file as my php file.
I am using xamp and sublime text.
it seems the issue is either browser cache or related to path..
please try
<link rel="stylesheet" type="text/css" href="assets/css/register.css?v=1.1"/>
if register.php is not in root folder then try..
<link rel="stylesheet" type="text/css" href="../assets/css/register.css?v=1.1"/>
here ?v=1.1 is added to load updated css. whenever you make changes in css file, simply chage v=1.1 with another number like v=1.2 etc... to avoid clear cache in browser and load updated css...
I have a interesting trouble, in my view I have:
<base href="{{asset('')}}" />
<link href="ad/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
that my css's link , it was long but it still worked a month ago, but now it doesn't work, and I try :
<link href="{{ URL::asset('ad/bower_components/bootstrap/dist/css/bootstrap.min.css') }}" rel="stylesheet">
too, but it haven't worked yet,
but when I try a shorter link, it works normally, so why?
<link href="{{asset('link_to_css_file_in_public_folder')}}" rel="stylesheet" >
That should work.
Ps: put this code in your layouts->app.blade.php or any other layout you use.
in case you want to load separate css file in different pages in your layout call this #yield('styles') and then in your blade import your css file like my sample above inside
#section('styles')
your_code
#endsection
<link rel="stylesheet" href="{{URL::to('/')}}/asset/ad/bower_components/bootstrap/dist/css/bootstrap.min.css">
is your asset folder in public folder or not?..if it then it works
I have seen many questions here regarding Laravel 5 finding css and script assets. I have done what those answers suggest, mainly using a blade.php template and using either asset() or URL::asset, but sadly none of these work. I suspect something else is wrong here.
I am getting to my view directly, using http://[MyIP]/[ProjectName]/resources/views/[MyFile].blade.php in the address bar. My scripts and css are in the public folder, within directories javascript and css respectively.
When I load [MyFile].blade.php, which looks like so:
<title>My File</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="stylesheet" href="{{ URL::asset('css/font-awesome.min.css')}}">
<link rel="stylesheet" href="{{ URL::asset('css/animatemolly.css')}}">
<link rel="stylesheet" href="{{ asset('css/molly.css')}}">
<script src="{{ URL::asset('javascript/jquerymin.js')}}"></script>
It finds none of those. And in the served page, I get this error:
GET http://[MyIp]/[ProjectName]/resources/views/%7B%7B%20URL::asset('javascript/jquerymin.js')%7D%7D
It's like w/e Laravel service should be converting these into something useful isn't running at all? Do I need to install something further? I was under the impression that using it this way came with Laravel 5, according to this answer: Laravel stylesheets and javascript don't load for non-base routes... so I must be having some other problem, please advise.
You cannot go to your blade template directly, it must be rendered first by the templating engine. You usually do that in your controller.
I'm trying to use bootstrap on a codeigniter web but it looks like the bootstrap files are not found
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link href="<?php echo base_url('application/bootstrap/css/bootstrap.min.css');?>" rel="stylesheet">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="<?php echo base_url('application/bootstrap/js/bootstrap.min.js');?>"></script>
I've checked the paths generated by base_url() and it are correct.
move bootstrap folder on root location, because CI is understanding application folder as controller although application folder is restricted from client request by /application/.htaccess file
|-
|-application
|-bootstrap
//and use path as
<?php echo base_url('bootstrap/css/bootstrap.min.css');?>
Here's the best guide I've found so far:
How to include bootstrap in CI
In short:
Download bootstrap
Put it in an assets folder on same level as application folder
Also put jquery
Include css in header and jquery in footer of your templates:
<html>
<head>
<title>CodeIgniter Tutorial</title>
<link rel="stylesheet" href="<?php echo base_url("assets/css/bootstrap.css"); ?>" />
</head>
<body>
<h1>H_E_A_D_E_R</h1>
and :
<hr/>
<em>© 2016</em>
<script type="text/javascript" src="<?php echo base_url("assets/js/jquery-3.1.1.js"); ?>"></script>
<script type="text/javascript" src="<?php echo base_url("assets/js/bootstrap.js"); ?>"></script>
</body>
</html>
Don't forget to include the CodeIgniter URL helper in your controller
$this->load->helper('url');
Just sharing over here so that you no need to combine folders manually. I used this package offered from github regularly to commit new projects. Of course you will have to modify the application/config/config.php to get things work !
https://github.com/sjlu/CodeIgniter-Bootstrap
Cheers !
Create a folder(assets) in Codeigniter root directly (Same level to application folder)
Paste your bootstrap files into that folder
add link code in your view file
<link type="text/css" href="<?= base_url(); ?>assets/bootstrap.min.css" rel="stylesheet">
add this line in your controller file application/cotrollers/test.php
<?php
class Test extends CI_Controller {
public function index()
{
$this->load->helper('url'); // Load url links
$this->load->view('index'); //Load view page
}
}
?>
Now you can use bootstrap classes in your view
Download the Bootstrap file from the internet if you want to work offline
Unzip and rename and copy to root folder. If you put it in application folder, .htaccess will not allow it to be accessed.
Add the link like the following line of code:
<link href="<?php echo base_url('assets/css/bootstrap.min.css');?> rel="stylesheet">
If you use the Ci4 , add the folder 'bootstrap' in the default folder 'public'.
Thanks
As the question suggests I have an index.php file with html in it and when I try to style it using external or internal css, it doesn't work. But inline css works. By the way I am using xampp on win7 to test the website. And the file structure looks like this c:/xampp/htdocs/test/index.php
Relevant html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width>
<!--<link rel="stylesheet" type="text/css" href="style.css">-->
<!--This css file contains the css shown below as internal css-->
<style>
body{
background-color: blue;
color: white;
}
.header{
color: white;
}
</style>
<?php
function somefuntion(){
/*I will be adding this function later once the html skeleton
is done.
This function will be calculating some numbers based on the
current date and echoing it.*/
}
?>
</head>
<body>
<section class="header">
<p>Spring</p>
</section>
<section class="body">
<p>Hello world</p>
</section>
</body>
</html>
Can someone also explain why internal css is not working?
Solution found by hRdCoder: missing " mark in the content attribute of meta tag.
<link rel="stylesheet" type="text/css" href="style.css"></link>
Only things to check for are that you add the closing tag and that the style.css file is in the same directory as your index.php.
Edit:
I just noticed that in your that you're missing the last set of quotation marks (") in the content attribute. Could that be affecting the rest of the page?
Also make sure you don't include the <style></style> tags in your external css file
Do one thing. open css file through xampp or wampp.. like
open browser -> search localhost/your folder and then open css or js file ,now copy that address and paste in href or src. hope this will help
the answer could be as simple as adding a class or id to the html tag like lets say there is a button tag like this..
<button>open</button>
and the code you wrote on external css is not working but inline does cuz there might be a class or id or the selector itself imposing the code without you knowing it so that's why it might not be working .That's why try adding a class or id to it like this..
<button class="btn">open</button>
<style>
.btn {
background-color:red;
}
</style>
it might just work..
there is something wrong with your path when linking your external css
is your index.php is in the same folder as your style.css?
<link rel="stylesheet" type="text/css" href="style.css">
try to put it in a separate folder named css
then link it as
<link rel="stylesheet" type="text/css" href="css/style.css">
you can also use firebug plugins for firefox or firebug lite plugin for chrome to check the errors