Monday, August 8, 2016

PDF parsing using pdfparser

PdfParser, a standalone PHP library, provides various tools to extract data from a PDF file.
Currently, secured documents are not supported.
This Library is still under active development. As a result, users must expect BC breaks when using the master version.

Prerequisites

This library requires PHP 5.3.
PDFParser is built on top of TCPDF parser.
This library will be automatically downloaded through Composer command line.

Installation

Using Composer

Add PDFParser to your composer.json file :
{
    "require": {
        "smalot/pdfparser": "*"
    }
}
Now ask for composer to download the bundle by running the command:
$ composer update smalot/pdfparser

As standalone library

First of all, download the library from Github by choosing a specific release or directly the master.
Once done, unzip it and run the following command line using composer.
composer update
This command will download any dependencies (Atoum library) and create the 'autoload.php' file.
Now create a new file with this content, in the same folder :
<?php

// Include 'Composer' autoloader.
include 'vendor/autoload.php';

// Your code
// ...

?>

Unit tests with Atoum

Run Atoum unit tests (with code coverage - if xdebug installed) :
$ vendor/bin/atoum -d vendor/smalot/pdfparser/src/Smalot/PdfParser/Tests/
Once this command is ended, the folder "coverage/" will contain html pages with a code coverage summary.

Use

This sample will parse all the pdf file and extract text from each page.
<?php

// Include Composer autoloader if not already done.
include 'vendor/autoload.php';

// Parse pdf file and build necessary objects.
$parser = new \Smalot\PdfParser\Parser();
$pdf    = $parser->parseFile('document.pdf');

$text = $pdf->getText();
echo $text;

?>
You can too extract text from each page handly or for a specific page.

Download demo here

Monday, August 1, 2016

How do I enable functions, procedures, and triggers for my Amazon RDS MySQL instance?

I need to enable functions, procedures, and triggers for an instance of MySQL on Amazon RDS. How can I do this?
To use functions, procedures, or triggers when binary logging is enabled requires the MySQL SUPER privilege, which is restricted for RDS MySQL DB instances.
You can can enable functions, procedures, and triggers when binary logging is enabled without the SUPER privilege by setting thelog_bin_trust_function_creators parameter to true for the DB parameter group that you create for your MySQL instance(s).
Note
A default DB parameter group is created if you create a DB instance without specifying a DB parameter group that you create. This group contains database engine defaults and Amazon RDS system defaults based on the engine, compute class, and allocated storage of the instance. You cannot modify the parameter settings of a default DB parameter group; you must create your own DB parameter group to change parameter settings from their default value. Note that not all DB engine parameters can be changed in a DB parameter group that you create.
  1. Sign in to the AWS Management Console and open the Amazon RDS console at https://console.aws.amazon.com/rds/
  2. In the navigation pane, choose Parameter Groups.
  3. Choose Create Parameter Group. The Create Parameter Group window appears.
  4. For Parameter Group Family, choose the parameter group family.
  5. For Group Name, type the name of the new DB parameter group.
  6. For Description, type a description for the new DB parameter group.
  7. Choose Create.
Important
After you create a DB parameter group, you should wait at least 5 minutes before creating your first DB instance that uses that DB parameter group.
For more information about creating a DB parameter group, see Working with DB Parameter Groups - Creating a DB Parameter Group.
  1. In the navigation pane, choose Parameter Groups. The available DB parameter groups appear in a list.
  2. In the list, select the parameter group you want to modify.
  3. Choose Edit Parameters and set the following parameter to the specified value:
        log_bin_trust_function_creators = 1
  4. Choose Save Changes.
Important
After you modify a DB parameter group, you should wait at least 5 minutes before creating your first DB instance that uses that DB parameter group.
For information about modifiying a DB parameter group, see Working with DB Parameter Groups - Modifying Parameters in a DB Parameter Group.
  1. In the navigation pane, choose Instances.
  2. Select the DB instance you want to associate with a DB parameter group.
  3. On the Instance Actions menu, choose Modify.
  4. In the Modify DB Instance dialog box, under Database Options, choose the parameter group you want to associate with the DB instance. Changing this setting does not result in an outage. The parameter group name changes immediately, but the actual parameter changes are not applied until you reboot the instance without failover.
  5. Apply changes by rebooting the instance.
Amazon RDS, MySQL, error 1419, create functions, super privilege, CURRENT_USER, stored procedure, DB parameter group, triggers, binary logging