print to PDF & send as E-Mail... by vbscript? - InfoPath Dev
in

InfoPath Dev

print to PDF & send as E-Mail... by vbscript?

Last post 12-06-2007 06:25 AM by mhudsonjr. 15 replies.
Page 1 of 2 (16 items) 1 2 Next >
Sort Posts: Previous Next
  • 09-19-2007 07:01 AM

    print to PDF & send as E-Mail... by vbscript?

    Hello again,

    I was asked to check on possibilities to automate this process:

    1. print out the form as pdf
    2. set up a new email with that pdf attached

    hmwell... and i'm already stuck at point 1... all i have found so far is the XDocument.PrintOut() command, which prints the form on the standard printer without any prompts and without any arguments.
    of course, that doesn't work, even if adobe pdf is the standard printer.

    but i think this should be possible somehow, maybe it needs some kind of pdf-server, but i don't know how to integrate this and where the interfaces between infopath and those applications are.. so, that whole OLE/COM/.NET thing, which i do not know how to use at all.

    soo... any suggestions? .. i don't even know what to google for anymore.

  • 10-17-2007 08:36 AM In reply to

    Re: print to PDF & send as E-Mail... by vbscript?

    Hi, you can print to the file, but then it's hard to actually get that file to attach to an email. For you scenario you will likely need to manually do the email step. The other option is to search for InfoPath PDF automation or such on Google to see if Adobe or someone else has the ability to output InfoPath forms to PDF automaticaly on the server. It may require saving your InfoPath XML to a database, creating a custom XSL to render the output (you can leverage your existing view XSL from InfoPath as a starting point) and then run that server side.

    Shiraz Cupala / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 11-16-2007 04:59 AM In reply to

    • GLazkano
    • Top 200 Contributor
      Female
    • Joined on 07-05-2007
    • Basque Country
    • Posts 54

    Re: print to PDF & send as E-Mail... by vbscript?

     Hi,

    is there a way (maybe code) to automatically print a form to pdf from a button? 

     

    Thanks. 

  • 11-16-2007 10:08 PM In reply to

    Re: print to PDF & send as E-Mail... by vbscript?

    Hi Gorka,

    In order to programmatically print, you have to make the form Full Trust (since print requires level 3 security). That will mean either signing the template using a digital certificate or creating an MSI via regform (which disables autoupdate). Both will incur an IT cost. That's why we don't recommend Full Trust. However, for a small number of "admin" users, it's not necessarily a bad option.

    Selecting the PDF option will require either a PDF printer - I use Cute PDF - or a PDF export tool. Since InfoPath has enabled importers and exporters, someone may have already created an Export to PDF option, but that wouldn't enable printing. You'd have to write code to print as PDF.

    Best regards,

    Patrick 

    Patrick Halstead
    Project Manager at Qdabra
  • 11-19-2007 03:16 AM In reply to

    • GLazkano
    • Top 200 Contributor
      Female
    • Joined on 07-05-2007
    • Basque Country
    • Posts 54

    Re: print to PDF & send as E-Mail... by vbscript?

    Hi Patrick,

    thanks for your reply. I tried Cute PDF and it's a nice solution to print Infopath forms as PDF, I will use it and recommend it.

    But now the question is: is there any 'standard' code to print as PDF programmatically, or will I need to develop my own code?

     

    Thanks. 

  • 11-20-2007 01:02 AM In reply to

    Re: print to PDF & send as E-Mail... by vbscript?

    Hi Gorka,

    Michael Hudson has sent me the following code:

                string FileName = "C:\\Documents and Settings\\mhudson.GCRC\\Desktop\\fax.pdf";

                FAXCOMLib.FaxServer faxServer = new FAXCOMLib.FaxServerClass();
                faxServer.Connect(Environment.MachineName);

                FAXCOMLib.FaxDoc faxDoc = (FAXCOMLib.FaxDoc)faxServer.CreateDocument(FileName);

                faxDoc.RecipientName = cbRefDoc.Text;
                faxDoc.FaxNumber = "123456789";
                faxDoc.DisplayName = "Test Fax";

                //int Response = faxDoc.Send();

                faxServer.Disconnect();

    I assume this prints programmatically but uses the default printer. That was the problem he had. We are investigating a jscript workaround that will allow non-default printers to be selected.

    Cheers!

    Patrick Halstead
    Project Manager at Qdabra
  • 11-20-2007 01:22 AM In reply to

    • GLazkano
    • Top 200 Contributor
      Female
    • Joined on 07-05-2007
    • Basque Country
    • Posts 54

    Re: print to PDF & send as E-Mail... by vbscript?

     Hi Patrick,

    thanks for your help. I'll try it as soon as posible.

    I'll post with the results.

     

    Thanks again! 

  • 11-20-2007 03:18 AM In reply to

    • GLazkano
    • Top 200 Contributor
      Female
    • Joined on 07-05-2007
    • Basque Country
    • Posts 54

    Re: print to PDF & send as E-Mail... by vbscript?

    Hi,

    when I use that code, infopath can't open my form. Can I use that code in VB? Is it necessary any plugin, library or something? 

  • 11-20-2007 07:11 AM In reply to

    • GLazkano
    • Top 200 Contributor
      Female
    • Joined on 07-05-2007
    • Basque Country
    • Posts 54

    Re: print to PDF & send as E-Mail... by vbscript?

     Hi again,

    it worked with this code:

    XDocument.View.Export("C:\\MyView.pdf", "PDF");'

    The only I need now is configure CutePDF as default PDF printer because now the problem is that the Adobe Reader doesn't show it with its size and page breaks.

     I suppose that uninstalling Adobe Reader and installing CutePDF will print it with the CutePDF instead Adobe Reader.

     

    Thanks for your help.

     

    Update: Well, it works perfectly, but once I set the full trust for security, mi 'view bar' (an html taskbar) shows code, is not 'executing' the HTML code, it only shows that code. Am I the only person with that problem?
     

  • 11-20-2007 06:40 PM In reply to

    Re: print to PDF & send as E-Mail... by vbscript?

    Great post on the Export logic!

    Sorry, but I don't quite understand this sentence: "once I set the full trust for security, mi 'view bar' (an html taskbar) shows code, is not 'executing' the HTML code, it only shows that code".

    Can you provide an image and more info on what you expect to happen and what you see happening?

    Thanks!

    Patrick Halstead
    Project Manager at Qdabra
  • 11-21-2007 02:05 AM In reply to

    • GLazkano
    • Top 200 Contributor
      Female
    • Joined on 07-05-2007
    • Basque Country
    • Posts 54

    Re: print to PDF & send as E-Mail... by vbscript?

    Hi,

    it's my fault, my english is bad.

    What I mean is that I have a taskbar in the right of the form. That taskbar, is only shown when the form is open. This is an image of the taskbar working with domain security:

     Form working

    But when I make the form full trust:

     

    Form failing 

     

    Do you understand me now? 

     

  • 11-26-2007 05:51 AM In reply to

    Re: print to PDF & send as E-Mail... by vbscript?

    Can anyone tell me what is wrong with my syntax in this statement.

    XDocument.View.Export("C:\\Progam Files\\FaxDocs\\test.pdf", "PDF"); 

     

    I am trying to export my view as a pdf , but when i run this code it gives an error:

        Infopath cannot export the form.  The system cannot find the path specified. 

     

    I have created a FaxDocs folder to put the pdf in, but for some reason it cannot find the folder.  Thanks for your help. 

  • 11-26-2007 06:28 AM In reply to

    Re: print to PDF & send as E-Mail... by vbscript?

    Due to page breaks and other issues with exporting, I am going to have to use a print to pdf instead of export to pdf.  I have a pdf printer installed, but I do not want the user to have to do anything to get it to print.  Example is that I do not want the users to have to select were they want it to save to or input the filename and hit save.  I want all this to be done in code.  I have seen some things on the web that leads me to believe this can be done by using an ActiveX control.  Does anyone have any information that could lead me to the right place or any examples?  Thanks

     

  • 11-26-2007 06:39 AM In reply to

    • GLazkano
    • Top 200 Contributor
      Female
    • Joined on 07-05-2007
    • Basque Country
    • Posts 54

    Re: print to PDF & send as E-Mail... by vbscript?

    mhudsonjr:

    Can anyone tell me what is wrong with my syntax in this statement.

    XDocument.View.Export("C:\\Progam Files\\FaxDocs\\test.pdf", "PDF"); 

     

    Hi, I think it fails because you type Progam instead Program.

    Check it.
     

  • 11-26-2007 10:42 AM In reply to

    Re: print to PDF & send as E-Mail... by vbscript?

    Thanks, not sure how i overlooked that one. haha.

    But after looking into the print to pdf in code(JScript).  I stumbled upon an activeX control.  Not sure if this is what I am looking for but this is the line.

    var factory = new ActiveXObject("ScriptX.Factory");

    factory.printing.PrintPDF("C:\\test.pdf");

     

    I get an error when it runs that says automation server cannot create object.  My form is fully trusted as well.  Not sure if this is what i am looking for. 
     

Page 1 of 2 (16 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.