/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public override DocsPaVO.Modelli.ModelResponse ProcessModel(DocsPaVO.Modelli.ModelRequest request) { DocsPaVO.Modelli.ModelResponse modelResponse = new DocsPaVO.Modelli.ModelResponse(); try { modelResponse.DocumentId = request.DocumentId; // Reperimento del motore word processor installato sul client per l'elaborazione del modello modelResponse.ProcessorInfo = ModelliManager.GetCurrentModelProcessor(request.UserInfo); if (modelResponse.ProcessorInfo == null) { throw new ApplicationException("In amministrazione non risulta impostato alcun software per generare il documento"); } // Reperimento scheda documento DocsPaVO.documento.SchedaDocumento document = this.GetDocument(request.UserInfo, request.DocumentId); // Reperimento del path del modello per la stampa della ricevuta di protocollo string modelPath = this.GetModelPath(document); // Reperimento del file template modello if (File.Exists(modelPath)) { modelResponse.DocumentModel.ModelType = BaseDocModelProcessor.MODEL_STAMPA_RICEVUTA; modelResponse.DocumentModel.File.FileName = Path.GetFileName(modelPath); modelResponse.DocumentModel.File.Content = File.ReadAllBytes(modelPath); modelResponse.DocumentModel.KeyValuePairs = this.GetModelKeyValuePairs(request.UserInfo, document); } else { throw new ApplicationException("File modello inesistente"); } } catch (Exception ex) { modelResponse = new DocsPaVO.Modelli.ModelResponse(); modelResponse.Exception = ex.Message; logger.Debug(string.Format("Errore nel reperimento dei dati del modello: {0}", ex.Message)); } return(modelResponse); }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public DocsPaVO.Modelli.ModelResponse ProcessModel(DocsPaVO.Modelli.ModelRequest request) { DocsPaVO.Modelli.ModelResponse response = null; try { IModelProcessor processor = this.CreateInstance(request.ModelType); //return processor.ProcessModel(request); response = processor.ProcessModel(request); } catch (Exception ex) { response = new DocsPaVO.Modelli.ModelResponse { DocumentId = request.DocumentId, Exception = ex.Message, }; } return(response); }
/// <summary> /// /// </summary> /// <param name="userInfo"></param> /// <param name="idDocument"></param> /// <returns></returns> public static DocsPaVO.documento.FileDocumento Create(DocsPaVO.utente.InfoUtente userInfo, string idDocument) { byte[] content = null; DocsPaVO.documento.FileDocumento fdoc = new DocsPaVO.documento.FileDocumento(); StampaRicevuteDocModelProcessor processor = new StampaRicevuteDocModelProcessor(); DocsPaVO.documento.SchedaDocumento document = GetDocument(userInfo, idDocument); DocsPaVO.Modelli.ModelResponse response = processor.ProcessModel( new DocsPaVO.Modelli.ModelRequest { DocumentId = idDocument, UserInfo = userInfo, ModelType = BaseDocModelProcessor.MODEL_STAMPA_RICEVUTA }); if (string.IsNullOrEmpty(response.Exception)) { using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { PdfStamper ps = null; // read existing PDF document PdfReader r = new PdfReader( // optimize memory usage // Reperimento del path del modello per la stampa della ricevuta di protocollo new RandomAccessFileOrArray(GetModelPath(document)), null); ps = new PdfStamper(r, stream); // retrieve properties of PDF form w/AcroFields object AcroFields af = ps.AcroFields; // fill in PDF fields by parameter: // 1. field name // 2. text to insert af.SetField("AMMINISTRAZIONE", FindDocumentValue(BaseDocModelProcessor.DocumentCommonFields.AMMINISTRAZIONE, response.DocumentModel.KeyValuePairs)); af.SetField("DATA_ORA_PROTOCOLLO", FindDocumentValue(BaseDocModelProcessor.DocumentCommonFields.DATA_ORA_PROTOCOLLO, response.DocumentModel.KeyValuePairs)); af.SetField("NUMERO_PROTOCOLLO", FindDocumentValue(BaseDocModelProcessor.DocumentCommonFields.NUM_PROTOCOLLO, response.DocumentModel.KeyValuePairs)); af.SetField("SEGNATURA", FindDocumentValue(BaseDocModelProcessor.DocumentCommonFields.SEGNATURA, response.DocumentModel.KeyValuePairs)); af.SetField("OGGETTO", FindDocumentValue(BaseDocModelProcessor.DocumentCommonFields.OGGETTO, response.DocumentModel.KeyValuePairs)); // make resultant PDF read-only for end-user ps.FormFlattening = true; //stream.Position = 0; //content = new byte[stream.Length]; //stream.Read(content, 0, content.Length); ps.Close(); fdoc.content = stream.ToArray(); stream.Close(); // ps.Close(); //stream.Close(); //stream.Flush(); } return(fdoc); } else { throw new ApplicationException(response.Exception); } }