I have tried reading the .docx file. I am successful in reading the .docx file. But I have to read .pdf file with PHPWord.
Any idea How can I do it?
I have tried the code
// Read contents
$source = "./example.pdf";
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'Word2007');
$data = '';
$section = $phpWord->addSection();
$section->addText($data);
$name = "officefile";
$source = __DIR__ . "/results/{$name}.html";
// Saving the document as HTML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
$objWriter->save($source);
PHPWord cannot read PDF files. Please see this Github issue too see that it is out of scope of the project.
Some alternative methods of reading PDF files with PHP can be found in this Stackoverflow question.
Related
I know how to use the Google Translate API. I want to know one thing do you have an idea to translate the PDF file without losing in the file format. I had tried to convert the PDF file to DOCX and then translate the file and then return it to PDF but the conversion from PDF to DOCX failed because of many PHPWORD BUGs.
Here is the question and the codes that I had received in order to request the conversion from PDF to DOCX.
<?php
require_once 'vendor/autoload.php';
// Create a new PDF reader
$reader = \PhpOffice\PhpWord\IOFactory::createReader('PDF');
$reader->setReadDataOnly(true);
// Load the PDF file
$phpWord = $reader->load('example.pdf');
// Save the DOCX file
$writer = $PhpOfficePhpWordIOFactory::createWriter($phpWord, 'Word2007');
$writer->save('example.docx');
echo 'PDF file converted to DOCX successfully!';
<?php
require_once 'vendor/autoload.php';
use PhpOffice\PhpWord\IOFactory as WordIOFactory;
// Convert PDF to text
exec('pdftotext -layout input.pdf output.txt');
// Load text file
$text = file_get_contents('output.txt');
// Create new DOCX file
$phpWord = new \PhpOffice\PhpWord();
$section = $phpWord->addSection();
$textrun = $section->addTextRun();
$textrun->addText($text);
// Save DOCX file
$objWriter = WordIOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('output.docx');
Do you have any idea how I can translate the PDF file without going through the conversion to other formats?
I am trying to attach(embedding) a .docx file to word document using phpword addObject() function, it's attaching file but while clicking on attached file it's not opening. If i do it for .doc file it's opening the attached file. I am using phpword library.
<?php
require_once '../PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->createSection();
// Add text elements
$section->addText('You can open this OLE object by double clicking on the icon:');
$section->addTextBreak(2);
// Add object
$section->addObject('Test.docx');
//if i use $section->addObject('Test.doc'); it's opening attached file. here Test.doc is word97-2003 format.
// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('Object.docx');
?>
Multiple issues were already logged for this, but no solution proposed for the issue yet :-(
addObject() function is not working with .docx file, it's working with .doc(word97-2003) file
Add Object Issue
Unable to open embedded object
Hi I want to extract a KMZ file that has an Images folder with some images and a kml file
Other questions here just have the kml file but mine has a images folder too!
how can I extract it?
I tried this but it didn't work
$data = file_get_contents("test/test.kmz"); // url of the KMZ file
file_put_contents("/test/kmz_temp",$data);
ob_start();
passthru('unzip -p /test/kmz_temp');
$xml_data = ob_get_clean();
header("Content-type: text/xml");
dd($xml_data);
and also this
$zip = new ZipArchive();
$zip->open('test/test.kmz');
$zip->extractTo('/test/public');
$zip->close();**strong text**
I found my solution
if you change the format of the file (while moving it to your folder) to zip it will extract it
I'm currently working on a project that needs to display excel files (xls, xlsx, csv) on the browser. So far, I have tried and used the PHPExcel library and was able to display the excel file (code below)
$opendoc = $userDoc;
$objReader = new PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load($opendoc);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objw = $objWriter;
$objw->writeAllSheets();
$objw->save('php://output');
The problem I'm encountering is that this code does not support the displaying images (charts , graph , etc) inside an excel file. Any ideas? Thanks in advance!
Errr..... yes it does. Have you read the documentation or looked at the examples? Images are supported directly, and (unless you tell PHPExcel to load data only) should always be loaded.
For charts and graphs, you specifically have to tell PHPExcel to load them when reading a file, and tell PHPExcel to save them when Writing. (Example)
$opendoc = $userDoc;
$objReader = new PHPExcel_Reader_Excel2007();
$objReader->setIncludeCharts(TRUE);
$objPHPExcel = $objReader->load($opendoc);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objw = $objWriter;
$objw->setIncludeCharts(TRUE);
$objw->writeAllSheets();
$objw->save('php://output');
i want to read content of Doc file or convert a doc file into Docx
I have used COM object but it's not working because i've linux based server.
I have also tried with shell_exec command but it doesn't work because there's no any feature provide on shared server .
is there any api ? so that i can convert a Doc file using Docx
If you want to use PHP, try out PHPWord.
There's an example on how to convert from .doc to .docx on this page:
require_once '../PHPWord.php';
$PHPWord = new PHPWord();
$document = $PHPWord->loadTemplate('Excel2003.doc');
// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('Excel2007.docx');