4

I have a webpart that is specialized business calculator. Once the user puts in the details of the contract, they need to save the web part (in pdf format) as part of the contract documentation. I have a button on the web part to initiate the request.

Specifically, I’d only want to save the web part contents, with none of the SharePoint chrome. Using a “pdf print driver” is not an option, as I cannot load additional software on the users' computer. Similarly, I don’t think a web service will work either, but am open to it as long as it is transparent to the user. The file will eventually be loaded in a non-SharePoint document repository, so it just needs to be downloaded to the browser, letting the user to save it to a temporary location before uploading it to the document repository.

The web part is a visual web part (farm solution user control) and is used in both MOSS and SP2010.

UPDATE (10/12/2011): I have successfully used iTextSharp to create a Pdf file and send it to the browser. The issue I still have is getting the html from my webpart into the HtmlTextWriter so I can pass the InnerWriter to iTextSharp. It works if I just pass in a single, simple control (like label), but once I try to pass in the full usercontrol, which has many Telerik controls (RadUpdatePanel, RadComboBox, RadTextBox, RadCalendar, etc.), I get the following error: Script control 'RadAjaxLoadingPanel1' is not a registered script control. Script controls must be registered using RegisterScriptControl() before calling RegisterScriptDescriptors().

How do I get a valid string of html that I can pass to iTextSharp?

1
  • UPDATE (11/15/2011): While I appreciate the responses, none of the supplied answer ended up being vaible for my issue. I ended up sending just the webpart to a new window and calling the Print dialog. We installed a Print To PDF driver of the user's machines that did not already have one. (We used BullZip PDF Printer.) Nov 15, 2011 at 15:30

3 Answers 3

1

You can consider two options using an iTextSharp kind of library. First, you can build the PDF from scratch in your code. Add the text literals, build tables, etc. The library has all the objects, methods, and properties to build your PDF content. This may be painful, but worth it in the end. Second, you can create a PDF template in Acrobat, add form fields, and store the file in SiteAssets or some other doc library. Then when you need to generate the file, your code would load the PDF template with form fields from the doc library, set the form field values from your web part input using iTextSharp, remove the fields so they are no longer editable, then write them to the output stream or save the file in a document library.

Alternatively, you can look in to Work Automation as previously mentioned, and I am sure there are third party products that can handle PDF generation.

Lou Estrada

1
  • I'm still holding out hope that I can pass in html from my webpart and get a reasonably formatted pdf file back, but I am having trouble getting the html out fo the webpart right now (see update above). Otherwise, it looks like I am manually building the pdf and loading the values myself. ugh Oct 12, 2011 at 17:46
1

I have had a similar situation in the past and this is how I accomplished it:

1) Create a PDF form (with form fields) of the document. That puts all the standard pieces on the page and you simply fill in the fields.

2) Collect whatever information you need from the user through the web part. (And do any calculations necessary)

3) Use the values you collect to populate the field on your PDF form template.

4) Flatten the PDF

5) Output the PDF to the user

I have written a blog post on how to use iTextSharp with PDF Forms: http://www.sharepointjohn.com/sharepoint-2010-fill-out-and-flatten-pdf-forms-with-itextsharp/

0

There is an article on MSDN that might prove useful, using Word Automation Services. My thinking is that perhaps using Office web apps to create the Word Document then generate the PDF that way.

It will at least show you one approach.

1
  • Your solution intrigues me, but the webpart currently runs in MOSS. We are starting a migration project, but this can't wait until I get to SP2010. Oct 12, 2011 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.