How to start using old PDF export version in SharpShooter Reports.Silverlight

 How to start using old PDF export version in SharpShooter Reports.Silverlight

Generally, the SharpShooter Reports.Silverlight product is not initially designed to support old PDF export version. In case you would like to have such functionality please follow the steps described below to make it work.

1) Remove previously used PDF export reference from your server side project and add a reference to PerpetuumSoft.Reporting.Export.Pdf[OldVersion] assembly that can be found in \Bin folder of the installed product.

 

 

2) Add a reference to System.ServiceModel.Web assembly

 

3) Add a link to IReportServiceResources interface within WCF service class definition as shown below:

 

public class ReportService : ReportServiceBaseIReportServiceResources

    {

4) Add the following methods to class code:


public new Stream ExportPdf(string id, string pr, string ko, string cr, string iq, string co, string ef, string nlh, string apri, string acom, string acha, string acop, string dop, string cpp, string ri)
        {
            Document doc = GetDocument(id);
            MemoryStream ms = new MemoryStream();
 
            if (doc == null)
            {
                return DocumentOutOfCache(ms);
            }
            PerpetuumSoft.Reporting.Export.Pdf.PdfExportFilter filter = null;
 
            filter = new PerpetuumSoft.Reporting.Export.Pdf.PdfExportFilter();
 
            // These features are not supported by the old pdf export
            //filter.AllowChangingDocument = OneOrZeroToBool(acha);
            //filter.AllowCommenting = OneOrZeroToBool(acom);
            //filter.AllowCopyingContent = OneOrZeroToBool(acop);
            //filter.AllowPrinting = OneOrZeroToBool(apri);
 
            filter.PagesRange = pr;
            filter.KeepOriginalImageResolutionAndQuality = ko == "1";
            filter.ImageResolution = int.Parse(cr);
            filter.ImageQuality = int.Parse(iq);
 
            filter.Compress = co=="1";
            filter.EmbedFonts = ef=="1";
            
            // These features are not supported by the old pdf export
            //filter.SecurityLevel = (nlh.Equals("0")) ? Reporting.Export.Pdf.SecurityLevel.None : (nlh.Equals("1")) ? Reporting.Export.Pdf.SecurityLevel.Low40RC4 : Reporting.Export.Pdf.SecurityLevel.High128RC4;
            //filter.UserPassword = dop;
            //filter.ChangePermissionsPassword = cpp;
            //filter.ReuseImage = OneOrZeroToBool(ri);
 
            filter.Export(doc, ms);
 
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/pdf";
 
            ms.Position = 0;
            return ms;
        }
 
        private static Stream DocumentOutOfCache(MemoryStream ms)
        {
            BinaryWriter sw = new BinaryWriter(ms);
            sw.Write(Encoding.GetEncoding(1251).GetBytes(Language.CurrentLanguage.GetString("Common.Exceptions", "OutOfCache", "The report is out of cache")));
 
            WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
            ms.Position = 0;
            return ms;
        }

5) Please note, the described changes do not affect the client side part. Besides, check the commented code in the method. The old PDF export version does not support some of the features implemented in a new version, that’s why setting these parameters would not affect the export results. Most probably, it would be necessary to hide the unused parameters by overloading the PDF export parameters form style.

 

Add Feedback