Conversion samples
Methods
doc2pdf
Description:
Method | Return values | Description |
---|---|---|
doc2pdf($content, $fileName) |
string |
Retrieve the uploaded document converted to PDF format. |
Parameters: $fileName string type is the document file name. Application uses this parameter to identify by document extension the document MIME TYPE. |
||
The openoffice service must be enabled in OpenKM server to get it running. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleConversion {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testDoc2pdf($method) {
try {
$fileName = dirname(__FILE__) . '/files/test.docx';
$content = $this->ws->doc2pdf(file_get_contents($fileName), "test.docx");
switch ($method) {
case 1:
$file = fopen(dirname(__FILE__) . '/files/out.pdf', 'w+');
fwrite($file, $content);
fclose($file);
echo 'conversion correct';
break;
case 2:
header('Expires', 'Sat, 6 May 1971 12:00:00 GMT');
header('Cache-Control', 'max-age=0, must-revalidate');
header('Cache-Control', 'post-check=0, pre-check=0');
header('Pragma', 'no-cache');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="out.pdf"');
echo $content;
break;
}
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleConversion = new ExampleConversion();
$exampleConversion->testDoc2pdf(1);
?>
pdf2swf
Description:
Method | Return values | Description |
---|---|---|
pdf2swf($content, $fileName) |
string |
Retrieve the uploaded document converted to SWF format. |
Parameters: $fileName string type is the document file name. Application uses this parameter to identify by document extension the document MIME TYPE. The pdf2swf tool must be enabled in OpenKM server to get it running. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleConversion {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testPdf2swf($method) {
try {
$fileName = dirname(__FILE__) . '/files/test.pdf';
$content = $this->ws->pdf2swf(file_get_contents($fileName), "test.pdf");
switch ($method) {
case 1:
$file = fopen(dirname(__FILE__) . '/files/out.swf', 'w+');
fwrite($file, $content);
fclose($file);
echo 'conversion correct';
break;
case 2:
header('Expires', 'Sat, 6 May 1971 12:00:00 GMT');
header('Cache-Control', 'max-age=0, must-revalidate');
header('Cache-Control', 'post-check=0, pre-check=0');
header('Pragma', 'no-cache');
header('Content-Type: application/x-shockwave-flash');
header('Content-Disposition: attachment; filename="out.swf"');
echo $content;
break;
}
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleConversion = new ExampleConversion();
$exampleConversion->testPdf2swf(1)
?>
imageConvert
Description:
Method | Return values | Description |
---|---|---|
imageConvert($content, $fileName, $params, $dstMimeType) |
string |
Retrieve the uploaded image with transformation. |
Parameters: $fileName string type is the document file name. Application uses this parameter to identify by document extension the document MIME TYPE. $params string type $dstMimeType string type is the expected document MIME TYPE result. The variable fileName is the document file name. Application uses this variable to identify by document extension the document MIME TYPE. The parameter dstMimeType is the expected document MIME TYPE result. Using this method you are really executing on server side the ImageMagick convert tool. You can set a lot of parameters - transformations - in params variable. Take a look at ImageMagick convert tool to get a complete list of them. The image convert tool must be enabled in OpenKM server to get it running. When params value is not empty always must contains ends with the chain "${fileIn} ${fileOut}". Ensure there is only a white space as separator between two parameters. When building your integrations, we suggest installing ImageMagic software locally, and check your image transformations first from your command line.
|
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleConversion {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testImageConvert() {
try {
$fileName = dirname(__FILE__) . '/files/test.png';
$content = $this->ws->imageConvert(file_get_contents($fileName), "test.png", "-resize 50% \${fileIn} \${fileOut}", "image/jpeg");
$file = fopen(dirname(__FILE__) . '/files/out.jpg', 'w+');
fwrite($file, $content);
fclose($file);
echo 'imvage convert';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleConversion = new ExampleConversion();
$exampleConversion->testImageConvert();
?>
html2pdf
Description:
Method | Return values | Description |
---|---|---|
html2pdf($url) |
string |
Retrieve the PDF of an URL. |
Parameters: $url string type The HTML to PDF conversion tool must be enabled in OpenKM server to get it running. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleConversion {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testHtml2pdf() {
try {
$content = $this->ws->html2pdf("http://www.openkm.com");
$file = fopen(dirname(__FILE__) . '/files/outhtml.pdf', 'w+');
fwrite($file, $content);
fclose($file);
echo 'html to pdf correct';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleConversion = new ExampleConversion();
$exampleConversion->testHtml2pdf();
?>
doc2txt
Description:
Method | Return values | Description |
---|---|---|
doc2txt($content, $fileName) |
string |
Extracts the text from the upload document. |
Parameters: $fileName string type is the document file name. Application uses this parameter to identify by document extension the document MIME TYPE. Must be enabled a Text Extractor for the document MIME TYPE in OpenKM server to get it running. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleConversion {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testDoc2txt() {
try {
$fileName = dirname(__FILE__) . '/files/test.docx';
$content = $this->ws->doc2txt(file_get_contents($fileName), "test.docx");
echo $content;
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleConversion = new ExampleConversion();
$exampleConversion->testDoc2txt();
?>
img2txt
Description:
Method | Return values | Description |
---|---|---|
img2txt($content, $fileName) |
string |
Extracts the text from the uploaded image. |
Parameters: $fileName string type is the document file name. Application uses this parameter to identify by document extension the document MIME TYPE. The OCR engine must be enabled in OpenKM server to get it running. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleConversion {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testImg2txt() {
try {
$fileName = dirname(__FILE__) . '/files/test.png';
$content = $this->ws->img2txt(file_get_contents($fileName), "test.png");
echo $content;
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleConversion = new ExampleConversion();
$exampleConversion->testImg2txt();
?>
barcode2txt
Description:
Method | Return values | Description |
---|---|---|
barcode2txt($content, $fileName) |
string |
Extracts the barcode text from the uploaded image. |
Parameters: $fileName string type is the document file name. Application uses this parameter to identify by document extension the document MIME TYPE. The Bar Code tool must be enabled in OpenKM server to get it running. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleConversion {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testBarcode2txt() {
try {
$fileName = dirname(__FILE__) . '/files/test.png';
$content = $this->ws->barcode2txt(file_get_contents($fileName), "test.png");
echo $content;
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleConversion = new ExampleConversion();
$exampleConversion->testBarcode2txt();
?>