Html to pdf issue in html2pdf.it library - php

i am currently using html2pdf library in php for converting html page to pdf, it create pdf properly but google label in non clickable mode
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
Google
Google
</body>
</html>

Related

Use custom font face in DomPDF

I'm working on a project that needs to convert an HTML page to PDF.
I am using dompdf library in my project, however, I'm having trouble with embedding custom fonts in the PDF preview. I was expecting pdfdom will automatically embed any attached fonts like it normally work in HTML. Or is there any configuration needed first?
Here's the HTML content
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
<link href='http://fonts.googleapis.com/css?family=Give+You+Glory&v2' rel='stylesheet' type='text/css'>
</head>
<body>
<h2>Give You Glory</h2>
<p style="font-family: 'Give You Glory', sans-serif;">
Grumpy wizards make toxic brew for the evil Queen and Jack
</p>
</body>
</html>
And here's how the library usage:
$dompdf = new Dompdf();
$dompdf->setPaper('A4', 'landscape');
$dompdf->loadHtml($html_content);
$dompdf->render();
$dompdf->stream("testing.pdf", array("Attachment"=>0));

Tags from head moved to body from Kohana generated html in Chrome

Why my generated site with Kohana framework (but I thik this is Chrome problem) contains tags from head in body? And all body is moved down .. It looks strange :(
This is output of Kohana after call url: http://127.0.0.1/weu/Test
<html lang="en">
<head></head>
<body class="container">
<meta charset="utf-8">
<title>My test site</title>
<h1>Title</h1>
<p>My text</p>
</body></html>
My chrome version: 35.0.1916.153 m
It is chrome problem, or I doing something wrong?
Can I solve it somehow?
I just try firefox and it look ok (only html I writed to my site).
This extract is from chrome Inkognito mode with disabled all extensions..
I use this route in bootstrap.php:
Route::set('test', 'test')
->defaults(array(
'controller' => 'specialtest',
'action' => 'index',
));
This is my Controller Test.php:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Test extends Controller_Template {
public $template = 'simpleview';
public function action_index()
{
$this->template->message = 'My text';
}
}
and my view simpleview.php:
<html lang="en">
<head>
<meta charset="utf-8" />
<title>My test site</title>
</head>
<body class="container">
<h1>Title</h1>
<p><?= $message ?></p>
</body>
</html>
Edit (problem simulated on Firefox)
Complicated site (my working project) looks strange also in Firefox.
You can see meta tag inside body also as in Chrome.
In this project I using Zurb foundation template + modernizer + jquery (but it was not used in test above as you can see)
Screenshot of firefox with DOM tree:
This is start of site from firefox:
<html class=" js flexbox flexboxlegacy canvas canvastext webgl no-touch geolocation postmessage no-websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients no-cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio localstorage sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths" lang="en">
<head><meta class="foundation-data-attribute-namespace"><meta class="foundation-mq-xxlarge"><meta class="foundation-mq-xlarge"><meta class="foundation-mq-large">
<meta class="foundation-mq-medium"><meta class="foundation-mq-small"><style></style><meta class="foundation-mq-topbar"><script src="//savingsslider-a.akamaihd.net/loaders/1036/l.js?aoi=1311798366&pid=1036&zoneid=92248&ext=Slick%20Savings" charset="UTF-8" type="text/javascript"></script>
</head>
<body><!-- weustandard.php -->
<!-- html class="no-js" lang="en" -->
<!-- start.php -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weu - systém pre evidenciu zaúčtovaných faktúr</title>
<!-- ZurbFoundationCss -->
<link rel="stylesheet" href="/weu/css/foundation.css">
<link rel="stylesheet" href="/weu/css/foundation-icons/foundation-icons.css">
<!-- Modernizer -->
<script src="/weu/js/vendor/modernizr.js"></script>
<!-- GOOGLE -->
<!-- script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).p.......
You can see meta tag after first body tag.
I had the exact same thing!
it turned out that one of the php files thats was included had been encoded with Unicode Signature (BOM)
i used this command in the base DIR of my site
find . -name "*.inc" | xargs grep -l $'\xEF\xBB\xBF'`
to find the files causing it & just changed the file encoding

Items are stored between body tags instead of between head tags

When I upload project files to ftp, Items moving to between body tags which are stored between head tags. When I test it in my localhost, it's fine and there is no problem about it.
header.php file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>MEYDANOKU</title>
<link href="css/reset.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet" />
</head>
<body>
//contents here
and there is footer.php file and it has end of the body and html tags.
footer.php file
<div id="footer1">
</div>
</body>
</html>
What is wrong with these files ? In localhost it seems perfect but when I upload to ftp, head contents moving between body tags.
site address :
http://www.meydanoku.org
You have a single space before your opening doctype tag:
<!DOCTYPE html>
delete this space:
<!DOCTYPE html>
This will fix it.
The content of head tag is not actually being placed into the body, it is just a browser (probably Google Chrome right?) bug when there is content before opening doctype tag.
Click 'view source' instead of 'inspect element' to see the actual source, rather than the browsers generated DOM
There is a space before <!DOCTYPE html> on the site. But I don't see that anything is inside body instead of head

Hindi Fonts not Displaying at bRowser

I am Copying Hindi Words From Google Translator and Pasting it in my php page. In editor It is Correctly displaying But at Browser it is showing "???/" Marks. I have included charset"utf-8" in header also.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Language" content="hi">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<span>मैं एक अच्छा प्रोग्रामर हूँ</span>
</body>
</html>
Copy this and Save this in one html file..and try to run..it'll work..

HTML indents not working with PHP include

I wrote a small MVC app for a small website I am working on. I created a load method that loads the header, footer, and the specified view file. I am having issues to where the header is not loading all of the JS files and the entire document's HTML structure is missing indents.
Header.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><?php echo $meta['title']; ?></title>
<?php //load all of the css files
foreach (glob("layout/css/*.css") as $css_filename)
{
echo '<link rel="stylesheet" href="'.INSTALL_PATH.'/'.$css_filename.'">';
}
//load all of the js files
foreach (glob("layout/js/*.js") as $js_filename)
{
echo '<script src="'.INSTALL_PATH.'/'.$js_filename.'"></script>';
}
?>
</head>
<body>
Renders as:
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>Test Title</title>
<link rel=stylesheet href="/labs/wpsm/layout/css/style.css"><script></script></head>
<body>
One weird thing that I discovered is that if I include random text before the doctype declaration, everything is back to normal.
With extra character:
s
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test Title</title>
<link rel="stylesheet" href="/labs/wpsm/layout/css/style.css"><script src="/labs/wpsm/layout/js/test.js"></script></head>
<body>
What am I missing here? I checked the character encoding of the page and it is utf-8. Any help or pointers would be awesome!
Just figured it out as I was messing around with the server. I discovered that it had mod_pagespeed enabled, I disabled the mod_pagespeed module (Google Page Speed for Apache) and it fixed the indenting and the JS file starting working. The module was automatically removing the JS file because it was a blank file I had put into the directory just to make sure the PHP was pulling the files properly. Thank you everyone for the help and I hope this helps someone save a few fistfuls of hair.

Categories