Open MOuli90 opened 10 years ago
hi. I just didnt write support for it. tjats the only reason. what you could do is either port the code to the lib, or use as is and import the pdf result as an image to the pdf created by hummus.
where would be the starting point to make a pr for png support? that would be really great for autographs
Before you go into that then by FAR the simplest solution is to find an existing module that creates PDFs from PNGs and embedding the PDF. Seriously, the alternative of building it yourself is significantly more time consuming and involved. imagemagick can probably help here.
If you do decide to do this internal to Hummus, Best would be to do this in the C++ code where you can surely access all the relevant hooks in hummus to create the objects you need. plus this way it's accessible to everyone. Still if you prefer to focus on javascript and missing some necessary hooks that are available on PDFWriter, let me know and we'll figure out how to open them up.
In any case, since hummusJS is mostly a wrapper around the C++ library, the best way to learn on how to add images types to hummus is to look into its implementation of AbstractContentContext::DrawImage and do the JS equivalent. follow the track of how jpg images are drawn because it's the simplest.
This will get you the details on how to add an image type in general.
You will need to know 2 more things:
To do 1, the best is to look for an existing implementation. someone that already converts png to pdf, and use the pdfwriter/hummusjs library to do the equivalent PDF stuff. Reading png will probably take libpng. if you cant find anything then it will take reading into libpng, figuring out how to get the color samples and creating the image object by yourself. yummy. in this case better read on how to create images objects (section 4.8) in the PDF specs . Following the JPG image creation trail in hummus will show you a simple example on how to implement images objects in PDF.
In case while reading 1 you didn't stumble upon a solution on how to carry transparency information, and you want transparency (in my tiff solution i got lazy and didn't), then you'll have to learn how to:
If you manage to do this, you will have my deep admiration and thanks. it is defo possible, and i done such things myself. it's just that it's not super trivial and will take time. I would clear something like 2 weeks for this and hope to get lucky and finish sooner.
wow that sounds super challenging, all i really need is to add an image with mayority alpha 1 pixels (no interims), like an autograph, without putting white background above the existing pdf, sounds easier to read the pdf at the position were the image will be inserted and snapshot a background of that area and use it as the background of the jpg autograph 🍭
thank you very much for your help and describing where to take the first steps, appreciate it lots
Folks. if anyone's looking to solve this. what's commonly done is to turn the PNG into a PDF using something like PDFKit, and then you can import it to hummus like an image.
NM Simple image drawing from the wiki works for PNGs.
~I noticed this section about PNG images, but trying it doesn't seem to work. Did it work in the past or perhaps it's just optimistic wikiing? 😄~
~Also this issue seems to suggest some support for PNGs…~
Why does HummusJS (PDF-Writer) not support images in the png format?
Is it possiable to copy the code of the ZF1 into this Project?
https://raw.githubusercontent.com/zendframework/zf1/master/library/Zend/Pdf/Resource/Image/Png.php