Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
    
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.) –  Don Kirkham Nov 15 '11 at 15:30

3 Answers 3

up vote 0 down vote accepted

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

share|improve this answer
    
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 –  Don Kirkham Oct 12 '11 at 17:46

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.

share|improve this answer
    
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. –  Don Kirkham Oct 12 '11 at 17:47

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/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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