Announcement

Collapse
No announcement yet.

PDF template generation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PDF template generation

    Is ir possible to update PDF template generation module to some more friendly and flexible. Issue is that if I enter a HTML code it not generate a document as it tis in HTML. If I create document using "graphical interface", it still generates some different looking doc. I have no ideas how to prepare nice looking PDF dokument as example "certificate". There are some visualisations from my experiments. One is how it's looks like in template and another one what i get in PDF
    Attached Files

  • #2
    Hi, the built in PDF engine (tcpdf) is quite limited in design possibilities. Do not expect too much. You will be able to create simple PDF and with a lot of tweaking you might get close to something, decent, that you could use. For a simple, table based design (designing with tables today normally is a no-go), plan many hours of trying and experimenting.
    I made more than once the experience, that a pre-designed HTML will not be output as you expect. The limited Wysiwyg-Editor is not really Wysiwyg (if you, e.g. have placeholder names, that are long, the layout is nothing more as what it will be in the PDF, so you are lost in the dark). If you work in the code view, the mess gets bigger normally.You have some fonts available, but I recommend, use only Helvetica, for me the others I used, many times already did not work properly.
    I know that nowadays there are much better engines available, but I also recognize, that to change this, will be a lot of work and does not seem to be in the priority list so far.

    Comment


    • partomas
      partomas commented
      Editing a comment
      I'm expecting so minimal layout modification options. alignment Just left / right/ center. Size of table and element modification, some padding no just drag and drop text and images. At Least picture in background would be enough and text on top of it.

  • #3
    left/right/center in table is possible
    Size of table I so far only succeded in working with empty columns, to get whitespace
    Picture in background I never tried, will not be easily to achive.
    There are a few threads about this subject, perhaps this one helps: https://forum.espocrm.com/forum/deve...ss-limitations

    Comment


    • #4
      > there are much better engines available

      Please let me know which ones? We need server side generation (browser-side is a deal breaker), no 3rd party services usage. Pure PHP is also desirable. We can't afford that people will need to install additional software on the server.

      Comment


      • #5
        My mistake, I don`t know about "better engines", that meet the requirements, but I see a lot of API solutions, that can convert HTML or json to PDF.
        What about LibreOffice Server headless? I don`t know enough about the developer`s background, but came across this.

        Or this: https://carbone.io/

        Comment


        • #6
          * Other HTML to PDF solutions are not much better than TCPDF.

          * JSON to PDF would be hard for non-technician people. Another problem: it requires installing additional software on the server that a lot of people won't bother to do.

          * Utilizing 3rd party services is not good option for an open source software I think.

          I would prefer improving the current TCPDF solution somehow.
          Last edited by yuri; 11-21-2020, 11:31 AM.

          Comment


          • #7
            found that from a former post of mine:https://forum.espocrm.com/forum/deve...2457#post62457

            Comment


            • #8
              Being quite unsatisfied with the tcpdf, today I made a lot of experimenting with better output of templates. As already written in another thread, the email editor works better for templating and accepts CSS.
              My approach with the best result:

              1. For test purpose I downloaded an available invoice html-template, made with bootstrap.
              2. The email editor only works with inline css, so I had to merge the css into the html, what helpfully was easily possible by a web-service offered here: https://get.foundation/emails/inliner.html
              I did not use any placeholder in this experiment, but it is possible.
              3. This file I inserted into the email template editor and sent the email to myself.
              4. I printed this email (only the body) to PDF

              The result in the attachment. (it is a screenshot, because the pdf was too big)

              My conclusions:

              - The editor works well with the css and allows all editing.
              - The result is as good, as I would expect.
              - Would it be possible to print directly from the editor`s result, without having to send the email to myself?
              - inserting the HTML into the template editor (for PDF) does not output the desired result due to the limitations of tcpdf.
              Click image for larger version

Name:	testrechnung.jpg
Views:	1103
Size:	64.5 KB
ID:	64873

              Comment


              • partomas
                partomas commented
                Editing a comment
                could you be more specific, you inserted this file as attachment in mail template or used as email template? My goal is to send some "certificate" or invoice in your case as pdf attachment. can you explain this aspect. all before is clare and sounds easy.
                For PDF generation of quotes / invoices and Certificates I use PDF Templates (../#Template) module
                Last edited by partomas; 11-22-2020, 03:10 PM.

              • shalmaxb
                shalmaxb commented
                Editing a comment
                No, it was not an attachment, but I inserted the complete HTML with the inline css into the email template editor and sent the email as HTML to my own account, from where I printed it.

              • partomas
                partomas commented
                Editing a comment
                Thank you for clarification. Yes email template editor might be better, and your suggestion is very useful. I'll use it for newsletters creation. My issue is with PDF document generation.

            • #9
              Always refreshing to see PDF template discussion. I had a look at the TCPDF github issue to see if there any solution or relevant information that other user is experiencing but could not find major discussion on it. I see quite many Pull Request that has not been accepted yet, will accepting these Pull Request improve EspoCRM TCPDF engine in any way?

              The description of TCPDF is stated as "PHP library to generate PDF documents" so I decide to search for that and found these (and my comments)

              http://www.fpdf.org/ - Pure PHP only, latest version is 2019. Forum seem to have form of life, there is no demo page though so can't test.

              https://mpdf.github.io/ - I think this is what YetiForce used as their engine, my (previous) experience with them wasn't so great (PDF-template that is). But it seem to require Composer to install so it doesn't fit in EspoCRM criteria.

              https://github.com/dompdf/dompdf - Not sure here, it sound like it fit EspoCRM but then these requirement making it difficult for me to say yes or no. But looking at the section #requirements section, at least I'm covered for those PHP extension requirement but not sure if these are standard enough for EspoCRM criteria.

              https://github.com/KnpLabs/snappy - This one require Snappy itself and the wkhtmltopdf library. But it look more like in-web browser PDF display/render (similar to Nextcloud PDF renderer?)

              https://github.com/tecnickcom/tc-lib-pdf - TCPDF version (2) - This is still in development though, it aim to replace TCPDF.

              ---

              I remember Emillod replace the engine altogether, I forgot which was used. I think this is also affecting why our editor and TCPDF don't play nice: https://github.com/espocrm/espocrm/issues/1801

              Comment


              • #10
                Hi,
                while playing around the whole weekend with the PDF Editor and the email Editor I am not so sure, if the editor itself is the best choice. I continued to design my templates in pure HTML (with the handlebars/mustache tags of course) and then put the ready HTML into the respective editors. This works as long as you afterwards do not change anything with the WYSYWIG editor. The WYSYWIG inserts aleatoric spans, sometimes p-Tags, if you change the font size it adds the new font size, without eliminationg the former, I experienced sudden closing span-Tags, sometimes empty style-Tags appear. All this breaks the former layout and it is a lot of work to purge the HTML manually. If you used the WYSYWIG editor, you will have to re-edit the whole HTML in a decent editor to get rid of the mistakes, that the WYSYWIG inserts.

                In my searching for other PDF-Libraries I came across the most of those espocrm mentions in his post. I also am astonished about the lack of explanation in most of these engine descriptions. It appears, that PDF generation is some kind of rocket science.

                Comment


                • #11
                  I plan to move the PDF printing logic behind an interface so that it will be easier for developers to implement a support of other HTML-to-PDF engines.
                  Last edited by yuri; 11-23-2020, 09:13 AM.

                  Comment


                  • shalmaxb
                    shalmaxb commented
                    Editing a comment
                    Thank you. I am looking forward.

                  • partomas
                    partomas commented
                    Editing a comment
                    email template generator in the same way. Pease Yuri.

                • #12
                  Thanks Yuri

                  Comment


                  • #13
                    Originally posted by shalmaxb View Post
                    ..It appears, that PDF generation is some kind of rocket science...
                    Hello,
                    i can say with my experiment (since 20years), that "pdf generation" it's a pain "penible in french" since long time.
                    i don't think it's because "opensource" .. tcpdf is if a remenber, a community edition of a commercial society. (or maybe another library).
                    what is difficult i think, it's because HTML is moving forward, CSS is moving forward, wysiwig go forward .. so many library don't follow the speed of progress.. so make a full "best of the best" with pdf, css, html and wysiwig is a "like go to mars" project
                    And more library = more "problem" with compatibility, update,..

                    I can say, PDF in espoCRM is really nice, i am really happy with what Yuri have make and what we can make actually... but if Yuri have put ehancement of pdf in his roadmap .. then we will be very happy
                    Last edited by item; 11-23-2020, 10:11 PM.

                    Comment


                    • #14
                      Found these to check out further:

                      WeasyPrint, The Awesome Document Factory. Transform HTML and CSS into PDF documents.


                      and to test it live:

                      PrintCSS Playground, try different HTML to PDF rendering tools directly in the Browser.

                      Comment


                      • #15
                        Hello,
                        i have try : https://cloudmersive.com/
                        easy to get PDF

                        my result for testing it :
                        i do special : docx as template => espoCrm Jobs => docx => cloudmersive.com convert to PDF

                        - docxTemplate to docx by espo => fast
                        - docx -> pdf by cloudmersive => slow (+- 2secondes by pdf)

                        sometime, cloudmersive crash (response : is valid docx?) .. and it's valide because i loop record .. so why 1 record to docx is valid and another not ?
                        docx template is not a basic template, it's a certificate type ..many block of shape and the result pdf by cloudmersive is correct (same as docx).

                        the same docx in espoCRM result in a blanc pdf.

                        So i can imagine, htlml -> pdf must be more simple and result more perfect


                        Comment

                        Working...
                        X