some of the fonts like ArialMT, Arial-boldMT, PTSans-bold..
when i am using this font like
$pdf->SetFont("ArialMT", "", 22);
then i got error like..
TCPDF ERROR: Could not include font definition file
when i saw the font folder of TCPDF library then i could not see this type of font..
how to install this font in TCPDF to solve the error and get effect of this font??
please help it is urgent..
thank you in advance..
i found one solution that in "fonts/utils/ttf2ufm.exe" then run following to command 1)$ ttf2ufm -a -F myfont.ttf and 2)$ php -q makefont.php myfont.ttf myfont.ufm first command is successfully executed but 2nd is not executing in windows command promt so tell me what i have to do for php file as you specify in "comici.php"..
Try this
$pdf->AddFont('Comic','I');
// is equivalent to:
$pdf->AddFont('Comic','I','comici.php');
You will find tutorial here.
http://api.joomla.org/com-tecnick-tcpdf/TCPDF.html#AddFont
Have you tried adding the font first?
$pdf->AddFont("ArialMT", "", 22);
If that does not work you can include the font in the library by using the command
$fontname = TCPDF_FONTS::addTTFfont(FCPATH.'/assets/css/fonts/ArialMT.otf');
For that you need to have the "otf" or "ttf" version of the font and set the correct directory.
For example I am using:
$fontname = TCPDF_FONTS::addTTFfont(FCPATH.'/assets/css/fonts/arialunicode050418/ArialUnicodeMS.otf');
// This should be ran only once to include the font. You can comment it afterwards.
$pdf->AddFont('ariaunicodems', '', 10, '',false);
$pdf->SetFont('ariaunicodems', '', 10, '',false);
You can print the "fontname" variable to see the correct name of the font to be added or set. It does not respond to the name of the font file.
TCPDF have a tool(tcpdf_addfont.php) to install any new font which is located in 'your_path_to_tcpdf/tools/ '
You can use the following command to install a new font to TCPDF.
path_to_tcpdf/tcpdf/tools/tcpdf_addfont.php -i path_to_ttf/ArialMT.ttf
The code above is pretty much self explanatory.
You can download the True Type (ttf) for any font easily using Google Search.
After running the above command you will get a output similar to:
>>> Converting fonts for TCPDF:
*** Output dir set to /path_to_tcpdf/tecnickcom/tcpdf/fonts/
+++ OK : path_to_ttf/ArialMT.ttf added as arial
>>> Process successfully completed!
Now use this font in TCPDF like any other font:
$pdf->SetFont("arial", "", 22);
You only have to create the font file once with TCPDF. This can be done, for example, with a separate PDF script.
It is important to know the exact path of the original ttf and, if necessary, to place it in the appropriate folder on the server.
TCPDF_FONTS::addTTFfont('File path to the ttf file.', 'TrueTypeUnicode', '', 32);
For all commands and details see:
https://stackoverflow.com/a/70337995/2320007
Related
I have PHP code running on Debian stretch with ImageMagick. It tries to convert SVG to another format. Here is how it starts
$im = new Imagick();
$im->readImageBlob($svg);
The variable $svg contains valid SVG code in a string. If I copy this string to a text file with a .svg extension then it opens just fine. But readImageBlob throws an exception saying no delegate for this image format.
I have seen similar questions solved by installing more packages to the system. But I've already installed libxml2-dev, librsvg2-bin, libmagickcore-6.q16-3-extra and libfreetype6-dev.
I have no idea what else I am missing.
I had to prepend the $svg with <?xml version="1.0" ?> and it worked. It least it does read in the SVG and attempts to create png/jpeg. One piece of text gets misplaced during convertion though. So the task in general is still failed. But this is another issue. I think the question is answered.
What do you get from running the following command from PHP exec()
convert -list format
The line SVG should say RSVG or MSVG/XML. Does it show that? if you need RSVG, you will have to install that delegate and then reinstall Imagemagick so that Imagemagick can find it. Imagemagick is used by Imagick. They are not the same. The RSVG delegate can be found by a Google Search or from linuxfromscratch.org/blfs/view/svn/general/librsvg.html. Your svg file seems to render properly for me in Imagemagick using RSVG, but I am not sure what it should look like. It is just a graph set of horizontal lines.
I do not know much about using readImageBlob(). Just use readImage(), where you supply the path to a saved svg image file. That should work. Try that and see what you get.
Here is what I get using RSVG 2.42.2 in Imagemagick 6.9.10.3 Q16 Mac OSX were I have saved your text in a file called test.svg.
convert test.svg test.png
If I force the use of the Imagemagick MSVG/XML, it does not look as good.
convert MSVG:test.svg test2.png
When I am trying to upload a pdf file and separating each page as pdf, with some pdf files it is working but some of pdf files show this error:
mPDF error: Unable to find xref table -" Maybe a Problem with auto_detect_line_endings"
My code:
ini_set('memory_limit', '512M');
$pagecount = Model::count_pages($documentPath.$journalDoc);
for ($i=1; $i<=$pagecount; $i++) {
$pdf = new mPDF('','Letter',12,'helvetica, sans-serif',200,0,0,20,0,10,'P');
$pdf->SetImportUse();
$pdf->SetSourceFile($documentPath.$journalDoc);
$import_page = $pdf->ImportPage($i);
$pdf->UseTemplate($import_page);
$pdf->Output($output_dir.$i.'.pdf', 'F');
}
This can be caused by PDF files of a version incompatible with the mPDF you're running. You can often circumvent the problem by regressing the source PDF files.
For instance, for mPDF v6.0 try brining your PDFs down to at most v1.4 using something like Ghostscript. (Where old.pdf is you're sourcefile)
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -o new.pdf old.pdf
Ghostscript won't write to the file it's reading so if you're doing this inline you'll have to dance;
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -o new.pdf old.pdf; mv -f new.pdf old.pdf
Increase the length size of this
public static $trailerSearchLength = 5500;
to this
public static $trailerSearchLength = 500000;
file location is: vendor\setasign\fpdi\src\PdfParser\CrossReference\CrossReference.php
This can be caused by the PDF file version that is incompatible with mPDF. You would better regress the PDF file version.
If you extracted a page from a file, you may have used an Adobe software.
Just use pdftk or pdfchain on Linux platform to solve the problem.
The version of FPDI in the offical repo of mPDF is very old. You may try to update to the latest version. Or you simply use the official version of FPDI which uses FPDF.
If you get a message about "unssported compression" you may check out the FPDI PDF-Parser add-on. Notice that there's a license incompatibility to mPDF.
I am running the following code and giving me this error : FPDF error: This document (testcopy.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI. I used another pdf named test.pdf and that works fine but it is giving me error in testcopy.pdf.
I think this is parser problem. Anyone know any other parser that can be used with fpdf to avoid this error?
My code:
require('fpdf17/fpdf.php');
require('fpdf17/fpdi.php');
// initiate FPDI
$pdf = new FPDI();
while (ob_get_level())
ob_end_clean();
header("Content-Encoding: None", true);
// set the sourcefile
$pagecount = $pdf->setSourceFile('testcopy.pdf');
I want to split pdf in two pdfs and want to attach both pdfs in file attachments field.How to save pdf to server. Can it be possible with fpdf?
Yes, Exactly the FPDF library supports only PDF version 1.4 & lesser. So to over come from this issue use GhostScript. This script helps to change the PDF versions dynamically.
(1) Download the Ghostscript here.
(2) Install the Ghostscript and define the environment variable PATH.
(3) Then, use the below php code to change the PDF version.
shell_exec( "gswin32 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=".$new_pdf." ".$old_pdf."");
(4) Now we get PDF with version 1.4 as output, then continue with FPDF.
Enjoy!
I had the same issue that PDFMerger does not work with certain PDF.
It seems that Adobe keep updating compression way of pdf extension.
I found solution with Chrome.
1. Open the PDF file(which does not work with PDFMerger) with Chrome
2. Right Click and Print
3. Change destination as [Save as PDF]
4. This exported PDF file is compatible with PDFMerger
The file needs to be PDF 1.4 (Acrobat 5) or lower. If you have Adobe Acrobat Pro you can change this with Document->Decrease File Size.
Looking through the answers so far, I wasn't able to resolve the issue.
Here's why and you may have the same issue so this answer would be invaluable to you too.
I did not have access to acrobat, so I couldn't downgrade the version of the original PDF. I wasn't in a position to purchase the newer version of the library which has upgraded encryption.
In the end I used an online PDF converter to downgrade my PDF file to version 5 (1.4)
If you are not able to find one, here's a link for completeness.
https://docupub.com/pdfconvert/
(bear in mind that the contents of a link may change)
Here is my answer from another topic:
"It can be overcome by re-saving the template and change compression type.
In Adobe Acrobat Pro go to File->Save As->Optimised PDF-> Popup left list - Clean Up,
Object Compression Options -> Change to "Compress document structure" -> OK to save"
Ref. Editing password protected pdfs with fpdi
GPL Ghostscript 8.70 (2009-07-31) / Centos 7
ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=new_file.pdf file.pdf
For those that don't have any of the pro versions of Acrobat:
I was having this problem with new versions of Word when trying to use the Office functionality to save to a PDF. It seems the PDF conversion tool supplied in Office is using the newer formats. Here's how I fixed it.
Install NitroPDF free version (May work with another free PDF creator that can be downloaded)
Go to the Word document and select 'Print'.
In the print options, instead of your printer, select 'Nitro PDF Creator (Reader 3)' or whatever the current version is.
A dialog box will open and allow you to select where to save the PDF.
The version saved was able to be opened by FPDF.
Hope it helps
In the case of Mac, you can open the PDF file in Preview and "export as PDF". The exported one can then be used.
I had a very similar error like you. My solution was to convert the pdf to a lower pdf version. Than everything worked like expected.
I hope that simple trick will help you!
I'm using TCPDF with Drupal's print module to generate PDF of articles, & ending up with following error message when I click the link to generate PDF:
TCPDF ERROR: [Image] Unable to get image: http://localhost/pathToDrupal/themes/bartik/logo.png
The Image exists in the location specified.
I tried applying:
allow_url_fopen = On;
allow_url_include = On;
in php.ini but that could not resolve the problem.
Please care to help :(
Apparently the "fopen"-wrappers are not used by TCPDF.
If you supply the URL of an image, TCPDF tries to download it with cURL into the "cache"-directory where your TCPDF-installation is stored (you have to check what the K_PATH_CACHE-constant contains to be sure).
So I guess you have to have write permissions in this directory that the magic works. Also you need cURL enabled.
We had problems with the way connections were handled in our linux "example.com" server. So this lead us to try on the server:
curl -v http://www.example.com/image.jpg
Whenever TCPDF tried to download an image with curl, the image was not found, nevertheless, we could view the image by just opening it directly in the browser (e.g. http://www.example.com/image.jpg).
We solved the problem by setting the example.com VirtualHost to accept 127.0.0.1 connections and adding the line "127.0.0.1 example.com" to /etc/hosts.
Just use the image path as "images/your_image.png" instead of "http://yourdomain.com/images/your_image.png" in the PDF html.
I've found that TCPDF would throw the Unable to get Image: error when the src was an absolute link. Just changing to a relative link would successfully create the PDF.
I had this problem on a staging server where the docroot of the site was protected by an .htaccess file (to prevent search engine indexing and other confusions)
tcpdf uses curl to fetch the image and it gives this error if it cannot access the file.
To solve it, I added a rule to .htaccess to allow requests from the webserver
Allow from 123.45.6.7.8
Try to add path by current working dir.
$img = getcwd().'/web/bundles/_bundlename_/img/logo.png';
$pdf->Image($base_url.'/'.$node->field_loc_images[0]['filepath'] ,30, 40, 75, 113, 'JPG', '', '', true, 300, '');
In your font unicode problems you need to put this syntax code:
// set font
$fontname = $pdf->addTTFfont('../your path here/sampletruetype.ttf', 'TrueTypeUnicode', '', 32);
$pdf->SetFont($fontname, '', <font size value here>);
put it before you add the page...
In drupal be sure to include the tcpdf library in your function and not at the top of your module file or you will get this error.
try this also
foreach($node->field_loc_images as $key=> $s)
{
$pdf->Image($base_url.'/'.$s['filepath'], $x, $y, $w, $h, 'JPG', '', '', false, 300, '', false, false, 0, $fitbox, false, false);
}
To expand on the error. It also seems to fail with base64 embedded images. This is a big problem for me right now.
After I upgraded PHP 5.5 to 5.6, I lost hours because of an image error,
I found the solution here from #caligari (a comment on the accepted answer) and it fixed the problem for me:
install CURL like this:
apt-get install php5-curl && /etc/init.d/apache2 restart.
In my case I tried to
curl -v http://www.example.com/image.jpg
and the "curl: (60) server certificate verification failed." was shown. So it was simply a certificate issue.
I can't seem to get Imagick::setFont to work in php. Taking the example straight from the man page:
/* Create new imagick object */
$im = new Imagick();
/* Set the font for the object */
$im->setFont("comic.ttf");
/* Create new caption */
$im->newPseudoImage(100, 100, "caption:Hello");
$im->setformat('png');
header('Content-type: image/png');
echo $im;
I get...
http://i53.tinypic.com/2d2bn9x.png
... which is clearly not comic sans. I've tried numerous fonts. It never changes. It does complain if the file doesn't exist. It does not accept names like "Arial".
When you're using setFont method you need to make sure you pass absolute path of the font:
$im->setFont("/var/www/html/mysite/media/fonts/myCustomFont.ttf");
Same would apply for your localhost development just change the absolute path.
(This is a bit old question but I figured to answer it anyways.)
I'm having the same situation here and I found this post
http://www.imagemagick.org/discourse-server/viewtopic.php?f=10&t=11937
They say Freetype library should be installed, but haven't tried yet.
UPDATE
Finally I had chance to try it and It worked.
I use
ImageMagick 6.7.6
Imagick 3.0
Freetype 2.4.9
Freetype-devel 2.3.11
Fontconfig-devel 2.8
PHP 5.3.13