问题
I was googling many hours but I haven't got solution yet.
I need to convert .xls file into .pdf file. How to do that? I have found this http://www.aspose.com/, but it seems, that it hasn't got PHP API, only .NET and JAVA.
Thanks for every advice...
回答1:
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.
回答2:
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');
回答3:
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.
回答4:
- 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...
来源:https://stackoverflow.com/questions/23223491/how-to-convert-xls-to-pdf-via-php