How to convert .xls to .pdf via PHP?

北城以北 提交于 2019-12-02 00:49:58

PHPExcel will do it directly (read XLS, output PDF), although the results are not very pretty.

A better solution might be to use PHPExcel to read the XLS file, render it to HTML in your code & style it the way you like it, then use an HTML->PDF converter like DOMPDF (that's the only one I've tried; there are others) to convert to PDF.

Or, if you want to skip the HTML step, render it directly to PDF using one of the PHP PDF libraries out there - my personal favourite is FPDF.

use headless libreoffice and a shell command shell_exec('C:\wamp64\www\phpexcel\lo\App\libreoffice\program\soffice.exe --headless --convert-to pdf:calc_pdf_Export --outdir C:\wamp64\www\phpexcel\o C:\wamp64\www\phpexcel\new.xlsx');

Anyone who is looking to do this in Ubuntu/linux using php -

Ubuntu comes with libre office installed default. Anyone can use the shell command to use the headless libre office for this.

shell_exec('/usr/bin/libreoffice --headless --convert-to pdf:calc_pdf_Export --outdir /var/www/html/XlsToPdf/public_html/src/var/output /var/www/html/XlsToPdf/public_html/src/var/source/company-a.xlsx');

Hope it helps a others like me.

  • my favourite is fpdf

Method 1 :

  • step 1 go to fpdf.org
  • step2 In left side having download button then click to save
  • step3 create index.php(paste below code) and save index.php to downloaded folder from the site of fpdf.org
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>

For Reference youtube link www.youtube.com/watch?v=QSrUWoTUmyo

Method 2:

using phpmyadmin store and retrieve data as pdf format

  • step 1: first import your excel to phpmyadmin
  • step 2: retrieve data from phpmyadmin using php code using echo concept
  • step 3: using fpdf library to display retrieved data as pdf file

This Video is very usefull refer this friends(Refer this youtube video as step by step its work) https://www.youtube.com/watch?v=c9twV7jkjJg

method 3:

html to pdf

Refer this youtube video as step by step its work Refer this links friends its usefull for you... https://www.youtube.com/watch?v=Kid6Xrqf9-Y

Thank you Friends...

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!