I'm using tcpdf to generate a pdf file, and have to conditionally convert coloured SVG files to grayscale.
But i'm not able to find any useful libraries to do that.
Is it even possible?
PS! I dont have imagemagick
Related
I'm struggling with generating high-quality images for printing - mainly because there is really poor support for CMYK colors in PHP libraries and Linux CLI tools.
The situation is as follows. I have input materials in tiff format and CMYK colors - it is the background. I need to add some text to it and save as tiff with CMYK colors. The challenge is to use exact CMYK colors (so no temporary export/import to sRGB during the process is possible).
My first thought was to use Imagemagick but Imageimagick has no option to draw in CMYK. I need to work in sRGB and export material to CMYK. So some information about colors are changed during the process.
It seems this is not possible with PHP to add text to image without temporarily converting colors to sRGB, so I'm looking for any option like Linux CLI tool, node.js lib, etc. The goal is to at least generate text as an image with a transparent background and with colors defined in CMYK with exact values or do the same directly on the background image.
Finally, I gave up with Imagemagick. As we can use PDF for professional printing I decided to go this way.
I installed TCPDF and TCPDI. With TCPDI I imported previously prepared pdf template with graphics etc. Using TCPDF I added necessary dynamic text - TCPDF support CMYK with no issues.
Depending on where you print you can embed fonts to PDF (it can be done with TCPDF) or change texts to outlines which is a small challenge. I needed to change fonts to outlines (client request) so I did it with Ghostscript.
It took me a whole day to figure it out, so I post it in case somebody will have a similar problem. Definitely not an answer to the question, but at least a good solution for the problem itself.
Ive a script to generate an image using imagemagick in PHP, after designing i need to create a pdf to print and this pdf need to be like a vector one, even if we zoom in the content should be crisp, but my pdf is not so, can some one guide me how to achieve this?
Do i need to convert my final png as svg? or is it possible to make pdf with PNG as vector?
My current application requires me to convert a document (doc, excel, ppt, image, etc) to PDF. It also requires to add a front page with several information (variable) and add footer to converted document. It may also require to add a text or a logo image as an watermark.
I have been able to convert document to PDF using LibreOffice. I generated a static pdf and I could merge it with converted document using PDFtk
But I need to generate front page dynamically because for each document, some information will change. I thought of using FPDF to generate front page, convert with libreoffice and merge it using PDFtk. But again, it will require adding footer and possibly a watermark. I think watermark can be done by PDFtk. And footer can be generated by FPDF.
So whole process will look like this:
Created Front page with FPDF and save pdf
Convert Doc to PDF with LibreOffice
Add footer to converted PDF and store with FPDF
Generate PDF with watermark using FPDF (possibly)
Combine above three pdf using PDFtk
I guess I am doing too much of processing. Is there a simpler way to achieve this? Are there any alternatives to achieve this with lesser resources / third party apps/lib ?
If you're open to commercially licenced software, PDFLib+PDI will handle all the tasks you require (after conversion to PDF). It runs natively on most server environments with generally very good performance.
The Library I have used to handle PDFs with PHP is TCPDF. It's open source, you can use HTML to style the PDF (a subset of HTML anyway), handle things like pages. I believe you should be able to perform the functions you require all in TCPDF.
To handle manipulations to images, which you may need for watermarking etc, I used GD which provides numerous functions for manipulating images. If you require some more complex image manipulations, you may also want to look at imagemagick.
All of this should simplify your workflow, and allow you to do most of what you require directly in PHP and HTML.
To decrease the number of different things that I need to do, I will simply use the FPDI library.
So what I am going to now is,
Convert the document into PDF format
Create Front Page using FPDI (which extends TCPDF and uses it's function)
Then I will import the converted document using FPDI ' s import feature
I will also add watermark and footer same time
So I will ultimately eliminate the use of PDFtk and reduce the number of libraries used and different activities required to be done separately.
These thing will be done in two activities only :
Convert to PDF with LibreOffice and
Add a front page, import and add footer and watermark with FPDI
I haven't tested it yet, but DomPDF looks like a nice project.
I was using HTML2PDF before, but it's not updated anymore so moving on.
If you're using such libraries, just make HTML templates (moreover, DomPDF supports PHP execution inside html templates) and have fun ;)
I am going to create some images with text using PHP script and want to simplify the process.
Are there any classes/libraries/wrappers for GD and ImageMagick that can help me with this? For example, add some effects, custom fonts, etc.?
This will help you : http://php.net/manual/en/book.image.php
imageloadfont function can be used to load new fonts refer : http://www.php.net/manual/en/function.imageloadfont.php
You could look into using SVG for this. Text items and effects such as blur can be added very easily with simple XML manipulation, and then you could render it with inkscape - in PNG or PDF format.
In PHP, it's quite easy to use GD to draw text onto a raster canvas in a certain font (according to a TTF file held on the server), and output it as a PNG or JPEG.
I want to do roughly the same thing, but to draw the text as a vector outline and output it as an SVG.
(I do not want to embed the font itself in the resulting SVG, as the font is not licensed for that.)
Is there any PHP library that provides this sort of functionality?
It's possible to script inkscape to do this.
The following command opens "example.svg" and selects all shapes in the file and converts them to paths, and then saves and closes the file.
inkscape --verb EditSelectAll --verb ObjectToPath --verb FileSave --verb FileClose example.svg
I was able to find CleverSVG trough searching, however I did not try this myself, and I am unsure if it will be able to draw text without forwarding the font.