Altering a PDF document in PHP - php

Is it possible to convert a PDF document to HTML or text and then edit some text of the html/text file and recreate the PDF, all in a PHP script?

Have a look at http://www.pdflib.com/download/

I have never seen or attempted todo this.
I find it better/cheaper to do the following:
Write the component that will do image intensive processing op a platform like .Net or Java. The application has be be console based and return/print the relevant info (if there was an error in processing etc).
Call the command from you php web application.
Php is a web language and used best for that purpose.

Related

How to run php code inside cordova?

I am new to cordova and want to transfer my existing app build with jquery mobile and php to iOS/Android. Am I correct, that there is no php interpreter inside cordova? That would mean, that the existing app is not transfarable to cordova as php is a central component in building those html files inside the project. This would make it kind of useless for me.
Is there a way to run php code inside cordova?
You cannot use any server-side scripting language (ex: PHP) inside cordova. But using Jquery and AJAX you can call php functions and get data easily.
PHP runs on the server-side; Cordova packages your app into a client-side application.
If you really really want to use your PHP server-generated HTML, rather than static HTML in your client-side app, you can package in an almost empty HTML file, and dynamically fetch HTML from your PHP server, AJAX or otherwise.
In today's age, with AJAX and HTML5 apps, most people will tell you that the server's role should not be to generate HTML files; it should be to generate data (JSON) through APIs. If you switch to such an architecture, you'll find that there are much more tools you can use easily.
Actually, you could use Quercus in Java to feed HTTP parameters to a PHP interpreter, no IP port necessary (you can construct a HTTP-request-holding data object) and for IOS, something like https://github.com/grantjbutler/PHPTest.
There are other embeddable solutions for IOS, I may edit this answer further, in the near future.
Quick search yielded this result: quercus: php in java (open source, 100% java implementation of php) so it should be possible to write plugin that execute your php code, probably with little modification. And then expose it in window.Plugin.method() like other plugins do (like this one cordova-plugin-shell-exec).

Word to xml conversion

Here is my problem: My organization wants to upload word documents from users to the server. On the server side, the word document (enforced with styles) needs to be converted to XML format files. Next, I need to use php to parse the open xml formats files and put the content into the database. Does anyone know how to convert word to XML on server side automatically?Is there any API or sample codes for php to parse Open XML Formats? Your suggestions are appreciated.
Have you looked at using VBA?
I have had to do similar work and I've used VBA within a WSF or VBS file. If you're server is a Windows environment it will run right from the OS. You can execute this from PHP (not recommended) or drop the Docx file into a hot folder outside of the web server environment. I recommend the latter since the web server env. can introduce security issues.
Another note, if you want to separate content from styling, you're going to need to perform some post-processing on the output markup. Word is a "word" processor so styling is what it is designed to do. If this is a requirement, I would suggest moving to a structured, XML-based authoring tool instead.
Hope this helps!

turn web page into an image on the fly?

I was wondering if there was any way of turning an entire HTML page into a png (or other kind of image?) I'm trying to create PDFs on the fly, but it's pulling across my styles as text, but I want the styles to stay the same as the page (cufon and all). Any help would be appreciated! :)
This doesn't look straightforward. The backend (PHP etc.) doesn't do rendering, layout. It merely generates content.
The layout and visual aspects of the website are done by your client (browser) and the backend has no way of accessing this.
However, given an HTML file, there are libraries that can render it into a PDF like Prince XML that seem to be capable of this.
The only way to generate an image identical, or even near, what a visitor sees in their browser when viewing your site is to launch a browser and take a screenshot. You need the browser's rendering engine to render the page. All the libraries you find to do it without a browser create something much different than what the visitor sees, and won't render cufon or other fancy things at all.
Companies that offer screenshot previews of a webpage now run many servers, each running many virtual PCs, each running a full operating system and real web browser. They have all those systems pulling jobs, opening the webpages in real browsers, taking screenshots and saving images. You won't replicate that with a little PHP script.
http://ipinfo.info/html/rendering_services.php
Turning web pages into images and PDFs is a royal pain using PHP. Solutions often require OS level scripting, fake printer drivers, or screen capturing, which can make for a rather fragile setup. I ran into the same issue a few years ago and started working on native PHP extension that leveraged the Gecko engine to render HTML to PDF, but never finished it.
The best answer I've seen doesn't quite turn a full web page into a PDF, but instead does XML to PDF. XEP by RenderX is the commercial tool Apple uses to produce developer documentation in many formats, including HTML and beautifully rendered PDFs, from an XML source. The great thing about using the XEP tool in conjunction with PHP is that PHP deals with XML very well, so you can pass generated XML to the XEP binary, let it do the conversion to PDF, then deal with the resulting PDF file in PHP.
consider building a regular PDF file that resembles your web page:
PHP::PDF - constructing using php.
PDF Reference - file structure.

openoffice document (odt) to PDF with command line on Linux?

we are building a PHP script that we need at work to create reports in PDFs
the reports will be created by using templates from postgrSQL.
so far I found that it can be done with the use of php and odt (openoffice) files [http://www.odtphp.com/] (do you have any other suggestions?)
now how I can convert the results to PDF so teachers will get the final reports as PDF
any tips? the server has no GUI and I want to make it as simple as possible
we tried using PHP to PDF directly with FPDF [http://www.fpdf.org/] but it is really a CPU killer!
http://www.artofsolving.com/opensource/pyodconverter
this may help you, it needs to start OpenOffice as service, and the python script is merely utilizing its api, maybe you can write one in PHP too

C++ Serve PHP documents?

I am writing a small web server, nothing fancy, I basically just want to be able to show some files. I would like to use PHP though, and im wondering if just putting the php code inside of the html will be fine, or if I need to actually use some type of PHP library?
http://www.adp-gmbh.ch/win/misc/webserver.html
I just downloaded that and I am going to use that to work off of. Basically I am writing a serverside game plugin that will allow game server owners to access a web control panel for their server. Some features would be possible with PHP so this is my goal. Any help would be appreciated, thanks!
The PHP won't serve itself. What happens in a web server like Apache is before the PHP is served to the user it is passed through a PHP parser. That PHP parser reads, understands and executes anything between (or even ) tags depending on configuration. The resultant output, usually still HTML, is served by the web server.
There are a number of ways to achieve this. Modules to process PHP have been written by Apache but you do not have to use these. PHP.exe on windows, installed from windows.php.net, will do this for you. Given a PHP file as an argument it will parse the PHP and spit the result back out on the standard output.
So, one option for you is to start PHP.exe from within your web server with a re-directed standard output to your program, and serve the result.
How to create a child process with re-directed IO: http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx however, you won't be writing the child process, that'll be PHP.exe
Caveat: I am not sure from a security / in production use perspective if this is the most secure approach, but it would work.
PHP needs to be processed by the PHP runtime. I'm assuming the case you're talking about is that you have a C++ server answering HTTP queries, and you want to write PHP code out with the HTML when you respond to clients.
I'm not aware of any general-purpose PHP library. The most straightforward solution is probably to use PHP as a CGI program.
Here's a link that might be useful for that: http://osdir.com/ml/php-general/2009-06/msg00473.html
This method is nice because you don't need to write the HTML+PHP out to a file first; you can stream it to PHP.
You need execute the PHP page to serve the page it generates.
The easiest thing for you to do would be to add CGI support to your webserver in some basic form. This is non-trivial, but not too difficult. Basically you need to pass PHP an environment and input, and retrieve the output.
Once you have CGI support you can just use any executable, including PHP, to generate webpages.

Categories