I'm going to use JpGraph in my web-project. To do this, I downloaded the library into my project folder and created the following test code:
<?php
include ( "jpgraph-3.5.0b1/src/jpgraph.php");
include ("jpgraph-3.5.0b1/src/jpgraph_gantt.php");
// A new graph with automatic size
$graph = new GanttGraph (0,0, "auto");
// A new activity on row '0'
$activity = new GanttBar (0,"Project", "2001-12-21", "2002-02-20");
$graph->Add( $activity);
// Display the Gantt chart
$graph->Stroke();
?>
The error message is:
The image “http://localhost:10088/test/check.php” cannot be displayed,
because it contains errors.
What's wrong with my code? In fact, it was just copied from here. The only thing I changed was the path to the JpGraph library. So, do I need to import this library in some special way into my project (so far, I've just copied the JpGraph's folder into the project's folder)? I'm using Zend Studio.
This can be caused by extra whitespace on the page. Make sure you don't have any spaces or line breaks before your opening <?php tag.
Related
I am doing a project in which I use the PHP Spreadsheet library, more info here.
I need to add an image, a jpeg file, in the header of the .xlsx document. For this I am using part of the example code from the official documentation. In this way:
// Create a New Excel
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing();
$drawing->setName('PhpSpreadsheet logo');
$drawing->setPath('app/files/images/example.jpeg');
$drawing->setHeight(36);
$spreadsheet->getActiveSheet()->getHeaderFooter()->addImage($drawing, \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter::IMAGE_HEADER_LEFT);
At the moment the image does not appear and I have not found any error in the code that I use or in the server log, it is a copy of the original, so the doubts that arise are if there is an incompatibility issue or something.
UPDATE:
I have done a test. With this code I have added an image in a cell:
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setName('Paid');
$drawing->setDescription('Paid');
$drawing->setPath('app/files/images/example.jpeg'); /* put your path and image here */
$drawing->setCoordinates('A1');
$drawing->setWorksheet($spreadsheet->getActiveSheet());
It's works fine to use in cell because it's not works in header :(
Please Could you help me?
SOLUTION:
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing();
$drawing->setName('PhpSpreadsheet logo');
$drawing->setPath('app/files/images/example.jpeg');
$drawing->setHeight(25);
$sheet->getHeaderFooter()->addImage($drawing, \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter::IMAGE_HEADER_RIGHT);
// Set header
$sheet->getHeaderFooter()->setOddHeader('&L&"Verdana,Negrita"&8HEADER TEXT&R&G');
After it sets the image object they is to set in OddHeader using codes:
$R -> To right align
$G -> Insert image
More info here.
I'd like to add an item on the last page of an existing PDF. The Item is added by an commercial non modifiable API.
The positon and size is definied relative to the Page. To support diffrent page formats, I have to get the page size of the existing PDF.
I've tried it with FPDI/FPDF but there are warnings. I'm not allowed to update the version.
Next try with the TCPDF doesn't throw an exception but after the import the function getNumPages returns 0;
Is there a possibility to get the page size of a PDF without using a library or a command line tool?
I have solved the problem by fixing the existing fpdi library. There were only small problems with the compatibility with newer PHP Versions. I've solved them. So I could use the following snippet:
$oPDF = new fpdi();
$iPageCount = $oPDF->setSourceFile($sFileLocation);
$mTemplateId = $oPDF->importPage($iPageCount);
$aTemplateSize = $oPDF->getTemplateSize($mTemplateId);
I've run into this weird issue with PDF file handling. Not sure if SO is the right place to ask this, but I couldn't find any specific sites for this. I hope that someone can shed some light on the issue.
This happens with the following specific process, if some of steps are omitted - the issue is not observed.
I have a PHP application that serves PDF files to users. These files are created by authors in MS Word 2007, then printed to protected PDF (using pdf995, most likely, I can confirm if needed).
I'll call this initial PDF file as 'source' hereinafter.
Upon request, the source file is processed in PHP the following way:
we decrypt it using qpdf:
qpdf --decrypt "source.pdf" "tmp_output.pdf"
Then we add security label / wartermark to it, encrypt and output to browser using mPDF 6.0:
$mpdf = new mPDF();
$mpdf->SetImportUse();
$pagecount = $mpdf->SetSourceFile($fpath);
if ($pagecount) {
for ($i=1;$i<=$pagecount;$i++){
$tplId = $mpdf->ImportPage($i);
$mpdf->UseTemplate($tplId);
$html = '[security label / watermark contents...]';
$mpdf->WriteHTML($html);
}
}
$mpdf->SetProtection(array('copy','print'), '', 'password',128);
$mpdf->Output('final_output.pdf','I');
With the exact steps described above, images in the output that were pasted in the Word doc appear as follows:
In the source PDF, tmp_output (qpdf decrypted file) the pasted images look correct:
The distortion doesn't take place if any of the following occurs:
Word doc printed to PDF without protection
mPDF output is not protected.
As you can see there too many factors, so I don't know where to look for a bug.
Each component works correctly on it's own and I cannot find any info on the issue. Any insights are greatly appreciated.
EDIT 1
After some more testing, it appears that this only happens to screenshots taken from web browser, Windows explorer, MS Word. Cannot reproduce this with screenshots from Gimp.
It appears that something along the way attempts to convert white to alpha and fails.
The current version (6.1) of Mpdf has a bug which does not handle escaped PDF strings (imported via FPDI) correct if they should be encrypted.
A pull request, which fixes this issue is available here.
I have gone through this link for the barcode generation.
I have downloaded the zip file and tested in my local host. It worked there, after that I have kept the files in my project and checked there. It doesn't work instead it gave me corrupted image as below.
GIF87aP���������,P���������p�قzu���b�a�I���xmZơFÌ,��}r�~���[�pH��(��>V�ie����q����dZΰ�+�����'�=]��n9?^wv�g��W���UƵ���h�8x(h�����GG� I��z�I:�j�y*zY�ij�::[� �Z+p+�J�k�Z�K�k�|��L�)����`N���qt���r���"�P���>�NA<~��]�p��{���!D +Z�ؠ;
Now I've created a sample file in the same location in my project with simple <?php ?> tags and kept the code
include "Barcode39.php";
// set Barcode39 object
$bc = new Barcode39("abc");
// display new barcode
$bc->draw();
again it worked in the sample file which I have kept in the project, but it is not working in the project related file.
Not getting the issue here.
Its perfectly working fine, make sure Barcode39.php in the same location.
As well it required PHP:GD, check again its install or not.
(Include could be issue if you are using any other framework)
I tested and got the below output
You can also use the below code to generate the gif file of barcode and link it anywhere in any page. you will not face any issue related to using html tags.
<?
// include Barcode39 class
include "Barcode39.php";
// set object
$bc = new Barcode39("123-ABC");
// set text size
$bc->barcode_text_size = 5;
// set barcode bar thickness (thick bars)
$bc->barcode_bar_thick = 4;
// set barcode bar thickness (thin bars)
$bc->barcode_bar_thin = 2;
// save barcode GIF file
$bc->draw("barcode1.gif");
?>
and include this file in the src attr of the image tag like
<img src="http://localhost/yourbarcodefilepath" alt="barcode"/>
then it will work
I'm a beginner here and need help. I have this code, which works and outputs a graph in my browser (if this is the only code in php file). I don't know how to add text below or above just like any other site. When I try, it returns my whole code in the browser. How do I go on about this?
<?php
// content="text/plain; charset=utf-8"
require_once ('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_line.php');
// Some data
$ydata = array(11,3,8,12,5,1,9,8,5,7);
// Create the graph. These two calls are always required
$graph = new Graph(350,250);
$graph->SetScale('textlin');
// Create the linear plot
$lineplot=new LinePlot($ydata);
$lineplot->SetColor('blue');
// Add the plot to the graph
$graph->Add($lineplot);
// Display the graph
$graph->Stroke();
?>
Thanks in advance!
What you need is quite simply:
<img src="graph.php">
Put that in a separate HTML file or PHP script. You cannot output the image and text in the same script / web page. It needs to be separated.
Don't worry about the .php extension for the image src= attribute. It will display despite the lack of .jpeg extension. (The Graph class already outputs the correct MIME type I assume.)
I'm a bit rusty on PHP, but I believe that all "require" are supposed to be made before any content is output. Otherwise, the normal HTML/XHTML syntax and formatting take precedence.
I haven't actually used this library, but I'm assuming the image is output directly to the browser. It's probably easiest to create a new HTML document (or whatever the rest of your site is powered by) and include this as an image, with the image's src being the name of this script.