public InsertPicture ( |
||
p | The Picture to insert. | |
index | int | The text index to insert at. |
Результат |
/// <summary> /// Method that creates a Microsoft Word Document full of the QR code images that are associated with each question /// of the current treasure hunt and passes to the Print view the location of where this new file is stored. /// </summary> public void ExecutePrintQRCodesCommand() { PopupMessage = "Preparing..."; PopupDisplayed = true; NewQuestion = null; //-http://cathalscorner.blogspot.co.uk/2009/04/docx-version-1002-released.html //The location of where this word document will be stored. String newDocumentFileLocation = myFileDirectory + "Documents\\" + this.currentTreasureHunt.HuntName + " QR Codes Sheet.docx"; //The creation of this new Word Document for the file location supplied using (DocX documentOfQRCodes = DocX.Create(newDocumentFileLocation)) { Novacode.Paragraph p = documentOfQRCodes.InsertParagraph(this.currentTreasureHunt.HuntName); documentOfQRCodes.InsertParagraph(); //For every question associated with the current treasure hunt using (var currentQuestionQRCode = this.questions.GetEnumerator()) { while (currentQuestionQRCode.MoveNext()) { if (currentQuestionQRCode.Current.URL != null && currentQuestionQRCode.Current.URL != "empty URL") { //Insert into the document the QR associated with the current question documentOfQRCodes.InsertParagraph(currentQuestionQRCode.Current.Question1); documentOfQRCodes.InsertParagraph(); Novacode.Paragraph q = documentOfQRCodes.InsertParagraph(); string locationOfImage = myFileDirectory + "QRCodes\\" + CurrentTreasureHunt.HuntId + " " + currentQuestionQRCode.Current.Question1 + ".png"; Novacode.Image img = documentOfQRCodes.AddImage(@locationOfImage); Picture pic1 = img.CreatePicture(); q.InsertPicture(pic1, 0); pic1.Width = 200; pic1.Height = 200; documentOfQRCodes.InsertParagraph(); } } } documentOfQRCodes.Save(); PopupDisplayed = false; } Messenger.Default.Send <UpdateViewMessage>(new UpdateViewMessage() { UpdateViewTo = "PrintViewModel" }); Messenger.Default.Send <PrintMessage>(new PrintMessage() { FileLocation = newDocumentFileLocation }); Messenger.Default.Send <SelectedHuntMessage>(new SelectedHuntMessage() { CurrentHunt = this.currentTreasureHunt }); }
//make internal public void ExecutePrintQRCodesCommand() { NewQuestion = null; //-http://cathalscorner.blogspot.co.uk/2009/04/docx-version-1002-released.html String newDocumentFileLocation = myFileDirectory + "Documents\\" + this.currentTreasureHunt.HuntName + " QR Codes Sheet.docx"; //if(File.Exists(myFileDirectory + "Documents\\" + this.currentTreasureHunt.HuntName + " QR Codes Sheet.docx") //{ using (DocX documentOfQRCodes = DocX.Create(newDocumentFileLocation)) { Novacode.Paragraph p = documentOfQRCodes.InsertParagraph(this.currentTreasureHunt.HuntName); Novacode.Paragraph space = documentOfQRCodes.InsertParagraph(""); documentOfQRCodes.InsertParagraph(); using (var currentQuestionQRCode = this.questions.GetEnumerator()) { while (currentQuestionQRCode.MoveNext()) { if (currentQuestionQRCode.Current.URL != null && currentQuestionQRCode.Current.URL != "empty URL") { documentOfQRCodes.InsertParagraph(currentQuestionQRCode.Current.Question1); Novacode.Paragraph q = documentOfQRCodes.InsertParagraph(); string locationOfImage = myFileDirectory + "QRCodes\\" + CurrentTreasureHunt.HuntId + " " + currentQuestionQRCode.Current.Question1 + ".png"; Novacode.Image img = documentOfQRCodes.AddImage(@locationOfImage); Picture pic1 = img.CreatePicture(); q.InsertPicture(pic1, 0); pic1.Width = 200; pic1.Height = 200; documentOfQRCodes.InsertParagraph(); } } } documentOfQRCodes.Save(); } Messenger.Default.Send <UpdateViewMessage>(new UpdateViewMessage() { UpdateViewTo = "PrintViewModel" }); Messenger.Default.Send <PrintMessage>(new PrintMessage() { FileLocation = newDocumentFileLocation }); Messenger.Default.Send <SelectedHuntMessage>(new SelectedHuntMessage() { CurrentHunt = this.currentTreasureHunt }); }
public override object Template(Int32 CompanyId, string templateBlobPath, Dictionary <string, string> templateKeywords) { util.ContainerName = "company-" + CompanyId; string blobName = util.getBlob(templateBlobPath); _cblob = util.BlobContainer.GetBlockBlobReference(blobName); //_cblob.FetchAttributes(); var ms = new MemoryStream(); _cblob.DownloadToStream(ms); long fileByteLength = _cblob.Properties.Length; byte[] fileContents = new byte[fileByteLength]; _cblob.DownloadToByteArray(fileContents, 0); DocX _template = DocX.Load(ms); if (templateKeywords != null && templateKeywords.Keys.Count > 0) { foreach (string key in templateKeywords.Keys) { if (key.ToLower().Equals("{signature}")) { using (FileStream imageFile = new FileStream(tempIMGpath, FileMode.Create)) { byte[] bytes = System.Convert.FromBase64String(templateKeywords[key].Replace("data:image/jpeg;base64,", string.Empty)); imageFile.Write(bytes, 0, bytes.Length); imageFile.Flush(); imageFile.Dispose(); } Novacode.Image img = _template.AddImage(tempIMGpath); Picture pic1 = img.CreatePicture(); Novacode.Paragraph p1 = _template.InsertParagraph(); p1.InsertPicture(pic1); _template.ReplaceText(key, ""); } else { _template.ReplaceText(key, templateKeywords[key]); } } } _template.SaveAs(tempDOCpath); Aspose.Words.Document doc = new Aspose.Words.Document(tempDOCpath); doc.Save(tempPDFpath); //doc.Remove(); /*Microsoft.Office.Interop.Word.Document wordDocument; * Application appWord = new Application(); * wordDocument = appWord.Documents.Open(tempDOCpath); * wordDocument.ExportAsFixedFormat(tempPDFpath, WdExportFormat.wdExportFormatPDF); * * wordDocument.Close();*/ ms.Flush(); ms.Close(); return(tempPDFpath); }