I am using Php PDFLIB to generate the pdf in my application I have gone through its block api by which we can define the block in pdf and we can populate that block values from db values
Eg::
http://www.pdflib.com/en/pdflib-cookbook/block-handling-and-pps/business-cards/php-business-cards/
I wanted know is there way we use the pdf loaded from AWS s3 link instead of storing that in Searchpath
i.e instead of the lines that says
$infile = "businesscard_blocks.pdf";
can we load something
$infile = aws/s3/path/businesscard_blocks.pdf
you should check out the PVF feature of PDFlib. With the PVF you can load resources from memory. So you create a named mapping between a variable data and file name.
So in your case you might load the data from AWS via a PHP function
$PDFfiledata = file_get_contents('https://XYZ.AWS.com/aws/s3/path/businesscard_blocks.pdf');
$p->create_pvf("/pvf/input.pdf", $PDFfiledata, "");
$doc = $p->open_pdi_document("/pvf/input.pdf", "");
then you can go ahead, as when you load the file from disc.
Please see the starter_pvf sample (http://www.pdflib.com/de/pdflib-cookbook/general-programming/starter-pvf/php-starter-pvf/) and PDFlib 9 Tutorial, chapter 3.1.2 "The PDFlib Virtual File System (PVF)"
Related
I have a Django app that contains a Video-on-Demand feature. It's powered by Azure Media Services (AMS). When a user uploads a video, I first save the video in an Azure storage blob, and then I use a PHP script (which utilizes the AMS php sdk) to encode the said video and prep a streaming URL (hosted on AMS).
My problem is this: how do I get the dimensions of the video? I need to know the height and width so that I can encode the video to lower res formats on AMS. I can't get the dimensions from python since I'm not uploading the video file onto a local server first (where my web server is running). What are my options? Please advise.
As you are using AMS SDK for PHP to create AMS task, and which requires the video asset file. You can leverage the PHP module http://getid3.sourceforge.net/ to get the info of video asset during the PHP process with a ease.
You can download the PHP module http://getid3.sourceforge.net/ and extract to your php application's folder, and you can use the following code snippet to get the dimensions of video asset:
require_once('./getid3/getid3.php');
$filename="<video_path>";
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($filename);
var_dump($ThisFileInfo['asf']['video_media']);
Any further concern, please feel free to let me know.
update using remotefile on Azure Storage
Here is a code sample, leveraging which, you can use the SAS url of blobs on Azure Storage. It will download the file to server folder, and detect the info, and then delete the template file.
$remotefilename = '<SAS Url>';
if ($fp_remote = fopen($remotefilename, 'rb')) {
$localtempfilename = tempnam('/tmp', 'getID3');
if ($fp_local = fopen($localtempfilename, 'wb')) {
while ($buffer = fread($fp_remote, 8192)) {
fwrite($fp_local, $buffer);
}
fclose($fp_local);
// Initialize getID3 engine
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($localtempfilename);
// Delete temporary file
unlink($localtempfilename);
}
fclose($fp_remote);
var_dump($ThisFileInfo);
}
I am trying to get specific metadata of an image located in dropbox using PHP and the Dropbox API.
After I connect to dropbox and list the images, I do this:
$md = $dbxClient->getMetadata($path);
print_r ($md);
Where the $path is the directory to my image. This works perfectly but I need to get more metadata regarding GPS location. In the Dropbox API (general view for Python, PHP, Java etc.) it says I have to set "include_media_info" to true to get gps metadata.
Going to the PHP part it has the function GetMetaData() with only one parameter: string
($path The Dropbox path to a file or folder).
Is there a way to get detailed metadata using the Dropbox API for PHP?
As you noted, the PHP library doesn't support the include_media_info parameter, so you'd need to modify the source code of the library to add support.
E.g. you could add this method:
function getMetadataWithMediaInfo($path)
{
Path::checkArg("path", $path);
return $this->_getMetadata($path, array("include_media_info" => "true"));
}
I had a look at the source, try this:
$md = $dbxClient->_getMetadata($path,array("list" => "true"));
or edit the core getMetadata and change its hard coded parameter list to true
I have PDF form files that I fill out dynamically with PHP using FPDM (the FPDF script). I can save them on my server no problem, and the text all looks fine in the PDF when I download and view in Acrobat.
My problem is: I'm trying to merge multiple PDF files together on the server so the user can download a single PDF document with several pages. I downloaded PDF Merger (http://pdfmerger.codeplex.com/) and got it merging the files together, but this causes the PDF form text to disappear.
Anyone know of a form-friendly PHP-based PDF merger that doesn't require installing anything (other than uploading libraries) to my server?
Code that works for merging but kills text in form boxes:
$pdfCombined= new PDFMerger;
$pdfCombined->addPDF('../forms/generated/16.pdf', 'all')
->addPDF('../forms/generated/19.pdf', 'all')
->merge('browser', 'mergedDoc.pdf');
The linked "PDF Merger" simply uses FPDI in the back. FPDI is not able to handle dynamic content as described here.
A pure PHP solution for merging PDF forms is the SetaPDF-Merger component (not free). An evaluation requires the installation of a Loader (Ioncube or Zend Guard). License owners will get access to the source code, so that no external library is needed. The usage is also that easy:
require_once("library/SetaPDF/Autoload.php");
// create a file writer
$writer = new SetaPDF_Core_Writer_Http("mergedDoc.pdf");
// create a new merger instance
$merger = new SetaPDF_Merger();
// add the files
$merger->addFile('../forms/generated/16.pdf');
$merger->addFile('../forms/generated/19.pdf');
// merge all files
$merger->merge();
// get the resulting document and set the writer instance
$document = $merger->getDocument();
$document->setWriter($writer);
// save the file and finish the writer
$document->save()->finish();
How can I convert 2 tiff images to PDF, I already knows how to get the image out of the DB, and I print it using echo and setting up the MIME type.
But, right know I need to use a duplex printer option, so I need a way to generate a PDF from inside my PHP page, that PDF must containt both TIFF images (one per page) How can I do that? What do I need for php to work with that library.
Thank you very much.
EDIT:
Is a self hosted app, I own the server (actually I'm using WAMP 2).
I extract the images from the MySQL DB (stored using LONGBLOBS).
There is a very simple PHP script that interfaces with ImageMagick:
How to convert multipage TIFF to PDF in PHP
I haven't used it myself but it looks all right.
For this you will need
ImageMagick installed
Ghostscript installed
the linked article describes how to install those in a Ubuntu Linux environment.
Another road to take would be inserting the images directly into a auto-generated PDF file without ImageMagick. The best-known PDF generation library, FPDF, can do this, but for JPEG, PNG and GIF only.
Maybe one of these works for you.
What you really need is a library that brings you a PDF composition engine. And of course you need that engine to support image insertions (specifically TIFF).
The best option is iText.
public void createPdf(String filename) throws DocumentException, IOException
{
// step 1
Document document = new Document();
// step 2
PdfWriter.getInstance(document, new FileOutputStream(filename));
// step 3
document.open();
// step 4
document.add(new Paragraph("PDF Title"));
// step 5
document.add(new Image("Tiff image path..."));
// step 6
document.close();
}
Hope it helps!
Using imagick library, below solution worked for me -
$document = new Imagick($path."/".$fileName.tiff);
$data = $document->getImageBlob();
$document->setImageFormat("pdf");
$document->writeImages($path."/".$fileName.pdf, true);
I want to display documents on my website. The server is hosted on a Debian machine. I was thinking I can allow the upload of support documents then use a Linux app or PHP app to convert the doc into PDF and display that in an HTML page. Are there any APIs or binaries that allow me to do this?
If it is an office document, one option would be to use openoffice in headless mode. See here for a python script that shows how: http://www.oooninja.com/2008/02/batch-command-line-file-conversion-with.html
If it is any other kind of document (e.g. your own XML document), then you would need to do a bit more work. I have had some success using XSL to define a translation to docbook format, then using docbook tools to generate the PDF (and various other formats). You could also use XSL to go straight to PDF if you need more precise control over how things look.
You can create a PDF print-to-file printer and send any number of documents to the printer via lpr.
function lpr($STR,$PRN,$TITLE) {
$prn=(isset($PRN) && strlen($PRN))?"$PRN":C_DEFAULTPRN ;
$title=(isset($TITLE))?"$TITLE":"stdin" . rand() ;
$CMDLINE="lpr -P $prn -T $title";
$pipe=popen("$CMDLINE" , 'w');
if (!$pipe) {print "pipe failed."; return ""; }
fwrite($pipe,$STR);
pclose($pipe);
} // lpr()
//open document...
//read into $source
lpr($source, "PDF", $title); //print to device
exit();
Also HTMLDOC can convert your HTML into a PDF.
A relatively new project, called phpLiveDocx can convert DOC to PDF (in addition to a number of other formats). It is a SOAP based service and can be used completely free of charge. For sample code to convert a DOC to PDF using phpLiveDocx, take a look at this recent blog post:
http://www.phplivedocx.org/2009/02/06/convert-doc-to-pdf-in-php/
Of course, as it is SOAP based, it can be used on all operating systems that support PHP :-)
An alternative method is to generate an HTML file that contains what you need in the pdf. Then use htmldoc to convert it to a PDF.
http://www.easysw.com/htmldoc/
It actually is much easier than directly manipulating the objects in a PDF doc.
Pear has a PHP PDF class. See:
http://pear.php.net/package/File_PDF
http://pear.php.net/package/File_PDF/docs/latest/apidoc/File_PDF/File_PDF.html