Convert InfoPath form to PDF programmatically

S

serious-sam

Hello,

I'm looking for a way to convert an InfoPath form to PDF
programmatically. I can see there is an export to to PDF feature in
InfoPath. Is this exposed in any way to the outside world?

I know I could use a third-party XML to PDF converter, but I would like
the output to be the same as the original InfoPath form (with minimum
effort :))

Cheers and regards,
Misha
 
S

S.Y.M. Wong-A-Ton

Switch to InfoPath 2007; you can use it to call the export to PDF
functionality in code and convert your form to PDF.
 
S

serious-sam

Hello,

Thank you for your advice. I've created a sample Windows application
that performs the conversion, using the object model you have guided me
to.

The source, for anyone who is interested, goes along these lines:

private void btnConvert_Click(object sender, EventArgs e)
{
try
{
formControl1.XmlForm.CurrentView.Export(s_filenameOut,
ExportFormat.Pdf);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex);
}
}

private void btnOpen_Click(object sender, EventArgs e)
{
try
{
formControl1.Open(s_filenameIn);
formControl1.XmlForm.CurrentView.ForceUpdate();
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex);
}
}

Fairly simple and convenient. This is in a Windows application. I
have a question:

Is it possible to do this from the command line? All the articles I've
come across relate to the Microsoft.Office.InfoPath.FormControl object,
which is a Windows form component. I'm unable to use it from a command
line application. Is there a way I could do this?


Thank you for your help.

Cheers and regards,
Misha
 
S

S.Y.M. Wong-A-Ton

I haven't tried it before, so I wouldn't know. Regarding articles: Remember
that InfoPath 2007 is still in beta, so it is early to expect to see many
articles on the product.
 
R

RickH

Anything you can run as a batch you can run as a Windows program, and
gain flexibility...

Unfortunately, I have to use Infopath 2003 to convert a bunch of
Infopath Report views into a PDF or Word document.
Right now, I export from Infopath to a MHT file. Then I open it in IE
and use Acrobat to convert to PDF.
Takes forever to combine about 30 Infopath views to one large PDF file.
And I have several EOY reports like this to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top