Insert Text in PDF with PHP but without Zend Framework - php

At the moment I am using this code to insert text in a PDF:
$pdf = Zend_Pdf::load("test_document.pdf");
$font = Zend_Pdf_Font::fontWithPath('arial_unicode_ms.ttf');
foreach ($pdf->pages as &$page) {
$page->setFont($font, 12);
$page->drawText("Inserted some text.", 200, 10);
}
The problem is, that I want to include this functionality in a Joomla plugin and I don't want to include all the data from Zend Framework to my project.
Is there any easy way or any small library which provides this pdf tagging mechanism?

If you still want to use Zend_Pdf, you'll probably need to have a look at the dependencies in the Zend/Pdf directory. You can grep for require_once to have a rough idea, and filter out the Zend/Pdf results:
grep -r require_once Pdf.php Pdf | grep -v "Zend/Pdf"
The first step outputs Zend_Memory, Zend_Exception and Zend_Log.
You can follow a similar method to check additional dependencies, and you'll see that Zend_Memory needs Zend_Cache, which needs only Zend_Log, which is self-contained, like Zend_Exception. I think you won't need to go much further, once you have included these four additional libraries.
EDIT: I found this link that lists all the dependencies between ZF modules (don't know how up to date it is, though): http://files.zend.com/help/Zend-Framework/requirements.dependencies.html
Hope that helps,

There are other pdf libraries available. I have used tcpdf in place of Zend_Pdf occassionally. It is all self contained, so you won't have any dependency issues with it.
In answer to your comment
I started using TCPDF as Zend_Pdf was incomplete and I needed a solution that would allow me to use existing pdf's as base documents as you seem to need. The solution I eventually opted for was to use FPDI in conjunction with TCPDF.
I haven't worked on that project for a while now, but I used the FPDI web site as the start of the solution that eventually worked for me.
I'm not sure if it will be a solution for you too, but it's worth having a look.

It is not necessary to include the whole Zend Framework with your project, you only need to include the Zend/Pdf.php and the Zend/Pdf folder. This isn't that large (combined size of ~ 1.2mb).

Related

How to properly install/use LESS in CodeIgniter

My original problem was linking multiple stylesheet frameworks. My primary option was Materialize and for reasons, i'd like to integrate Bootstrap on some buttons and other components. After hours of desperate research, i found myself staring at css pre-processors, e.g. LESS and SASS. I found out that you can do dynamic css using these badasses.
Investing a couple more hours deciding which to use, I ended up failing to install both.
So far I managed to download bootstrap sass and integrated it inside my project and compiled it using grunt (follow this instruction). I don't know how to use it and where to start.
I found some cool references here but it was not enough to get me going.
.bootstrap {
#import "/bootstrap.less"
}
I have so my follow up questions to the post:
should I link the less file on my index.php?
can I use any editor and compile the less with any less compiler?
should i link the compiled less or the created css?
do I even need to use LESS for this?
Note: I'm a total newbie with LESS and SASS. Any information is a ++.
I personally prefer Sass and I use it a lot even for small CSS stylesheets!
Here you are my answer:
Absolutely not! A less file is not intended for browser parsing. It is intended only for development purpose, that is to produce one or more .css file.
Feel free to use any editor you prefer and compile with any compiler you prefer. For example, I use Scout-App for Sass.
You must link only .css produced files.
It depends on your project and/or your needs. LESS and Sass are very similar.
Other tips for you:
Install on your CodeIgniter app an asset helper, and in asset folder place your css and less files. See the directory structure below:
application
system
user_guide
assets
--css
--less
--js
--img
ecc...
Put your less file separated from your css file. Link css file with the asset helper and you will have autoupdatable style!
If you use Git, remember to ignore css folder and track less or sass folder.
I hope you can find these tips helpful!
UPDATE: It's a shame that no one answer to this question in time!

How to use PHP classes from GitHub?

I am trying to do some PDF form filling. I found this PHP library:
https://github.com/mikehaertl/php-pdftk
However, I have never installed libraries before and am not sure how to proceed. I already have pdftk installed on the server. I read about autoload, and am familiar with functions like require_once, etc, but I am really not sure how to properly go about this. Any help is appreciated!
Regards
Hard to say without seeing the project but if there are a ton of files then there is probably 1 that is using the rest as dependencies. What I mean by that is that there should be 1 file that you can require_once. See if there is a readme. That's usually my first step.
I don't know this particular library, but usually it is just enough to require_once on the library's main class.
Edit: The library uses Composer to resolve its dependencies. You could do the same: https://getcomposer.org

Best Way to Install Zend Framework 2

I'm new to the Zend Framework but have used PHP in the past. I've gone through the basic tutorial provided by Zend, and understand a lot of it, but I'm fuzzy on the installation process. There seems to be many different ways to install, is that right? Here are the ways I've seen:
Download .zip file and manually extract
Use command line with composer.phar
Use command line with zftool
If someone could give a brief explanation of each of those above methods, how they differ, and which one is better, that would be great!
Also, two more quick questions on topic:
The tutorial mentions including Zend in your PHP include path. Why would you need to do this if the framework is included in the projects directory?
Is there a way to install the framework without the skeleton app?
Thanks in advance!
I'll only go about the 2nd set of questions:
You don't. You either have it inside your include path or inside your projects.
php composer.phare require zendframework/zendframework 2.2.*
Your first question is rather opinionated and it heavily depends on your workflow. To quote some song lyrics:
Sei ying there is no special move that is best, it all depends, any move could be best,
its up to you when the times right, to move correctly, accurately and with great speed...
tl/dr choose the method that seems most practical to your solution.
Try this website: http://www.packtpub.com/article/building-your-first-zend-framework-application
It shows how to install, add a virtual host and skeleton application and add modules to that application.
Happy learning
Use Zip if you dont have access to other methods (composer or git). With Zip you wont be able (easily) to upgrade or downgrade components.
composer is great because you can configure your needs. for example:
"require": {
"zendframework/zend-config": "2.2.*",
"zendframework/zend-http": "2.2.*"
},
More info: http://framework.zend.com/downloads/composer
Use Git if you wish to be on the edge (more hard to maintain versions)

Using Zend Service Amazon

Originally, I was searching how to use php to retrieve book information from amazon. and I found this question:
How can I use Amazon's API in PHP to search for books?
I think this works, but I am having stupid question. I am not able to install and use Zend Service Amazon. I downloaded the software of around 60 MB but, was corrupted.
May be, I actually want some php files to implement it. but, its giving some kind of exe file.
so, here my question is;
Where do I download Zend framework?
How do I install it?
How do I use it?
Thanks in advance
The official download for Zend Framework can be found here. Since you intend to use ZF more as a library than an MVC application framework, you only really need to download the much smaller minimal package.
From looking at the Amazon files you are interested in, I think the list of the following files are all you would need to copy into your application in order to use the Zend Framework Amazon Service APIs (when I use ZF as a library, I always try to only include the actual files I will be using, rather than the whole package, but for starters you can just copy the entire Zend folder to get going):
Zend/Exception.php
Zend/Loader.php
Zend/Loader/Autoloader.php
Zend/Loader/Exception.php
Zend/Uri.php
Zend/Uri/Exception.php
Zend/Service/Abstract.php
Zend/Service/Amazon.php
Zend/Service/Exception.php
Zend/Service/Amazon/Abstract.php
Zend/Service/Amazon/Accessories.php
Zend/Service/Amazon/Authentication.php
Zend/Service/Amazon/CustomerReview.php
Zend/Service/Amazon/EditorialReview.php
Zend/Service/Amazon/Image.php
Zend/Service/Amazon/Item.php
Zend/Service/Amazon/ListmaniaList.php
Zend/Service/Amazon/Offer.php
Zend/Service/Amazon/OfferSet.php
Zend/Service/Amazon/Query.php
Zend/Service/Amazon/ResultSet.php
Zend/Service/Amazon/SimilarProduct.php
Zend/Rest/Client.php
Zend/Rest/Client/Result.php
Zend/Rest/Client/Result/Exception.php
Zend/Crypt.php
Zend/Crypt/Exception.php
Zend/Crypt/Hmac.php
Zend/Crypt/Hmac/Exception.php
If I missed any, forgive me; you should get an exception saying class not found if I left any out, and that should be pretty straightforward to resolve which additional file(s) you need to include.
In order to use Zend Framework I recommending doing the following:
First and foremost, add Zend Framework's files to your PHP include_path. In order to use the ZF files, you need to preserve the directory structure they use, at the very least, you need a Zend folder with all the ZF files in there.
Add to your include path like this:
set_include_path(get_include_path() . PATH_SEPARATOR . '/zf/folder/path');
zf/folder/path should be the path to the folder that the Zend directory is in, but make sure not to actually include the Zend folder in the include path (since Zend does require_once 'Zend/File.php';
Secondly, set up the autoloader if possible. If you decide to use the Zend Framework autoloader, you won't have to manually 'require_once' many of the ZF files.
To set up their autoloader, all you have to do is get an instance of it:
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
You don't need to save or do anything with $autoloader. Just that call is enough to register the Zend autoloader. Since the ZF files are in your path, it will automatically know how to load and locate all ZF files.
After you perform those steps, you are able to use the Amazon services via Zend Framework in your PHP application.
As for the details of using that, hopefully you can find all the details and help you need here, Zend_Service_Amazon Reference Guide. The reference guide should be your best bet, but you can always find the phpDocumentor class documentation here.
Hope that helps! Feel free to ask if you need clarification on anything.

Best practices for php project organization using GIT?

I'm working on releasing a PHP framework I have been using for a few years
on github. Been trying to read up on the most correct way a project
should be structured, what extra files such as readme's etc should be
added. Been coming up with blanks on google. Can anyone point me to a
project that's a good example or any good write ups.
Some PHP projects hosted on Git(hub) include:
CakePHP
Gallery3
Garden
PHPUnit
Kohana
I'd just make sure that no temporary files, etc. get in the repository by creating a .gitignore file, and add some readme's etc. to the root of the repository.
Any configuration files should also be ignored, and sample configuration files should be created in the repository.
I'd recommend writing the readme file in a format that Github supports, like Markdown. It'll make your repository front page look better.
You might want to follow some kind of class naming guideline to make things like autoloading easier to implement. For example, the class MyFramework_Controller should be located at directory /lib/MyFramework/Controller.php.
You should just create some kind of basic layout for now - it'll be easier to give suggestions when we can see what you have right now.

Categories