I'm creating a new compnent in Joomla 3 that will use dompdf to generate PDF's of certain information on the screen.
I have tested my dompdf code outside of joomla and everything works okay, but as soon as I bring the code inside my component it goes wrong.
Dompdf generates the PDF, but it is invalid and does not open correctly.
I have opened the PDF in a text editor and the issue is that the pdf that dompdf is generating has gotg all the Joomla headers in (stylesheets, jaavascript etc.) even though I'm only passing some dedicated HTML though to it.
Is there anything that I'm missing ? The code is listed below
$fhtml = '<html><head><title>Sales Order</title>';
$fhtml .= PHP_EOL . '<link type="text/css" href="test.css" rel="stylesheet" /></head><body>';
$fhtml .= PHP_EOL . '<center><img src="elite.jpg" /><img src="premierdealer.jpg" /><img src="logo.jpg" /><img src="traveller.jpg" /><img src="childrens.jpg" /><img src="westfield.jpg" /></center>';
$fhtml .= PHP_EOL . '<h2>Header</h2><p>Para</p>';
$fhtml .= PHP_EOL . '</body></html>';
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->setPaper('A4', 'portrait');
$dompdf->loadHtml($fhtml);
$dompdf->render();
$dompdf->stream('salesorder');
You can see from the code above that I pass the html over to dompdf->loadhtml.
A pdf is generated, but when I open teh PDf in a text editor (it is a corrupted PDF so I cannot open it with a pdf reader) I find the following inside the PDF :
<!DOCTYPE html>
<html lang="en-gb" dir="ltr">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8" />
<base href="http://test1.questleisure.local/index.php/portal/portal-home" />
<meta name="keywords" content="quest leisure air awnings caravan awnings camping caravan air tents outdoor funriture" />
<meta name="rights" content="Quest Leisure" />
<meta name="description" content="Quest Leisure Public Website" />
<meta name="generator" content="Joomla! - Open Source Content Management" />
<title>Portal Home</title>
<link rel="stylesheet" href="/media/com_questportal/css/default.css" />
<link rel="stylesheet" href="/plugins/system/rokbox/assets/styles/rokbox.css" />
<link rel="stylesheet" href="/media/gantry5/assets/css/font-awesome.min.css?57344a42" />
<link rel="stylesheet" href="/media/gantry5/engines/nucleus/css-compiled/nucleus.css?57344a42" />
<link rel="stylesheet" href="/templates/rt_galatea/custom/css-compiled/galatea_11.css" />
<link rel="stylesheet" href="/media/gantry5/assets/css/bootstrap-gantry.css?57344a42" />
<link rel="stylesheet" href="/media/gantry5/engines/nucleus/css-compiled/joomla.css?57344a42" />
<link rel="stylesheet" href="/media/jui/css/icomoon.css" />
<link rel="stylesheet" href="/templates/rt_galatea/custom/css-compiled/galatea-joomla_11.css" />
<link rel="stylesheet" href="/templates/rt_galatea/custom/css-compiled/custom_11.css" />
<link rel="stylesheet" href="/templates/rt_galatea/css/demo.css" />
<link rel="stylesheet" href="/templates/rt_galatea/css/animate.css" />
<script src="/media/system/js/mootools-core.js"></script>
<script src="/media/system/js/core.js"></script>
<script src="/media/system/js/mootools-more.js"></script>
<script src="/plugins/system/rokbox/assets/js/rokbox.js"></script>
<script src="/templates/rt_galatea/js/jui/jquery.min.js"></script>
<script src="/media/jui/js/jquery-noconflict.js"></script>
<script src="/media/jui/js/jquery-migrate.min.js"></script>
<script src="/media/jui/js/bootstrap.min.js"></script>
<body class="gantry g-galatea-style site com_questportal view-questportal no-layout task-display dir-ltr itemid-229 outline-11 g-offcanvas-left g-default g-style-preset1">
<div id="g-offsidebar-overlay"></div>
<div id="g-offcanvas" data-g-offcanvas-swipe="1" data-g-offcanvas-css3="1">
<div
class="g
So dompdf is getting all thebasic Joomla headers from the buffer, even though I'm only passing it certain html.
Is there anything I have to do to stop dompdf using all the headers from joomla, and just use the HTML I pass it ?
Cheers
I have traced this issue back to the way that dompdf->stream() works.
If I create a physical pdf file using dompdf->output() then the pdf file is 100% correct.
If I then use dompdf->stream() afterwards the resulting PDF file has all the joomla headers and stylesheets etc, in which causes the issue. The code showing the difference is below :
$fhtml = '<html><head><title>Sales Order</title>';
$fhtml .= PHP_EOL . '<link type="text/css" href="dompdf.css" rel="stylesheet" /></head><body>';
$fhtml .= PHP_EOL . '<center><img src="elite.jpg" /><img src="premierdealer.jpg" /><img src="logo.jpg" /><img src="traveller.jpg" /><img src="childrens.jpg" /><img src="westfield.jpg" /></center>';
$fhtml .= PHP_EOL . 'Test content';
$fhtml .= PHP_EOL . '</body></html>';
require_once JPATH_COMPONENT . '/libraries/dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->setPaper('A4', 'portrait');
$dompdf->setBasePath(JPATH_COMPONENT . '/libraries/');
$dompdf->loadHtml($fhtml);
$dompdf->render();
$dompdf->output();
$file_to_save = JPATH_COMPONENT . '/temp/test.pdf';
file_put_contents($file_to_save, $dompdf->output());
$dompdf->stream();
In the example above the test.pdf file is 100% correct, but the downloaded file (created by the dompdf->stream() command) is actually corrupt and contains all the chrome from joomla.
I'm closing this question off and will raise a new one with the issue between stream and output instead.
Related
I have a problem with my favicon icons, they are in public folder inside img folder and html looks like this:
<link rel="apple-touch-icon" sizes="180x180" href="img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png">
<link rel="manifest" href="img/manifest.json">
<link rel="shortcut icon" href="img/favicon.ico">
<meta name="msapplication-config" content="img/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
<link rel="manifest" href="/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
I am 100% sure that the href is correct because if I copy it it shows me the image, however the icon is not displayed in the tab. What can I do about it?
Try to add ?version=1 to href. Google Chrome caches favicons very hard.
Try this
<link rel="icon" type="image/png" sizes="16x16" href="{{URL::asset('img/favicon-16x16.png')}}">
I am working on a Spring MVC application that use FreeMarker for my views.
I am absolutly new in FreeMarker and I have the following problem: in my projct I have 3 files that have to be assemblet togheter into a single page.
So I have:
1) header.ftl representing the header of all my pages, somthing like:
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js is-ie8"><![endif]-->
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Registrazione - MY WEBSITE</title>
<meta name="robots" content="noindex,nofollow">
<link rel="stylesheet" href="resources/css/webfont.css">
<link rel="stylesheet" href="resources/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="resources/bootstrap/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="resources/plugins/bs-select/bootstrap-select.min.css">
<link rel="stylesheet" href="resources/plugins/bs-dialog/bootstrap-dialog.min.css">
<link rel="stylesheet" href="resources/css/style.css" />
</head>
<body id="main">
<!-- versione per popup. non prendere in considerazione -->
<!--
<div class="container page-header">
<h1>MY WEBSITE</h1>
</div>
2) footer.ftl representing the footer of all my pages:
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/plugins/bs-select/bootstrap-select.min.js"></script>
<script src="assets/plugins/bs-select/i18n/defaults-it_IT.min.js"></script>
<script src="assets/plugins/bs-dialog/bootstrap-dialog.min.js"></script>
<script src="assets/plugins/jq-form-validation/jquery.validation.js"></script>
<script src="assets/js/functions.lib.js"></script>
<script src="assets/js/form-validation.js"></script>
</body>
</html>
3) Then I have my specific page (named myPage.ftl that represent only the content, something like this:
<h1>This is the content</h1>
<p>Some inforamation</p>
The header.ftl and the footer.ftl are into this directory **\WEB-INF\freemarker\layout** of my project.
So my problem is: how can I import the header.ftl content above the content of the myPage.ftl and the footer.ftl under the content of myPage.ftl page?
I did this using user-defined macros for page layouts, e.g. let's call your layout standardPage.ftl:
<#macro standardPage title="">
<!DOCTYPE html>
<html lang="en">
<head>
<title>${title}</title>
</head>
<body>
<#include "/include/header.ftl">
<#nested/>
<#include "/include/footer.ftl">
</body>
</html>
</#macro>
Then you can call this macro in each of your pages, e.g. homePage.ftl:
<#include "/pages/standardPage.ftl" />
<#standardPage title="Home">
<h1>Home Page</h1>
<p>This bit replaces the nested tag in the layout</p>
</#standardPage>
I have a situation where i have a view file users.blade.php which extends master. and the master includes another file called header.blade.php, i want to pass some data from users.blade to header.blade.
Here is the simplified version of the files
/****** Users.blade.php *********/
#extends('shared.master')
#section('title', 'Dashboard')
#section('pagecss')
<link rel="stylesheet" href="links to css file" />
#endsection
Here is the master.blade.php
/******Shared/master.blade.php ********/
<html>
<head>
<title>#yield('title')</title>
#include('shared.header')
</head>
<body >
#yield('content')
</body>
</html>
Here is the header file
/******Shared/header.blade.php ********/
<link rel="stylesheet" href="links to bootstrap" />
#yield('pagecss')
<link rel="stylesheet" href="links to other files" />
#yield('pagecss') doesn't work in the header.blade, but it does work in master.blade. Now i cant paste it in master.blade because there are some files which override other files, so it has to be in a specific order. Any ideas how to make the yield work in header.blade?
EDIT:
I do like Bharat Geleda approach, i have modified the code to include some heredocs to make it more convenient. But i think its kind of a hack and still looking for a better solution.
/********** Users.blade.php ***********/
#extends('shared.master')
#section('title', 'Dashboard')
#section('pagecss')
<link rel="stylesheet" href="links to css file" />
#endsection
<?php $pagecss = <<<CSS_FILES
<link rel="stylesheet" href="links to page css" />
CSS_FILES;
?>
/*********** Shared/header.blade.php **********/
#if(isset($pagecss))
{{-- */ echo $pagecss;/* --}}
#endif
A possible solution would be to do this
<?php $pagecss = '<link rel="stylesheet" href="links to css file" />'?>
/****** Users.blade.php *********/
#extends('shared.master')
#section('title', 'Dashboard')
master.blade.php would remain the same
/******Shared/master.blade.php ********/
<html>
<head>
<title>#yield('title')</title>
#include('shared.header')
</head>
<body >
#yield('content')
</body>
</html>
And then in your header file you could do this
/******Shared/header.blade.php ********/
<link rel="stylesheet" href="links to bootstrap" />
#if(isset($pagecss))
{{ $pagecss }}
#endif
<link rel="stylesheet" href="links to other files" />
EDIT: TESTING OUT QUESTION
main.blade.php (master in your case)
<html>
<head>
#include('test.header')
</head>
<body >
#yield('content')
</body>
</html>
header.blade.php
<link rel="stylesheet" href="links to bootstrap" />
#yield('pagecss')
<link rel="stylesheet" href="links to other files" />
users.blade.php
#extends('test.main')
#section('content')
CONTENT
#endsection
#section('pagecss')
<link rel="stylesheet" href="links to css file" />
#endsection
OUTPUT :
<html>
<head>
<link rel="stylesheet" href="links to bootstrap" />
<link rel="stylesheet" href="links to css file" />
<link rel="stylesheet" href="links to other files" />
</head>
<body >
CONTENT
</body>
</html>
I guess this is as expected.
Simple if it's working on homepage and not in inner views, that means you've used it, and Blade will take only the higher level and resolve it (include its content where it should be placed within #yield).
What I'm trying to say that if you got a #yield within your header file and you've used it as #section('pagecss') later you got another view as in your case Users.blade.php with the same statement #section('pagecss') blade won't take the inner one.
Solution
Nice way but foolish:
create another #yield within your shared header blade file and name it as level two or like so. i.e #yield('pagecss-2')
Good way:
using #parent, this directive is going to append (rather than overwriting) content to the layout
as mentioned here within docs of laravel
i use sub folder in controller like admin_panel
in admin_panel / main.php i use this code
public function index()
{
$h_data['title'] = 'admin';
$c_data = array();
$this->parser->parse('admin/head',$h_data);
$this->parser->parse('admin/index',$c_data);
}
and head.php in view/admin contain :
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../assets/css/font.css" type="text/css" />
<link rel="stylesheet" href="../assets/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="../assets/css/bootstrap-responsive.css" rel="stylesheet">
<link rel="stylesheet" href="../assets/css/bootstrap-theme.min.css" type="text/css" />
<!-- HTML5 shim for IE backwards compatibility -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="../assets/css/admin_style.css" />
<script type="text/javascript" src="../assets/js/jquery.min.js"></script>
<script type="text/javascript" src="../assets/js/bootstrap.min.js"></script>
<title> {title} </title>
</head>
asstes folder exist in root project but when refresh page all head tags return 404 and not found ???
You could try
public function index() {
// Load Parser library or autoload it.
$this->load->library('parser');
$data['title'] = "Page Title";
$data['base_url'] = base_url(); // Make sure you add url helper to autoload.
// May need to add true, i.e $this->parser->parse('header', $data, true);
$data['header'] = $this->parser->parse('header', $data);
// May need to add true, i.e $this->parser->parse('footer', NULL, true); Null No Data
$data['footer'] = $this->parser->parse('footer');
$this->parser->parse('content', $data);
}
On Content View Area's
<?php echo $header;?>
Content
<?php echo $footer;?>
Header View Example
<!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.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<title><?php echo $title;?></title>
<base href="<?php echo base_url();?>"></base>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>assets/admin/css/bootstrap.css" media="screen">
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>assets/admin/css/custom.css" media="screen">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>assets/admin/js/common.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>assets/admin/js/filemanager.js"></script>
</head>
<body>
Footer View Example
<footer id="footer">
<br />
</footer>
</div>
<script type="text/javascript" src="<?php echo base_url();?>assets/admin/js/bootstrap.min.js"></script>
</body>
</html>
Auto load url helper
$autoload['helper'] = array(
'url',
'file',
'form',
'text',
'html',
'date'
);
i find answer this error occure for .htaccess not suitable code . i use this htaccess and work fine :)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Recently I was migrating a web page from joomla 1.5 -> joomla 3.2.
The template itself works great.
The content is not displayed because of the tag.
The written code I have in my index is as:
<?php
defined('_JEXEC') or die('Restricted access'); // no direct access
JHtml::_('behavior.framework',true);
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'functions.php';
$document = null;
if (isset($this))
$document = & $this;
$baseUrl = $this->baseurl;
$templateUrl = $baseUrl . '/templates/' . $this->template;
artxComponentWrapper($document);
?>
<!DOCTYPE html>
<html xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>"
xmlns:jdoc="http://www.w3.org/1999/XSL/Transform">
<head>
<jdoc:include type="head" name="all" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link rel="stylesheet" href="<?php echo $this->baseUrl; ?>/templates/system/css/system.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseUrl; ?>/templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="<?php echo $templateUrl; ?>/css/template.css" media="screen" />
<!--[if IE 7]><link rel="stylesheet" href="<?php echo $templateUrl; ?>/css/template.ie7.css" type="text/css" media="screen" /><![endif]-->
<script type="text/javascript" src="<?php echo $templateUrl; ?>/script.js"></script>
</head>
...
</html>
And this renders as:
<html xml:lang="sl-si" lang="sl-si" xmlns:jdoc="http://www.w3.org/1999/XSL/Transform" class="chrome win">
<head>
<style type="text/css"></style>
</head>
<body>
<jdoc:include type="head" name="all">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<link rel="stylesheet" href="/templates/system/css/system.css" type="text/css">
<link rel="stylesheet" href="/templates/system/css/general.css" type="text/css">
<link rel="stylesheet" type="text/css" href="/TKMS/templates/tkms_theme/css/template.css" media="screen">
<!--[if IE 7]><link rel="stylesheet" href="/TKMS/templates/tkms_theme/css/template.ie7.css" type="text/css" media="screen" /><![endif]-->
<script type="text/javascript" src="/TKMS/templates/tkms_theme/script.js"></script>
<!--CONTENT-->..
</jdoc:include>
Why does this happen? How can I fix this? I read that this happens because of BOM, but I could not fix it.
try to move the
<jdoc:include type="head" name="all">
tag into the head-tags, right (You have it in the body). That's at least where it's supposed to be. Not sure if it will actually render, though...
The problem is that the theme is an Artisteer theme. To solve this issue simply open the .artx theme and export for other joomla version.
If you don't have the .artx file then I cannot help you because I deemed the problem unsolvable.