So I am using the codeigniter pdf library from: https://github.com/chrisnharvey/CodeIgniter-PDF-Generator-Library
And it works wonders except, It doesn't keep the style sheet when the pdf is generated.
I am trying to use bootstrap to make it look nice, But when I run the script and download the pdf it doesn't have the styling anymore. What do I need to do to keep the stylesheet linked?
My Controller:
public function AdminPracticeSheetLateReport()
{
$this->load->view('pdf/practiceLateReport');
$this->pdf->load_view('pdf/practiceLateReport');
$this->pdf->render();
$this->pdf->stream("welcome.pdf");
}
I am loading the bootstrap stylesheet like so in my view:
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
Is this even possible with this plugin? If not it's quite the crappy plugin if you ask me.
BTW: This library for codeigniter uses the DomPDF
I just checked the source code of codeigniter and noticed that it does not itself make a PDF, but uses DOMPDF in turn (which is another PHP library). codeigniter does not properly send the html and css to DOMPDF, so in my suggestion you should remove codeigniter and use DOMPDF instead. This should correct your problem and also speed up the conversion by a few miliseconds.
Related
I want to create a pdf page from html file in Laravel but I do not know how to do it. You can help me
https://github.com/barryvdh/laravel-dompdf
// Import in top of controller file
use Barryvdh\DomPDF\Facade as PDF;
// use below code to generate and download pdf file
$pdf = PDF::loadView('bladefilename', ['arrayname' => $array]);
return $pdf->download('filename.pdf');
Write Above code in the controller file
In Blade file (HTML file) set array data.
Show Below Link : https://github.com/barryvdh/laravel-dompdf/issues/126
I know I am a little bit late but hopefully this will help someone.
There are 2 ways:
Create HTML page and use jspdf to print this page. The best way is to use html2pdf: https://github.com/eKoopmans/html2pdf.js
You can use this one to convert html to canvas and print to pdf. All css will be kept but you have to change the page to fix the space between pages as there may be some bad cut at the end of each page.
Print the page using latex. You have to use laravel latex compiler: https://github.com/fvhockney/latexcompiler
It is a little bit harder to styling the page but there is no problem with paging.
This is the case:
I have a form where the user has to fill in 5 fields. I also have a PDF template with some layout with 5 empty colored boxes.
Now when the user fills in the form a PDF should be generated from the pdf template and the fields that the user has given in should be added to the template.
Now my question what's the best and easiest way to do this? I've look at the library laravel-dompdf but it didn't look like it's working with templates.
Did anybody had to do this? If yes, how did you do it? I'm working with laravel 5.0 .
I've used the packages fpdf and fpdi to work with pdf templates.
I use the "vsmoraes/laravel-pdf": "^1.0" package and it does well for us.
use Vsmoraes\Pdf\Pdf;
private $pdf;
public function __construct(Pdf $pdf)
{
$this->middleware('auth');
$this->pdf = $pdf;
}
public function pdfMaker($data)
{
$html = view('pdf.shippinglabel')->with('purchase', $purchase)->with('products', $products)->render();
$label = $this->pdf->load($html)->output();
file_put_contents(storage_path()."/ftp/po/label_".$id.".pdf",$label);
}
And then I have the formatted pdf with embedded CSS and not including external CSS file linking.
here's the github url: https://github.com/vsmoraes/pdf-laravel5
Dompdf doesn't work with pdf templates, but it works with HTML templates.
So, you can do this way:
Prepare a HTML template and place some placeholders( i.e: {field1}, {field2}, ecc ) where you want to print the values you'll get from the form
When the form is submitted, load the html template into a string, replace the placeholders in the string with the actual values you got from the form
Pass the string (that will contain valid html) to dompdf and it will generate a PDF file
With the Laravel package from Barry (https://github.com/barryvdh/laravel-dompdf) you can load views. So in that way it is possible to make a template using the Blade views.
i designed the invoice using bootstrap css, i used tcpdf to design invoice. I called bootstrap css file but its not working, Kindly help me.. My coding is
$baseurl = "http://localhost/erp";
$html = '<style>'.file_get_contents($baseurl.'css/bootstrap.min.css').'</style>';
$html = '<style>'.file_get_contents($baseurl.'css/style.css').'</style>';
First of all - Bootstrap use js scripts for working; As You understand, scripts could not be working in tcpdf file;
More than that - tcpdf not allowed all CSS attributes; I can't find supported css list in official documentation, but this can help;
I am having trouble using a script I found at http://www.marcofolio.net/webdesign/use_a_custom_font_on_your_website.html
The problem is, when I load a page, the text shows up then each word is replaced by a generated image of it using the PHP GD lib.
It creates a flicker effect that I can't seem to get rid of. There are options is the js file:
var hideFlicker = true;
var hideFlickerCSS = "replacement-screen.css";
var hideFlickerTimeout = 0;
But when I change any of those settings, nothing happens.
Please help!
Thank you.
For what you seem to be trying to do, image replacement is an extremely outdated method. All the ninja-devs are using technology called #font-face for their fonts and font replacements.
It's simpler, doesn't require anything to happen on the server and text on the page can be modified dynamically.
You can use services like http://www.fontsquirrel.com/ or http://code.google.com/webfonts for ready made font packages.
If you have a custom font (that you have a license for) you can create an #font-face package for it, using fontsquirrel's #font-face generator: http://www.fontsquirrel.com/fontface/generator
And then you just define your fonts in the CSS. Simple, elegant and works in 99% of browsers (yes, even IE6)
Cheers!
I want to generate a PDF of a webpage but apply an alternate, print-type stylesheet to it instead of the styles it uses now. Say, for example, I have a button on http://eorailway.co.uk to generate a PDF of the same page (which is run and administered by me, so therefore I can include any PHP/JS necessary to each page) but I want to apply alternate styling to it before generating the PDF.
At the moment I am using the dompdf PHP library to generate the PDF using the normal/default stylesheet, but cannot for the life of me think how to apply the alternate stylesheet to the page when clicking the "Generate PDF" button.
Any advice is most appreciated.
Since the site is under control, you could dynamically decide which stylesheets to include based on a query string parameter. i.e. http://example.com/page.php?stylesheet=print would have your template output only the alternate stylesheet, and your PDF library would fetch that page to generate.
I would recommend making an alternate page with the "print" stylesheet applied and point to it using the print meta tag. (e.g. <link rel="alternate" media="print" href="<? ECHO $_SERVER['PHP_SELF'].'?print'; ?>""> )
Then have PHP determine the stylesheet to use based on the presence of that GET variable.
You can use the DOMXML stuff in php to apply a specific XSLT file to some XML:
$stylsheet = "Example.xsl";
$xsldoc = domxml_xslt_stylesheet_file($stylsheet);
$htmldoc = $xsldoc->process($xmldoc);
$results_page = $xsldoc->result_dump_mem($htmldoc);
That's something I did in php4, might be an easier way in 5.
In the 0.6.0 release of DOMPDF you can specify the stylesheet to use by modifying the DOMPDF_DEFAULT_MEDIA_TYPE configuration constant.
http://code.google.com/p/dompdf/source/browse/trunk/dompdf/dompdf_config.inc.php?r=336#234