Convert html page to pdf and email

I have a webpage that I need to add a button to that will open up a print friendly version of the page in PDF and attach it to an email.

I don't want to have to print as pdf and then open the email and attach it. I was hoping there was something out there where the user could push a button and it would convert the page to pdf, open up their email client, and attach the document.

Is it just wishful thinking?
BHUCAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ravi KallaTechnology LeadCommented:
There are two steps -
1. On click of a button, you can hit a server side java code that converts the HTML page to PDF as iText.
2. Open email client and attach PDF document to it -
        a) You can use javascript to read PDF content from backend and open email client and attach it.
        b) Please check this link to open email and attach PDF document to it.
        c) Without opening email client, you can alternatively send the email from the backend itself using javamail API.
0
Ray PaseurCommented:
As a practical matter it's just wishful thinking.  Let me try to explain.

HTML is a semantic markup language which attaches meaning to content.  HTML does not care about layout, just about meaning of the content.  (Two decades ago, there were no really good layout options for web pages, and HTML was "pressed into service."  Today we have CSS for electronic document layout, and nobody uses HTML tables for layout any more.)

in contrast, PDF is a document layout for the printed page.  It does not care at all about the meaning of the content; it just puts the information precisely into the page layout.

Semantic markup and document layout are not quite as different as fish and bicycles, but almost.  If you prepare a document for the web, the process is very different from preparing a document for print.  In PHP we have two free and open source libraries that are popularly used for preparing PDF documents.  They are FPDF and TCPDF.  Download one of them and run with it.  Neither one is "drop-dead easy" but they can both be mastered with a little trial and error, and once you have the document layout completed, both libraries are lightning fast.  To help you get started, here is the FPDF "Hello World" script that shows some of the basics.

<?php // demo/fpdf_hello_world.php
error_reporting(E_ALL);


// DEMONSTRATE SOME OF THE BASICS OF FPDF


// SOME VARIABLES FOR OUR TESTS (COULD COME FROM DATA BASE, ETC)
$font = 'Arial';
$text = 'Hello World!';

// BRING IN THE PDF THING
require_once('fpdf16/fpdf.php');

// SYNTHESIZE THE PDF FILE INFORMATION
$pdf_file_link
= 'throwaway'
. DIRECTORY_SEPARATOR
. 'temp_pdf_blue'
. '.pdf'
;
$pdf_file_name
= getcwd()
. DIRECTORY_SEPARATOR
. $pdf_file_link
;

// DO THE HELLO WORLD EXERCISE IN WHITE ON A BLUE BACKGROUND
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont($font, 'B', 16);
$pdf->SetFillColor(  0,   0, 255);
$pdf->SetTextColor(255, 255, 255);
$pdf->Cell(40, 10, $text, 0, 2, 'L', TRUE);

// WRITE THE PDF TO DISK
$pdf->Output($pdf_file_name, 'F');

// PRESENT A LINK
echo '<a target="my_PDF" href="' . $pdf_file_link . '">Blue PDF</a>';



// START OVER FOR A NEW PDF
unset($pdf);
echo PHP_EOL . "<br/>";

// SYNTHESIZE THE PDF FILE INFORMATION
$pdf_file_link
= 'throwaway'
. DIRECTORY_SEPARATOR
. 'temp_pdf_red'
. '.pdf'
;
$pdf_file_name
= getcwd()
. DIRECTORY_SEPARATOR
. $pdf_file_link
;

// DO THE HELLO WORLD EXERCISE IN BLACK ON A RED BACKGROUND
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont($font, 'B', 24);
$pdf->SetFillColor(255,   0,   0);
$pdf->SetTextColor(  2,   2,   2);
$pdf->Cell(52, 10, $text, 0, 2, 'L', TRUE);

// WRITE THE PDF TO DISK
$pdf->Output($pdf_file_name, 'F');

// PRESENT A LINK
echo '<a target="my_PDF" href="' . $pdf_file_link . '">Red PDF</a>';

Open in new window

HTH, ~Ray
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.