private void button1_Click(object sender, EventArgs e) { TXTextControl.DocumentServer.MailMerge mm = new TXTextControl.DocumentServer.MailMerge(); mm.TextComponent = textControl1; textControl1.Load("invoice.tx", TXTextControl.StreamType.InternalUnicodeFormat); Invoice invoice = CreateSampleInvoice(); // merge data into template mm.MergeJsonData(JsonConvert.SerializeObject(invoice)); // create the XML string xmlZugferd = invoice.CreateXml(); // get the required meta data string metaData = MetaData.GetMetaData(); TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings(); // create a new embedded file var zugferdInvoice = new TXTextControl.EmbeddedFile( "ZUGFeRD-invoice.xml", Encoding.UTF8.GetBytes(xmlZugferd), metaData); zugferdInvoice.Description = "ZUGFeRD-invoice"; zugferdInvoice.Relationship = "Alternative"; zugferdInvoice.MIMEType = "application/xml"; zugferdInvoice.LastModificationDate = DateTime.Now; // set the embedded files saveSettings.EmbeddedFiles = new TXTextControl.EmbeddedFile[] { new TXTextControl.EmbeddedFile( "ZUGFeRD-invoice.xml", Encoding.UTF8.GetBytes(xmlZugferd), metaData) }; // export the PDF textControl1.Save("test.pdf", TXTextControl.StreamType.AdobePDFA, saveSettings); }
public ActionResult StoreDocument( [FromBody] string Document, [FromBody] string UniqueId, [FromBody] string SignerName) { byte[] bPDF; // create temporary ServerTextControl using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) { tx.Create(); // load the document tx.Load(Convert.FromBase64String(Document), TXTextControl.BinaryStreamType.InternalUnicodeFormat); TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings() { CreatorApplication = "TX Text Control Sample Application", }; // save the document as PDF tx.Save(out bPDF, TXTextControl.BinaryStreamType.AdobePDF, saveSettings); } // calculate the MD5 checksum of the binary data // and store in SignedDocument object SignedDocument document = new SignedDocument() { Checksum = Checksum.CalculateMD5(bPDF) }; // define a Blockchain object Blockchain bcDocument; // if the blockchain exists, load it if (System.IO.File.Exists( Server.MapPath("~/App_Data/Blockchains/" + UniqueId + ".bc"))) { string bc = System.IO.File.ReadAllText( Server.MapPath("~/App_Data/Blockchains/" + UniqueId + ".bc")); bcDocument = JsonConvert.DeserializeObject <Blockchain>(bc); } else { bcDocument = new Blockchain(true); // otherwise create a new blockchain } // add a new block to the blockchain and store the SignedDocument object bcDocument.AddBlock(new Block(DateTime.Now, null, JsonConvert.SerializeObject(document))); // store the blockchain as a file System.IO.File.WriteAllText( Server.MapPath("~/App_Data/Blockchains/" + UniqueId + ".bc"), JsonConvert.SerializeObject(bcDocument)); // create and return a view model with the PDF and the unique document ID StoredDocument storedDocument = new StoredDocument() { PDF = Convert.ToBase64String(bPDF), DocumentId = UniqueId }; return(new JsonResult() { Data = storedDocument, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }