• Resolved orahdev

    (@orahdev)


    Hello,
    I’m trying to convert html to pdf in function.php but it’s not working.
    I retrieve the content of an email in html and I would like to attach it in pdf.
    I get the html by doing this: $body = $phpmailer->Body;
    This works well but when I am trying to convert it to php using the given code:$test=wp_objects_pdf($body);.
    This returns me an empty pdf
    Can you help ?

    Best Regards,

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Support Mirza Hamza

    (@hamza1010)

    Hi @orahdev,

    Thanks for contacting us,

    I hope you are doing well, Can you please let me know which PHP version you are using?

    Thanks & Regards

    WP Experts Support Team

    Thread Starter orahdev

    (@orahdev)

    Hello @hamza1010 ,
    Thank you for your response,
    I’m using php version 7.4

    Best regards,

    Plugin Support Mirza Hamza

    (@hamza1010)

    Hi @orahdev,

    Sorry for the delay, we are unable to replicate the issue on our staging site.

    It is possible if you can share the screencast video of this issue?

    Thank you

    Thread Starter orahdev

    (@orahdev)

    Hello @hamza1010 ,

    Thank you for your response !
    In function.php I’m trying to convert the content of my email into pdf.
    I made a function that allows to retrieve the content of the email and put it as an attachment.
    It works correctly however the attachment is therefore in html format.
    When I try to convert it to pdf using your plugin I have an empty pdf.

    Here is my function:

    function add_attachment( $phpmailer )
    if (strpos($phpmailer->Subject, 'New order') !== false) {
      $body = $phpmailer->Body;
    
      $filename = 'email_content_' . time() . '.pdf';
    
      $test=wp_objects_pdf($body);
    
      $phpmailer->AddStringAttachment( $test, $filename, 'base64', 'pdf' );
    
    }
    }
    
    add_action( 'phpmailer_init', 'add_attachment' );

    Best regards,

    • This reply was modified 1 year, 9 months ago by orahdev.
    Plugin Support Mirza Hamza

    (@hamza1010)

    Hi @orahdev,

    Please paste this code in the function.php file.

    Here is the code:

    function add_attachment( $phpmailer ) {
      if (strpos($phpmailer->Subject, 'New order') !== false) {
        $body = $phpmailer->Body;
    
        $filename = 'email_content_' . time() . '.pdf';
    
        $test = wp_objects_pdf($body);
    
        $phpmailer->addStringAttachment($test, $filename, 'base64', 'application/pdf');
      }
    }
    
    add_action('phpmailer_init', 'add_attachment');

    Please check it and let me know if you still have any issues.

    Thank you

    Thread Starter orahdev

    (@orahdev)

    Hello,

    Thank you for your response !
    I tried your code and I still have an empty pdf attached to my mail.
    However if I leave it in html I have content but I need it in pdf.
    Do you have any solution ?


    Best Regards,

    Plugin Support Mirza Hamza

    (@hamza1010)

    Hi @orahdev,

    To escalate your case, please create a ticket on our official website so that we can connect you directly with our Technical team.

    Looking forward to getting your issue resolved.

    Thank you

    Thread Starter orahdev

    (@orahdev)

    Hello @hamza1010 ,

    I went to your official website : https://wpexperts.io/support/
    But when I click on “Open a ticket” there is a list of plugin but “WP PDF Generator?” isn’t in it.
    Am I on the wrong website ?


    Best Regards,

    Plugin Support Mirza Hamza

    (@hamza1010)

    Also, You can contact via email.

    Thread Starter orahdev

    (@orahdev)

    Okay I’m not sure if I did it right but I send a “Pre sale question”.

    Plugin Support Mirza Hamza

    (@hamza1010)

    We have replied to the email. Please follow up there.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Convert html to pdf in function’ is closed to new replies.