public MergedDocument MergeDocument([FromBody] MergedDocument Document)
        {
            byte[] data;

            Customer customer = new Customer()
            {
                Firstname = "Klaus", Name = "Klaasen"
            };

            using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
            {
                tx.Create();
                tx.Load(Convert.FromBase64String(Document.Document), TXTextControl.BinaryStreamType.InternalUnicodeFormat);

                TXTextControl.DocumentServer.MailMerge mm = new TXTextControl.DocumentServer.MailMerge();
                mm.TextComponent = tx;

                mm.MergeObject(customer);

                tx.Save(out data, TXTextControl.BinaryStreamType.InternalUnicodeFormat);

                return(new MergedDocument()
                {
                    Document = Convert.ToBase64String(data)
                });
            }
        }
Example #2
0
        private void btnMerge_Click(object sender, EventArgs e)
        {
            // merge the template with JSON data
            using (TXTextControl.DocumentServer.MailMerge mailMerge = new TXTextControl.DocumentServer.MailMerge())
            {
                mailMerge.TextComponent = textControl1;
                mailMerge.FieldMerged  += MailMerge_FieldMerged;

                string data = File.ReadAllText("data.json");
                mailMerge.MergeJsonData(data, false);
            }
        }
        private void RbPreview_Click(object sender, EventArgs e)
        {
            // create a MailMerge instance
            TXTextControl.DocumentServer.MailMerge mailMerge =
                new TXTextControl.DocumentServer.MailMerge()
            {
                TextComponent = textControl1
            };

            // attach the IncludeTextMerging event
            mailMerge.IncludeTextMerging += MailMerge_IncludeTextMerging;

            // merge template with dummy data
            mailMerge.MergeObject(report);
        }
        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);
        }