public stDoc ToRasterFormatExParameters(stDoc Doc, string ext, string label, stParameter[] parameters)
        {
            try
            {
                logger.DebugFormat("ToRasterFormatExParameters - INIT - {0} - ext: {1}, label: {2}", HttpContext.Current.Request.UserHostAddress, ext, label);

                AttachConversionMode mode = AttachConversionMode.Default;
                if (parameters != null && parameters.Length > 0 &&
                    parameters.Any(x => x.Name == stParameterOption.AttachMode))
                {
                    stParameter foundParameter = parameters.First(x => x.Name == stParameterOption.AttachMode);
                    if (int.TryParse(foundParameter.Value, out int val))
                    {
                        mode = (AttachConversionMode)val;
                    }
                }

                byte[] documentContent    = Convert.FromBase64String(Doc.Blob);
                byte[] pdfDocumentContent = PrintRedirectedService.ConvertToFormatLabeled(documentContent, Doc.FileExtension, ext, label, mode);
                return(new stDoc
                {
                    Blob = Convert.ToBase64String(pdfDocumentContent),
                    FileExtension = ext
                });
            }
            catch (Exception exception)
            {
                logger.Error(exception);
                throw;
            }
            finally
            {
                logger.DebugFormat("ToRasterFormatExParameters - END - {0}", HttpContext.Current.Request.UserHostAddress);
            }
        }
        public void UploadSecureDocument(stDoc document)
        {
            try
            {
                logger.InfoFormat("UploadSecureDocument - INIT - {0}", HttpContext.Current.Request.UserHostAddress);
                if (_secureDocumentService == null)
                {
                    logger.Warn("UploadSecureDocument - SecureDocumentService not initialize. Please check application configuration settings.");
                    throw new Exception("Servizio di securizzazione non abilitato. Verificare le impostazioni del sistema.");
                }

                SecureDocumentModel request = new SecureDocumentModel()
                {
                    DocumentContent = Convert.FromBase64String(document.Blob),
                    IdDocument      = document.ReferenceId
                };
                logger.DebugFormat("UploadSecureDocument - Call upload secure document for iddocument {0}", document.ReferenceId);
                _secureDocumentService.Upload(request);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw ex;
            }
            finally
            {
                logger.InfoFormat("UploadSecureDocument - END - {0}", HttpContext.Current.Request.UserHostAddress);
            }
        }
 public stDoc ToRasterFormatEx(stDoc Doc, string ext, string label)
 {
     try
     {
         logger.DebugFormat("ToRasterFormatEx - INIT - {0}, {1}, {2}", HttpContext.Current.Request.UserHostAddress, ext, label);
         return(ToRasterFormatExParameters(Doc, ext, label, null));
     }
     catch (Exception exception)
     {
         logger.Error(exception);
         throw;
     }
     finally
     {
         logger.DebugFormat("ToRasterFormatEx - END - {0}", HttpContext.Current.Request.UserHostAddress);
     }
 }
 public int GetNumberOfPages(stDoc document, string fileName)
 {
     try
     {
         logger.InfoFormat("GetNumberOfPages - INIT - {0}", HttpContext.Current.Request.UserHostAddress);
         byte[] documentContent = Convert.FromBase64String(document.Blob);
         return(PrintRedirectedService.GetNumberOfPages(documentContent, fileName));
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         throw ex;
     }
     finally
     {
         logger.InfoFormat("GetNumberOfPages - END - {0}", HttpContext.Current.Request.UserHostAddress);
     }
 }
        public stDoc ToRasterFormatRgWatermarked(stDoc Doc, string ext, string label, string watermark, string user, string password,
                                                 int AllowPrinting, int AllowModifyContents,
                                                 int AllowCopy, int AllowModifyAnnotations,
                                                 int AllowFillIn, int AllowScreenReaders,
                                                 int AllowAssembly, int AllowDegradedPrinting)
        {
            try
            {
                logger.DebugFormat("ToRasterForToRasterFormatRgWatermarkedmatRg - INIT - {0}", HttpContext.Current.Request.UserHostAddress);

                stDoc res = new stDoc()
                {
                    FileExtension = "PDF"
                };
                byte[] documentContent                    = Convert.FromBase64String(Doc.Blob);
                byte[] pdfDocumentContent                 = PrintRedirectedService.ConvertToFormatLabeled(documentContent, Doc.FileExtension, "PDF", label);
                byte[] watermarkedDocumentContent         = PrintRedirectedService.EtichettaWatermark(pdfDocumentContent, watermark);
                ConversionSecureParameter secureParameter = new ConversionSecureParameter
                {
                    User                   = user,
                    Password               = password,
                    AllowPrinting          = Convert.ToBoolean(AllowPrinting),
                    AllowModifyContents    = Convert.ToBoolean(AllowModifyContents),
                    AllowCopy              = Convert.ToBoolean(AllowCopy),
                    AllowModifyAnnotations = Convert.ToBoolean(AllowModifyAnnotations),
                    AllowFillIn            = Convert.ToBoolean(AllowFillIn),
                    AllowScreenReaders     = Convert.ToBoolean(AllowScreenReaders),
                    AllowAssembly          = Convert.ToBoolean(AllowAssembly),
                    AllowDegradedPrinting  = Convert.ToBoolean(AllowDegradedPrinting)
                };
                byte[] lockedDocumentContent = PdfLabelerService.RightPdf(watermarkedDocumentContent, secureParameter);
                res.Blob = Convert.ToBase64String(lockedDocumentContent);
                return(res);
            }
            catch (Exception exception)
            {
                logger.Error(exception);
                throw;
            }
            finally
            {
                logger.DebugFormat("ToRasterForToRasterFormatRgWatermarkedmatRg - END -{0}", HttpContext.Current.Request.UserHostAddress);
            }
        }
 public stDoc ToRasterXmlWithStylesheet(stDoc toConvertDocument, byte[] xsl, string label)
 {
     try
     {
         logger.InfoFormat("ToRasterXmlWithStylesheet - INIT - {0}", HttpContext.Current.Request.UserHostAddress);
         byte[] documentContent          = Convert.FromBase64String(toConvertDocument.Blob);
         byte[] convertedDocumentContent = PrintRedirectedService.ConvertXmlToPdfWithStylesheet(documentContent, xsl, toConvertDocument.FileExtension, label);
         return(new stDoc
         {
             Blob = Convert.ToBase64String(convertedDocumentContent)
         });
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         throw ex;
     }
     finally
     {
         logger.InfoFormat("ToRasterXmlWithStylesheet - END - {0}", HttpContext.Current.Request.UserHostAddress);
     }
 }
 public stDoc PdfToPngThumbnail(stDoc Doc)
 {
     try
     {
         logger.DebugFormat("ToRasterFormatWatermarked - INIT - {0}", HttpContext.Current.Request.UserHostAddress);
         byte[] documentContent  = Convert.FromBase64String(Doc.Blob);
         byte[] thumbnailContent = PrintRedirectedService.ConvertPdfToThumbnailPng(documentContent);
         return(new stDoc
         {
             Blob = Convert.ToBase64String(thumbnailContent)
         });
     }
     catch (Exception exception)
     {
         logger.Error(exception);
         throw;
     }
     finally
     {
         logger.DebugFormat("ToRasterFormatWatermarked - END - {0}", HttpContext.Current.Request.UserHostAddress);
     }
 }
 public stDoc ToRasterFormatExBox(stDoc Doc, string ext, string label, BoxConfig boxConfig)
 {
     try
     {
         logger.DebugFormat("ToRasterFormatExBox - INIT - {0}", HttpContext.Current.Request.UserHostAddress);
         byte[] documentContent    = Convert.FromBase64String(Doc.Blob);
         byte[] pdfDocumentContent = PrintRedirectedService.ConvertToFormatLabeledWithForm(documentContent, Doc.FileExtension, ext, label, boxConfig);
         return(new stDoc
         {
             Blob = Convert.ToBase64String(pdfDocumentContent),
             FileExtension = ext
         });
     }
     catch (Exception exception)
     {
         logger.Error(exception);
         throw;
     }
     finally
     {
         logger.DebugFormat("ToRasterFormatEx - END - {0}", HttpContext.Current.Request.UserHostAddress);
     }
 }
        public stDoc CreateSecureDocument(stDoc document, string filename, string label)
        {
            try
            {
                logger.InfoFormat("CreateSecureDocument - INIT - {0}", HttpContext.Current.Request.UserHostAddress);
                if (_secureDocumentService == null)
                {
                    logger.Warn("CreateSecureDocument - SecureDocumentService not initialize. Please check application configuration settings.");
                    throw new Exception("Servizio di securizzazione non abilitato. Verificare le impostazioni del sistema.");
                }

                filename = Path.GetFileName(filename);
                logger.DebugFormat("CreateSecureDocument - Convert document {0} to PDF", filename);
                stDoc pdfDocument           = ToRasterFormatEx(document, Path.GetExtension(filename), label);
                SecureDocumentModel request = new SecureDocumentModel()
                {
                    DocumentContent = Convert.FromBase64String(pdfDocument.Blob),
                    DocumentName    = string.Concat(Path.GetFileName(filename), ".pdf")
                };
                logger.DebugFormat("CreateSecureDocument - Call create secure document for document {0}", filename);
                SecureDocumentModel response = _secureDocumentService.Create(request);
                return(new stDoc()
                {
                    Blob = Convert.ToBase64String(response.DocumentContent),
                    ReferenceId = response.IdDocument
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw ex;
            }
            finally
            {
                logger.InfoFormat("CreateSecureDocument - END - {0}", HttpContext.Current.Request.UserHostAddress);
            }
        }
 public stDoc ToRasterFormatWatermarked(stDoc Doc, string label, string watermark)
 {
     try
     {
         logger.DebugFormat("ToRasterFormatWatermarked - INIT - {0}, {1}, {2}", HttpContext.Current.Request.UserHostAddress, label, watermark);
         byte[] documentContent            = Convert.FromBase64String(Doc.Blob);
         byte[] pdfDocumentContent         = PrintRedirectedService.ConvertToFormatLabeled(documentContent, Doc.FileExtension, "PDF", label);
         byte[] watermarkedDocumentContent = PrintRedirectedService.EtichettaWatermark(pdfDocumentContent, watermark);
         return(new stDoc
         {
             Blob = Convert.ToBase64String(watermarkedDocumentContent),
             FileExtension = "PDF"
         });
     }
     catch (Exception exception)
     {
         logger.Error(exception);
         throw;
     }
     finally
     {
         logger.DebugFormat("ToRasterFormatWatermarked - END - {0}", HttpContext.Current.Request.UserHostAddress);
     }
 }