Output to PDF using Adobe FDF and send as an email attachment via ASP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swens2005
    New Member
    • May 2010
    • 3

    Output to PDF using Adobe FDF and send as an email attachment via ASP

    I need to save an ASP generated page as a PDF file to my server and then attach that file to an e-mail and send it.

    My first major issue is that I can't find code anywhere to just create a PDF file (I have the Adobe FDF Toolkit and have registered the DLLs properly) via ASP.

    Any help would be greatly appreciated.

    Thanks!

    Meagan
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    I don't know of any free code, but there are some packages you can buy that do this. I believe there is one called ASPPDF

    Comment

    • swens2005
      New Member
      • May 2010
      • 3

      #3
      Well, my sys admin had installed the Adobe suite of products as well as registering the DLLs from the FDF toolkit on the server. So I was hoping there was some simple code to access the create and save features for the PDF. But after two full days of searching this was the only thing I could find:

      http://www.aspxnet.it/public/default.asp which is in Italian and this site which is in French http://www.aspfr.com/codes/CREER-PDF...ASP_21612.aspx and references the first site. I did get this code to work so whether it needs the FDF DLLs to be registered or not, I can't be sure. But I would recommend using this to anyone that needs to create and save PDFs on the server. I also did figure out how to e-mail them as an attachment. So if anyone needs any of the code, feel free to contact me via PM. Because I know what a pain it was for me to figure this out.

      Thanks!
      Last edited by Niheel; May 19 '10, 03:48 PM. Reason: edited email address to PM

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        Wow Meagan, that would be really useful. If you could jot down everything you did, I would appreciate it, I'd love to have that in our Articles/Insights section.

        Jared

        Comment

        • swens2005
          New Member
          • May 2010
          • 3

          #5
          Sure! Adobe Acrobat 6.0 Standard (that does allow manual PDF creation) was installed on a Windows 2008 R2 Standard Server. Then I downloaded the FDF Toolkit for Windows from here: http://www.adobe.com/devnet/acrobat/fdftoolkit.html. And registered the DLLs (I didn't do this part, but I believe it tells you how to in the documentation). Note for Windows 2008 Server the DLLs need to be in Windows\SysWOW6 4. However, you must enable 32-bit applications in IIS (see here http://forums.iis.net/t/1147571.aspx.) to get these to work. This then did cause a problem with my database connection that had to be changed to a 32-bit compatible connection.

          Next I took the code from this site http://www.aspfr.com/codes/CREER-PDF...ASP_21612.aspx, it will allow you to download the entire zip file, but you must register. I used the google toolbar to translate the page.

          Once I got that I was just about home free. Unzip it and put all the files on the server and you should have some working code. I did have to change things a bit though.

          Here's what you would've seen in the testpdf.asp file without all my extra code:
          Code:
          <!--#include file="fpdf.asp "-->
          <%
             function createpdf(quote_num)
               Set pdf=CreateJsObject("FPDF")
               pdf.CreatePDF()
               pdf.SetPath("pdf/fpdf/")
               pdf.SetFont "Arial", "",10
               pdf.Open()
               pdf.AddPage()
               pdf.SetTextColor 0,0,0
               pdf.Image "http://bytes.com/images/logo.jpg",0,0,200,35,"jpg",""
               Set rs = conn.Execute("SELECT b.site_name, a.quote_nam, a.quote_dsc, a.quote_num, a.quote_amt, a.quote_po FROM qq_quotes a, qq_sites b WHERE a.site_id = b.site_id and a.quote_id = " & id)
                 do while rs.eof = false 
                   qnum = rs("quote_num")
                   pdf.SetFillColor 239,239,239
                   pdf.Cell 190,35, "",0,1,"L"
                   pdf.Cell 190,5, "Information for Quote " & rs("quote_num"),0,1,"C",1
                   pdf.Cell 190,5, "Site: " & rs("site_name"),0,1,"L"
                   pdf.Cell 190,5, "Name: " & rs("quote_nam"),0,1,"L"
                   pdf.Multicell 190,5, "Description: " & rs("quote_dsc"),0,1,"L"
                   pdf.Cell 190,5, "Amount: " & FormatCurrency(rs("quote_amt")),0,1,"L"
                   rs.movenext
                 loop
               set rs = nothing
               pdf.Output ("c:/inetpub/wwwroot/myapp/pdfdir/" + quote_num + ".pdf")
               pdf.Close()
             end function 
          
             function sendnotification(quote_num)
               set rs = conn.execute("SELECT user_email FROM users WHERE user_id = " & session("uid"))
                 do while rs.eof = false
                   to_email = rs("user_email")
                   rs.movenext
                 loop
               rs.close
          
               to_email = to_email 
               subject  = "Subject of Email"
               body     = "Body of Email
               set myMail = createobject("CDO.Message")
                 myMail.subject  = subject
                 myMail.from     = "me@mymail.com"
                 myMail.to       = to_email
                 myMail.htmlbody = body
                 if fct = "snq" or fct = "saq" then
                   myMail.AddAttachment "c:/inetpub/wwwroot/myapp/pdfdir/" + quote_num + ".pdf"
                 end if
                 'myMail.Configuration.Fields.Item (cdoSMTPAuthenticate) = 1
                 'myMail.Configuration.Fields.Item (cdoSendUserName) = "uname"
                 'myMail.Configuration.Fields.Item (cdoSendPassword) = "pwd"
          
                 myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")      = 2 
                 myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")     = "smtpserver"
                 myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
                 myMail.Configuration.Fields.Update
                 myMail.send
               set myMail = nothing
             end function
          
                 createpdf quote_num
                 sendnotification quote_num
          Make sure that the directory you are saving your PDFs to allows full control to all the appropriate users. I didn't test to see which ones I needed to give full control to yet, I just gave everyone full control-- this directory only holds the PDFs though so I don't have a lot of concern about access issues.


          I did also adjust the code in pdf/fpdf.asp for the Output function to be this:
          Code:
          	this.Output=function Output(xfile , xdownload , Overwrite)
          		{
          		if (arguments.length<3) {
          		Overwrite=true;
          			if (arguments.length<2) {
          				xdownload=false;
          				if (arguments.length<1){xfile=""};
          			}
          		}
          		;
          		if(this.state<3)this.Close();
          
          		if(xfile==""){
          
          		}
          			else
          
          				{
          				xf=lib.fopen(xfile,"wb");
          				if(xf.number)this.Error("Unable to create output file: " + xfile);
          				lib.fwrite(xf,this.buffer);
          				lib.fclose(xf);
          				}
          		}
          If you need help in figuring out where to place the PDF cells, I used the manual from this site, http://www.aspxnet.it/public/Default...age=175&idp=19, which was really helpful. (Again, just use the translate option on the Google toolbar.)

          Hope this helps someone else not have to spend hours upon hours trying to find something that works for classic asp.

          Thanks!
          Last edited by Frinavale; May 19 '10, 03:39 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

          Comment

          Working...