Delphi For PHP Forums    


Go Back   Delphi-PHP Forums > Programming > PHP - Code Snippets
Forum Jump Register FAQ Members List Downloads Search Today's Posts Mark Forums Read

PHP - Code Snippets Functional Code Snippets that other people may find useful. Post them here!

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 9th October 2009, 15:10
Marco Amici's Avatar
D4PHP User
 
Join Date: Jan 2009
Location: Rome
Posts: 18
Marco Amici is on a distinguished road
Send a message via MSN to Marco Amici Send a message via Skype™ to Marco Amici
Default Fantastic Generator PDF / Delphi for Php

Hi All
Today I tried this wonderful tool for print.
Good this is result, look this movie ( little tutorial ) :
http://www.marcoamici.com/public/download/imaging.htm

And this is result:



It is very easy to use:

1) First if your PHP and checking for the SOAP extension

reading: Using LiveDocx with PHP 5 SoapClient | phpLiveDocx

2) If you need soap also remember to enable the following extensions
php_soap.dll
php_openssl.dll

3) This is code with 3 examples
Quote:
<?php
require_once("vcl/vcl.inc.php");
include("funzioni_print.php");
//Includes
use_unit("components4phpfull/jtobjectcontrol.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Unit1 extends Page
{
public $Button3 = null;
public $Button2 = null;
public $JTObjectControl1 = null;
public $JTSiteTheme1 = null;
public $Button1 = null;
//
// SAMPLE #3 - Esempio Personale
//
function Button3Click($sender, $params)
{

$soap = new SoapClient(ENDPOINT);

$soap->LogIn(
array(
'username' => USERNAME,
'password' => PASSWORD
)
);

$data = file_get_contents('./esempioxx.doc');

$soap->SetLocalTemplate(
array(
'template' => base64_encode($data),
'format' => 'doc'
)
);

// Assign data to template

$fieldValues = array (
'destinatario' => 'Magic Graphical Compression Suite v2.5',
'societadestinatario' => 'Marco Amici Example see its fantastic tools',
'data' => date('F d, Y'),
'indirizzo' => 'Roma - Piazza Mazzini n.32',
'altro' => 'Test TEST test ò è à'

);

$soap->SetFieldValues(
array (
'fieldValues' => assocArrayToArrayOfArrayOfString($fieldValues)
)
);

// Build the document

$soap->CreateDocument();

// Get document as PDF

$result = $soap->RetrieveDocument(
array(
'format' => 'pdf'
)
);

$data = $result->RetrieveDocumentResult;

// Name File
$nomedocumento = "./esempio.pdf";

//file_put_contents('./license-agreement-document.pdf', base64_decode($data));
file_put_contents($nomedocumento, base64_decode($data));

// PDF into Object
$this->JTObjectControl1->Data = $nomedocumento;

// Log out (closes connection to backend server)

$soap->LogOut();

unset($soap);

}

function Button2Click($sender, $params)
{


//
// SAMPLE #2 - Telephone Bill


$soap = new SoapClient(ENDPOINT);

$soap->LogIn(
array(
'username' => USERNAME,
'password' => PASSWORD
)
);

// Upload template

$data = file_get_contents('./telephone-bill-template.doc');

// Assign field values data to template

$soap->SetLocalTemplate(
array(
'template' => base64_encode($data),
'format' => 'doc'
)
);

$fieldValues = array (
'customer_number' => sprintf("#%'10s", rand(0,1000000000)),
'invoice_number' => sprintf("#%'10s", rand(0,1000000000)),
'account_number' => sprintf("#%'10s", rand(0,1000000000)),
'phone' => '+49 421 335 9000',
'date' => date('F d, Y'),
'name' => 'James Henry Brown',
'service_phone' => '+49 421 335 910',
'service_fax' => '+49 421 335 9180',
'month' => date('F Y'),
'monthly_fee' => '€ 15.00',
'total_net' => '€ 100.00',
'tax' => '19%',
'tax_value' => '€ 15.00',
'total' => '€ 130.00'
);

$soap->SetFieldValues(
array (
'fieldValues' => assocArrayToArrayOfArrayOfString($fieldValues)
)
);

// Assign block field values data to template

$blockFieldValues = array (
array ('connection_number' => '+49 421 335 912', 'connection_duration' => '00:00:07', 'fee' => '€ 0.03'),
array ('connection_number' => '+49 421 335 913', 'connection_duration' => '00:00:07', 'fee' => '€ 0.03'),
array ('connection_number' => '+49 421 335 914', 'connection_duration' => '00:00:07', 'fee' => '€ 0.03'),
array ('connection_number' => '+49 421 335 916', 'connection_duration' => '00:00:07', 'fee' => '€ 0.03')
);

$soap->SetBlockFieldValues(
array (
'blockName' => 'connection',
'blockFieldValues' => multiAssocArrayToArrayOfArrayOfString($blockFieldValues)
)
);

// Build the document

$soap->CreateDocument();

// Get document as PDF

$result = $soap->RetrieveDocument(
array(
'format' => 'pdf'
)
);

$data = $result->RetrieveDocumentResult;


// Name File
$nomedocumento = "./example_bill.pdf";


file_put_contents($nomedocumento, base64_decode($data));

// PDF into Object
$this->JTObjectControl1->Data = $nomedocumento;



// Log out (closes connection to backend server)

$soap->LogOut();

unset($soap);

}
function Button1Click($sender, $params)
{


// -----------------------------------------------------------------------------

//
// SAMPLE #1 - License Agreement
//
// Instantiate SOAP object and log into LiveDocx

$soap = new SoapClient(ENDPOINT);

$soap->LogIn(
array(
'username' => USERNAME,
'password' => PASSWORD
)
);

// Upload template

$data = file_get_contents('./license-agreement-template.docx');

$soap->SetLocalTemplate(
array(
'template' => base64_encode($data),
'format' => 'docx'
)
);

// Assign data to template

$fieldValues = array (
'software' => 'Magic Graphical Compression Suite v2.5',
'licensee' => 'Marco Amici Example see its fantastic tools',
'company' => 'Megasoft Co-Operation',
'date' => date('F d, Y'),
'time' => date('H:i:s'),
'city' => 'Berlin',
'country' => 'Germany'
);

$soap->SetFieldValues(
array (
'fieldValues' => assocArrayToArrayOfArrayOfString($fieldValues)
)
);

// Build the document

$soap->CreateDocument();

// Get document as PDF

$result = $soap->RetrieveDocument(
array(
'format' => 'pdf'
)
);

$data = $result->RetrieveDocumentResult;

// Name File
$nomedocumento = "./licenze.pdf";

//file_put_contents('./license-agreement-document.pdf', base64_decode($data));
file_put_contents($nomedocumento, base64_decode($data));

// PDF into Object
$this->JTObjectControl1->Data = $nomedocumento;

// Get document as bitmaps (one per page)

$result = $soap->GetAllBitmaps(
array(
'zoomFactor' => 100,
'format' => 'png'
)
);

$data = array();

if (isset($result->GetAllBitmapsResult->string)) {
$pageCounter = 1;
if (is_array($result->GetAllBitmapsResult->string)) {
foreach ($result->GetAllBitmapsResult->string as $string) {
$data[$pageCounter] = base64_decode($string);
$pageCounter++;
}
} else {
$data[$pageCounter] = base64_decode($result->GetAllBitmapsResult->string);
}
}

foreach ($data as $pageCounter => $pageData) {
$pageFilename = sprintf('./license-agreement-document-page-%s.png', $pageCounter);
file_put_contents($pageFilename, $pageData);
}

// Get document as Windows metafiles (one per page)

$result = $soap->GetAllMetafiles();

$data = array();

if (isset($result->GetAllMetafilesResult->string)) {
$pageCounter = 1;
if (is_array($result->GetAllMetafilesResult->string)) {
foreach ($result->GetAllMetafilesResult->string as $string) {
$data[$pageCounter] = base64_decode($string);
$pageCounter++;
}
} else {
$data[$pageCounter] = base64_decode($result->GetAllMetafilesResult->string);
}
}

foreach ($data as $pageCounter => $pageData) {
$pageFilename = sprintf('./license-agreement-document-page-%s.wmf', $pageCounter);
file_put_contents($pageFilename, $pageData);
}

// Log out (closes connection to backend server)

$soap->LogOut();

unset($soap);




}

}

global $application;

global $Unit1;

//Creates the form
$Unit1=new Unit1($application);

//Read from resource file
$Unit1->loadResource(__FILE__);

//Shows the form
$Unit1->show();

?>
4) funzioni_print.php
Quote:
<?php
// Turn up error reporting
error_reporting (E_ALL|E_STRICT);

// Turn off WSDL caching
ini_set ('soap.wsdl_cache_enabled', 0);

// Define credentials for LD
define ('USERNAME', 'yourname');
define ('PASSWORD', 'yourpassword');

// SOAP WSDL endpoint
define ('ENDPOINT', 'https://api.livedocx.com/1.2/mailmerge.asmx?WSDL');

// Define timezone
date_default_timezone_set('Europe/Berlin');


/**
* Convert a PHP assoc array to a SOAP array of array of string
*
* @param array $assoc
* @return array
*/
function assocArrayToArrayOfArrayOfString ($assoc)
{
$arrayKeys = array_keys($assoc);
$arrayValues = array_values($assoc);

return array ($arrayKeys, $arrayValues);
}

/**
* Convert a PHP multi-depth assoc array to a SOAP array of array of array of string
*
* @param array $multi
* @return array
*/
function multiAssocArrayToArrayOfArrayOfString ($multi)
{
$arrayKeys = array_keys($multi[0]);
$arrayValues = array();

foreach ($multi as $v) {
$arrayValues[] = array_values($v);
}

$_arrayKeys = array();
$_arrayKeys[0] = $arrayKeys;

return array_merge($_arrayKeys, $arrayValues);

}


?>
anyway you can see this and another here:
phpLiveDocx - Generate PDF, DOCX, DOC & RTF with PHP


Good Day
Marco

Last edited by Marco Amici; 9th October 2009 at 15:21.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 04:34.




Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 ©2009, Crawlability, Inc.
Copyright © 2004 - 2009, G&J Solutions Ltd. All Rights Reserved. terms of use