I have read lots of questions and answers here but I haven't found a clear Question/Answer.
I need to create a really simple webpage which allows users to enter LaTeX and generate a PNG (or other lightweight image format). The webpage contains only a textarea and a submit button and it produces a link like "http://www.example.com/generated-images/cnl344l4jcxlj.png" with the image.
INPUT: already-written latex like
f(x)=\displaystyle\int_{-\infty}^x e^{-t^2}dt
OUTPUT: Link to the generated PNG or GIF image
The processing of the latex code and the generation of the image should happen in the server-side (so no JavaScript)
I'd like to do this in PHP (which I'm pretty good at), but if there are simple-enough libraries I could give it a shot in Perl.
A straightforward implementation in pure C could also work. A program which scanfs the input latex code and printfs "image generated at c:/program/image00000000001.gif"
Any free/opensource libraries that do any of this? Any advice in how to proceed? Any special concerns?
http://rinconmatematico.com/latexrender/pictures/35800007a15a3f0e39006dc63f04f1b5.gif
Try:
TeX2PNG - generate png image for given equation
MathJax - JavaScript library that find and render math equations in HTML
KaTeX - lighter and a little bit less capable alternative to MathJax
Look at dvipng. I wouldn't write a wrapper over it in C but in a scripting language.
If it's not a high-traffic website, you can try online rendering with sites like the Online LaTeX Equation Editor. In particular, this site allows you to put LaTaX directly into the URL like the following:
The URL being: http://latex.codecogs.com/gif.latex?\sum_k%20a_k
Related
I'm just wondering about a small problem I have. I'm creating a simple website with PHP, HTML and CSS. The user enters the dimensions of a rectangle into a form, and this all works perfectly. However, I'm unsure how to proceed.
The system should then use these dimensions (both stored as separate variables) to draw a rectangle of that size (in cm). The rectangle should be draw in a .pdf document, which the user can then download.
I'm a beginner, so sorry if there's anything wrong with this question.
You're going to want to start with looking into the html5 canvas element for drawing. There's plenty of tutorials online for you. As far as saving to pdf, see this: Convert canvas to PDF good luck.
Take a look at the fpdf extension available for php. Or even better and more consequent: use its unicode capable variant 'tfpdf'.
It allows you to generate a pdf document on the server side in a step by step way. You can control all details of that document. When finished you can return the document to the requesting client.
I'm looking for a solution / API (i.e. like PDFLib) that can extract (and remove) a drawn path from a graphic PDF. For example a path that outlines a picture or logo that was drawn in Illustrator or Indesign (not JPG clipping path), that is set to a specific spot color (ie "CutContour"). I need to get the data that makes up that path to extract for use in a cutting system.
While PDFLib can extract text, it cannot extract graphic elements. I'm even open to solutions outside of PHP!
Thanks in advance!
I wasn't able to find any php pdf parsers, but...
If you aren't opposed to using an alternate language, I found a ruby gem that will parse a pdf file. From the docs it looks like you're able to grab a hash of the objects of a file.
http://rubygems.org/gems/pdf-reader
If you're looking for a pure programmatic solution that might work, but seems like it would be difficult.
Otherwise, I know that you can open up pdf files in Adobe Illustrator and extract graphics that way. You might even be able to write some javascripts that will automate the process. This solution obviously won't work on linux though.
I want to generate PDF from a PHP file that includes HTML controls like textbox, and textarea. I attached CSS in the same. I tried FPDF, DOMPDF and TCPDF, but still I don't get exactly what I want. How do I pass HTML controls with PHP variables and CSS to these libraries?
mpdf is another option that you could try.
EDIT :
Found another solution for it, TCPDF is a FLOSS PHP class for generating PDF documents. Looks more dominating library.
"PRINCEXML" is a good library (not completely free now).
Others:
If your meaning is to create a PDF file from PHP, pdflib will help you (as some other suggested).
Else, if you want to convert an HTML page in PDF via PHP, you'll find
a little trouble outta here.. For three years I have been trying to do it as best as I
can.
So, the options I know are:
HTML2PS: same of DOMPDF, but this one convert first in .ps
(Ghostscript), then, in whatever format you need (PDF, JPEG, PNG). For
me it is a little better than dompdf, but I have the same speed problem.. Oh,
it has better compatibility with CSS.
Those two are PHP classes, but if you can install some software on the
server, and access it through passthru() or system(), have a look at
these too:
wkhtmltopdf: based on webkit (safari's wrapper), is really fast and
powerful... It seem like it is the best one (atm) for converting HTML pages to PDF on the fly, taking only two seconds for a three pages XHTML document
with CSS 2. It is a recent project. Anyway, the Google Code page is often
updated.
htmldoc: this one is a tank, it really never stops orcrashes... The project
seems to have died in 2007, but anyway if you don't need CSS compatibility
this can be nice for you.
** Thumbs Up For Strae.
If I understand your needs correctly I don't think any PHP-PDF class would do that.
Mostly you could insert only text and images to a PDF file, so if you would want something that looks like an HTML element you would need to insert it as an image.
Usually just putting HTML doesn't mean all your elements would stay intact in the PDF . (Different world, after all)
http://www.fpdf.org/ is the site having a great HTML-to-PDF class which work well. I am using it, but you have to first study its functionality and then start.
I'm developing an app where the user adds items to a list. That list is stored in an array and passed to PHP with JSON.
The objective is to then create a PDF with all the values extracted from the user. The PDF is quite complicated. It includes images depending on what the user selects and the text varies depending on the images and the input data.
The first idea was to generate the pdf in php with one of those pdf libraries, but that's going to be a real hassle.
Then I thought of creating an html & css (much easier) and the convert it to PDF. But since the html & css are quite complex I don't think those pdf converters will work with this.
Then I thought I could convert the html to jpg and then to pdf.
It'll be much simpler if I could just use html but the output needs to be pdf.
What do you suggest?
Here's a post that discusses creating PDF files with PHP and the PDFLib extension.
Generate PDFs with PHP it's on sitepoint.
Or if you want to go from HTML to the PDF it looks like TCPDF might work.
You can try using FPDF
Then I thought of creating an html & css (much easier) and the convert it to PDF. But since the html & css are quite complex I don't think those pdf converters will work with this.
wkhtmltopdf to the rescue! If you are on a VPS or dedicated machine, it's probably the best (open source) HTML-to-PDF engine out there. It leverages Webkit, the rendering engine used by Google Chrome and Apple Safari, amongst others.
Otherwise, your only other options are going to involve drawing every aspect of the PDF or image yourself, "by hand" in your code.
Could you please tell me how to extract content from PDF document using PHP? Formatting is the main problem im facing here. So let me know, if there are some ways to extract content with the same format and to display it on an online text editor.
Thanks
Have a look at XPDF
I suppose you could do
$text = shell_exec("pdftotext $pdffile");
As for displaying it in an editor? Well, which editor?
To retain some type of formatting information, and assuming by web editor you mean HTML editor, you can convert it to HTML. Perhaps there are other tools available, but since i use xpdf i came across this converter that is based on xpdf.
Basic usage
pdftohtml -noframes -c test.pdf test.html
To get it into your favorite editor
echo file_get_contents('test.html');
You may need to wrap things inside PHP functions/classes. And you may want to add security measures and whatnot.
As far as I can see, it is not possible to convert a PDF to editable HTML using PHP on the fly, while preserving formatting. There are a number of Desktop apps around that all try to extract data from PDFs with sometimes more, sometimes less reliable results. I would say this is not realistically possible at the moment and all you can do is to extract plain text using XPDF or other command line tools.
It may be different with that new XML-Based PDF format but I don't really know anything about that yet.
Feel free to prove me wrong, of course - I'd be very interested myself if there were a solution.