I want to show odometer simple example but its not working. My jpgraph files are within src/ directory. Myline graph is working but for odometer which file to use ??
PHP code:
<?php
require_once ('/src/jpgraph.php');
require_once ('/src/jpgraph_line.php');
require_once ('jpgraph/jpgraph_odo.php');
// Create a new odometer graph
$graph = new OdoGraph(500,180);
$odo = array();
// Now we need to create an odometer to add to the graph.
for( $i=0; $i < 5; ++$i ) {
$odo[$i] = new Odometer();
$odo[$i]->SetColor('lightgray:1.9');
$odo[$i]->needle->Set(10+$i*17);
$odo[$i]->needle->SetShadow();
if( $i < 2 )
$fsize = 10;
else
$fsize = 8;
$odo[$i]->scale->label->SetFont(FF_ARIAL,FS_NORMAL,$fsize);
$odo[$i]->AddIndication(92,100,'red');
$odo[$i]->AddIndication(80,92,'orange');
$odo[$i]->AddIndication(60,80,'yellow');
}
// Create the layout
$row1 = new LayoutHor( array($odo[0],$odo[1]) );
$row2 = new LayoutHor( array($odo[2],$odo[3],$odo[4]) );
$col1 = new LayoutVert( array($row1,$row2) );
// Add the odometer to the graph
$graph->Add($col1);
// ... and finally stroke and stream the image back to the browser
$graph->Stroke();
?>
Error:
Fatal error: Class 'OdoGraph' not found in C:\wamp\www\PowerMonitor\odometer.php on line 9
I had similar problem of this Fatal error. As Gal pointed out, it is problem with in-proper JPGRAPH_ODO.PHP loading or missing. You can download the file from here and keep it under src directory with other files. Then apply
require_once ('/src/jpgraph_odo.php');
might work.
Related
I use the following code to convert PDF to PNG. As you can see, I use code setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE ) to remove the background transparency. But in practice it only works for the last page. Do you think there is a problem with the code? Do you have a better solution with a higher speed?
$PDF = 'test.pdf';
$img = new imagick();
$img->readImage($PDF.'[0-9]'); //Convert 10 pages
$img->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE );
$pages = count($img);
$img->writeImages('./images/'.'pdf.png', true);
This looks like an iterator issue. You can try looping with something like this:
<?php
$PDF = 'test.pdf';
$img = new Imagick();
$img->readImage($PDF. '[0-9]'); //Convert 10 pages
$lastIndex = $img->getIteratorIndex();
$img->resetIterator();
for($i = $img->getIteratorIndex(); $i <= $lastIndex; $i++) {
$img->setIteratorIndex($i);
$img->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
}
$pages = count($img); // not sure why you need this
$img->writeImages('./images/'.'pdf.png', true);
You could also get the iterating part down to a simple loop, if you like it more, since the Imagick class implements Iterator:
foreach($img as $i)
{
$img->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
}
I have a problem by including a pdf merge system
I have tried a lot of code from git, but nothing works.
Now I have seen that if I comment out the lines with the use:
than the page can load if the use lines are in the code the page will not load.
if (isset($_POST["merge"]))
{
//use setasign\Fpdi;
//use setasign\fpdf;
require_once '../buchhaltung/vendor/autoload.php';
require_once '../buchhaltung/vendor/setasign/fpdf/fpdf.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
set_time_limit(2);
date_default_timezone_set('UTC');
$start = microtime(true);
$pdf = new Fpdi\Fpdi();
//$pdf = new Fpdi\TcpdfFpdi('L', 'mm', 'A3');
if ($pdf instanceof \TCPDF) {
$pdf->SetProtection(['print'], '', 'owner');
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
}
$files = [
' $_SESSION["filePath0"]',
' $_SESSION["filePath1"]',
];
foreach ($files as $file) {
$pageCount = $pdf->setSourceFile($file);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$pdf->AddPage();
$pageId = $pdf->importPage($pageNo, '/MediaBox');
//$pageId = $pdf->importPage($pageNo, Fpdi\PdfReader\PageBoundaries::ART_BOX);
$s = $pdf->useTemplate($pageId, 10, 10, 200);
}
}
$file = uniqid().'.pdf';
$pdf->Output('I', 'simple.pdf');
//$pdf->Output('output/'.$file, 'I');
}
But if I comment this lines out I get this fault:
Fatal error: Uncaught Error: Class "Fpdi\Fpdi" not found in /home/.sites/707/site3898181/web/buchhaltung/belegAdd.php:28 Stack trace: #0 {main} thrown in /home/.sites/707/site3898181/web/buchhaltung/belegAdd.php on line 28
Does someone have an idea what I am doing wrong?
The function of the Page should :
Upload multiple pdf files to the ftp (work)
if upload more than one file -> merge to one file and last store the path of the file into DB (this part I have in a other file (copy and paste))
only the merge does not work
I am using Pdfparser Library for parsing pdfs. While parsing, Some pages of the 20-page pdf file are read and some pages are not. This is code I am using
$str_path = 'example_book.pdf';
$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile($str_path);
$pages = $pdf->getPages();
$page = $pages[7];
$text = $page->getText();
echo $text;
When I run the php script I get this error:
Call to undefined method Smalot\PdfParser\Encoding::__toString()
Smalot\PdfParser\Font::translateChar
vendor/smalot/pdfparser/src/Smalot/PdfParser/Font.php:104
Is there any other way to do this?
follow below steps
1.open below mentioned file on the editor
vendor\smalot\pdfparser\src\Smalot\PdfParser\Font.php
search for function
translateChar
3. Comment Out the below-mentioned code (or remove )
if (\strlen($char) < 2 && $this->has('Encoding') && 'WinAnsiEncoding'
=== $this->get('Encoding')->__toString()) {
$fallbackDecoded = self::uchr($dec);
}
save file and exit.
I've written the following code for merging PDFs using this answer
function merge_pdfs() {
$pdfs_array = array('1.pdf', '2.pdf');
$pdf = new FPDI_Protection();
for ($i = 0; $i < count($pdfs_array); $i++ ) {
$pagecount = $pdf->setSourceFile($pdfs_array[$i]);
for($j = 0; $j < $pagecount ; $j++) {
$tplidx = $pdf->importPage(($j +1), '/MediaBox');
$pdf->addPage('P','A4');
$pdf->useTemplate($tplidx, 0, 0, 0, 0, TRUE);
}
}
$dt = new DateTime(NULL, new DateTimeZone($data->user->timezone));
$pdf->SetTitle('PDF, created: '.$dt->format(MYHMRS_DATETIME_FRIENDLY));
$pdf->SetSubject('PDF subject !');
$output = $pdf->Output('', 'S');
$name = "PDF".'-'.$dt->format('ymd').'.pdf';
$this->output
->set_header("Content-Disposition: filename=$name;")
->set_content_type('Application/pdf')
->set_output($output);
}
So, after this I'm getting the following error message
This document (1.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI. (See https://www.setasign.com/fpdi-pdf-parser for more details)
I've checked the link and it suggests to set another PDF Parser ( If I understand right )
But I'm not sure how to make it working with Codeigniter and my example
Should I create library and try to use it?
Or maybe you know another solution for merging PDFs
The issue was related to PDF versions
Edit
If you don't know, the PDFs has versions. Yeah, I was surprised as well. Please check them here PDF versions
So, the problem was that I was trying to merge PDF 1.5 version with PDF 1.6
An example. It is simple.
<?php
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->AddPage('P');
$mpdf->WriteHTML('<h1>More</h1>');
$mpdf->Output();
?>
I need to solve this problem soon. I tried many solutions, but all the tutorials and samples create the document and download the word file into local computer. what I want is to upload or save it to the file system of the server. Please help me to solve this.
Thanks.
PHPWord can do this:
http://phpword.codeplex.com/releases/view/49543
I have tried Examples/BasicTable.php, it creates the file on the server and doesn't download it.
Here's the code used:
<?php
require_once '../PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->createSection();
// Add table
$table = $section->addTable();
for($r = 1; $r <= 10; $r++) { // Loop through rows
// Add row
$table->addRow();
for($c = 1; $c <= 5; $c++) { // Loop through cells
// Add Cell
$table->addCell(1750)->addText("Row $r, Cell $c");
}
}
// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('BasicTable.docx');
?>