This article was created in response to a support issue logged with K2. The content may include typographical errors and may be revised at any time without notice This article is not considered official documentation for K2 software and is provided "as is" with no warranties.
After an upgrade from 4.7 to 5.1, when you are attempting to run the Save As PDF control's Save As PDF or Save as PDF Async method on a SmartForm, you will get the error below and the PDF is not created:
The PDF could not be saved.
Key could not be found in the collection.
at SourceCode.Forms.Controls.Web.SaveAsPDFRequest.ExecuteSaveAsPDFMethod(SaveAsPDFRequest request)
at SourceCode.Forms.Controls.Web.SaveAsPDFHandler.ProcessRequest(HttpContext context)
- This same form design worked before the upgrade on K2 Blackpearl 4.7.
- All forms/views with the Save as PDF control will exhibit this behavior. Creating a new form/view does not show any different behavior.
- Running the PDFConverter SmartObject outside of a form/view (i.e. in the SmartObject Tester Tool or K2 Management Site) will properly create a PDF.
- You will note that the PDF Converter SmartObject's Properties do not match that of the Service Object:
This behavior is due to the fact that the SmartObject backing the SaveAsPDF Control was not properly refreshed during the upgrade process to K2 Five. This SmartObject is named PDFConverter. In K2 Five we added 4 new properties to this SmartObject for Left Margin, Right Margin, Top Margin, Bottom Margin.
Steps to Resolve:
1. Open the SmartObject Tester tool ("C:\Program Files (x86)\K2 blackpearl\Bin\SmartObject Service Tester.exe")
2. Expand ServiceObject Explorer > PDF Converter Service instance > PDF Converter Service Object. Right-click on the Service Object and select create SmartObject.
3. On this window, click the Get Existing GUID button. The GUID should be:
4. In the Category box, add the path to the PDFConverter SmartObject which is:
System\Controls\Save as PDF
5. Click Publish SmartObject. Click yes to overwriting the SmartObject.
6. Go to the SmartObject and confirm that the SmartObject now shows the 4 Margin Properties (Left, Right, Top, Bottom) on the properties and methods.
7. Test the form behavior by saving a PDF. The error should now be gone and the PDF will be created as expected.