Integración con API

We have SDK for the following languages:

You can see all the integrations in Github.

Full API reference can be found on this webpage.

Render a remote DOCX with JSON

You can get the file result having an URL with the DOCX and passing JSON as a paramter

# pip install docxmerge_sdk 
# https://pypi.org/project/docxmerge-sdk/

from docxmerge_sdk import Docxmerge
docxmerge = Docxmerge("API_KEY", "default", "https://api.docxmerge.com")

pdf = docxmerge.render_url(
    "http://docxmerge.com/static/hello_world.docx",
    {
        "logo": "https://docxmerge.com/assets/android-chrome-512x512.png",
        "name": "James Bond"
    },
    "PDF"
)

open("./example-hello-world.pdf", "wb").write(pdf)
package com.docxmerge.prueba_sdk;

import com.docxmerge.Docxmerge;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;

public class DocxmergeExample {
    public static void main(String[] args) throws Exception {
        Docxmerge docxmerge = new Docxmerge("API_KEY", "default", "https://api.docxmerge.com");
        HashMap<String, Object> data = new HashMap<>();
        data.put("name", "James Bond");
        data.put("logo", "https://docxmerge.com/assets/android-chrome-512x512.png");
        byte[] bytes = docxmerge.renderUrl("http://docxmerge.com/static/hello_world.docx", data, "PDF");
        FileOutputStream outputStream = new FileOutputStream("./hello_world_java.pdf");
        outputStream.write(bytes);
        outputStream.close();
    }

}
<?php
require_once('vendor/autoload.php');

// the package can be downloaded in
// https://packagist.org/packages/docxmerge/docxmerge-php

use Docxmerge\Docxmerge;

$docxmerge = new Docxmerge("API_KEY", "default", "https://api.docxmerge.com");
$fp = fopen("./hello_world_php.pdf", "w");

$docxmerge->renderUrl(
    $fp,
    "http://docxmerge.com/static/hello_world.docx",
    array(
        "name" => "James bond",
        "logo" => "https://docxmerge.com/assets/android-chrome-512x512.png"
    ),
    "PDF"
);
const Docxmerge = new require('docxmerge')
const fs = require('fs')

const docxmerge = new Docxmerge("API_KEY", "default")
docxmerge
  .renderUrl(
    "http://docxmerge.com/static/hello_world.docx",
    {
      logo: "https://docxmerge.com/assets/android-chrome-512x512.png",
      name: "James Bond",
    },
    "PDF", // this can be PDF, PNG, HTML, SVG...
  )
  .then(stream => stream.pipe(fs.createWriteStream("./hello_world_nodejs.pdf")))
  .catch(err => {
    console.error(err)
  })
package main
// package in github.com/docxmerge/docxmerge-go
import (
	"bytes"
	"github.com/docxmerge/docxmerge-go"
	"io/ioutil"
	"log"
)

func main() {
	data := map[string]interface{}{
		"name": "David Viejo",
		"logo": "https://docxmerge.com/assets/android-chrome-512x512.png",
	}
	docxmerge := docxmerge_go.NewDocxmerge(docxmerge_go.DocxmergeOptions{
		BaseUrl: "https://api.docxmerge.com",
		ApiKey:  "API_KEY",
		Tenant:  "default",
	})

	pdf, err := docxmerge.RenderUrl(
		"http://docxmerge.com/static/hello_world.docx",
		data,
		"PDF",
	)
	if err != nil {
		panic(err)
	}
	buf := new(bytes.Buffer)
	_, err = buf.ReadFrom(pdf)
	if err != nil {
		panic(err)
	}
	output := "./hello_world_golang.pdf"
	err = ioutil.WriteFile(output, buf.Bytes(), 0644)
	if err != nil {
		panic(err)
	}
	log.Printf("Check %s", output)
}
require "docxmerge"
# gem install docxmerge
# https://rubygems.org/gems/docxmerge
docxmerge = Docxmerge::Docxmerge.new("API_KEY", "default", "https://api.docxmerge.com")

response = docxmerge.render_url(
    "http://docxmerge.com/static/hello_world.docx", 
    {
        :logo => "https://docxmerge.com/assets/android-chrome-512x512.png",
        :name => "James Bond",
    },
    "PDF"
)

file_output = "./hello_world_ruby.pdf"

f = File.open(file_output, "wb")
f << response
f.close
puts "Check #{file_output}"
using System.Collections.Generic;
using System.IO;

// can be download in https://nuget.org/packages/Docxmerge/
// dotnet add package docxmerge

namespace DocxmergeExample
{
  class Program
  {
    static void Main(string[] args)
    {
      var docxmerge = new Docxmerge.Docxmerge("API_KEY", "default", "https://api.docxmerge.com");
      var output = docxmerge.RenderUrl(
          "http://docxmerge.com/static/hello_world.docx", 
          new Dictionary<string, object>{
             {"name", "James Bond"},
             {"logo", "https://docxmerge.com/assets/android-chrome-512x512.png"}
          },
          "PDF"
      ).Result;
      using (var ms = new MemoryStream())
      {
        output.CopyTo(ms);
        var outputFile = "./hello_world_dotnet.pdf";
        File.WriteAllBytes(outputFile, ms.ToArray());
        System.Console.WriteLine($"Check {outputFile}");
      }
    }
  }
}

Render a local DOCX with JSON

# pip install docxmerge_sdk 
# https://pypi.org/project/docxmerge-sdk/

from docxmerge_sdk import Docxmerge
docxmerge = Docxmerge("API_KEY", "default", "https://api.docxmerge.com")

pdf = docxmerge.render_file(
    open("./hello_world.docx"),
    {
        "logo": "https://docxmerge.com/assets/android-chrome-512x512.png",
        "name": "James Bond"
    },
    "PDF"
)

open("./example-file-hello-world.pdf", "wb").write(pdf)
package com.docxmerge.prueba_sdk;

import com.docxmerge.Docxmerge;

import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;

public class DocxmergeExample {
    public static void main(String[] args) throws Exception {
        Docxmerge docxmerge = new Docxmerge("API_KEY", "default", "https://api.docxmerge.com");
        HashMap<String, Object> data = new HashMap<>();
        data.put("name", "James Bond");
        data.put("logo", "https://docxmerge.com/assets/android-chrome-512x512.png");

        byte[] docxBytes = Files.readAllBytes(Paths.get("./hello_world.docx"));

        byte[] bytes = docxmerge.renderFile(docxBytes, data, "PDF");
        FileOutputStream outputStream = new FileOutputStream("hello_world_java.pdf");
        outputStream.write(bytes);
        outputStream.close();
    }
}
<?php
require_once('vendor/autoload.php');

use Docxmerge\Docxmerge;

$docxmerge = new Docxmerge("API_KEY");

$fp = fopen("./hello_world_php.pdf", "w");

$docxmerge->renderFile($fp, "../fixtures/hello_world.docx", array(
    "name" => "James bond",
    "logo" => "https://docxmerge.com/assets/android-chrome-512x512.png"
), "PDF");
// step 1, install docxmerge
// npm install docxmerge

// Step 2, import libraries
const Docxmerge = require("docxmerge") // npm i docxmerge
const fs = require("fs")

// Step 3, execute
const docxmerge = new Docxmerge("API_KEY", "default")
docxmerge
  .renderFile(
    fs.createReadStream("./hello_world.docx"),
    {
      logo: "https://docxmerge.com/assets/android-chrome-512x512.png",
      name: "James Bond",
    },
    "PDF",
  )
  .then(stream => stream.pipe(fs.createWriteStream("./hello_world_nodejs.pdf")))
  .catch(err => {
    console.error(err)
  })
package main

import (
	"bytes"
	docxmerge_go "github.com/docxmerge/docxmerge-go"
	"io/ioutil"
	"os"
)

func main() {
	data := map[string]interface{}{
		"name": "David Viejo",
		"logo": "https://docxmerge.com/assets/android-chrome-512x512.png",
	}
	file := "./hello_world.docx"
	docxmerge := docxmerge_go.NewDocxmerge(docxmerge_go.DocxmergeOptions{
		BaseUrl: "https://api.docxmerge.com",
		ApiKey:  "API_KEY",
		Tenant:  "default",
	})

	f, err := os.Open(file)
	if err != nil {
		panic(err)
	}

	pdf, err := docxmerge.RenderFile(
		f,
		data,
		"PDF",
	)
	if err != nil {
		panic(err)
	}
	buf := new(bytes.Buffer)
	_, err = buf.ReadFrom(pdf)
	if err != nil {
		panic(err)
	}
	output := "./hello_world_golang.pdf"
	err = ioutil.WriteFile(output, buf.Bytes(), 0644)
	if err != nil {
		panic(err)
	}
	log.Printf("Check %s", output)
}
require "docxmerge"

docxmerge = Docxmerge::Docxmerge.new("API_KEY", "default")

response = docxmerge.render_file(
    File.open("./hello_world.docx", "r"),
    {
        :logo => "https://docxmerge.com/assets/android-chrome-512x512.png",
        :name => "James Bond",
    },
    "PDF"
)

file_output = "./hello_world_ruby_file.pdf"

f = File.open(file_output, "wb")
f << response
f.close
puts "Check #{file_output}"
using System.Collections.Generic;
using System.IO;
namespace DocxmergeExample
{
  class Program
  {
    static void Main(string[] args)
    {
      var docxmerge = new Docxmerge.Docxmerge("API_KEY");
      var input = File.OpenRead("./hello_world.docx");
      var output = docxmerge.RenderFile(input, new Dictionary<string, object>{
          {"name", "James Bond"},
          {"logo", "https://docxmerge.com/assets/android-chrome-512x512.png"}
      }, "PDF").Result;
      using (var ms = new MemoryStream())
      {
        output.CopyTo(ms);
        var outputFile = "./hello_world_file_dotnet.pdf";
        File.WriteAllBytes(outputFile, ms.ToArray());
        System.Console.WriteLine($"Check {outputFile}");
      }
    }
  }
}

Render a template located in Docxmerge with JSON

# pip install docxmerge_sdk 
# https://pypi.org/project/docxmerge-sdk/

from docxmerge_sdk import Docxmerge
docxmerge = Docxmerge("API_KEY", "default")

pdf = docxmerge.render_template(
    "hello-world",
    {
        "logo": "https://docxmerge.com/assets/android-chrome-512x512.png",
        "name": "James Bond"
    },
    "PDF",
    "latest"
)

open("./example-hello-world-template.pdf", "wb").write(pdf)
package com.docxmerge.prueba_sdk;

import com.docxmerge.Docxmerge;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;

public class DocxmergeExample {
    public static void main(String[] args) throws Exception {
        Docxmerge docxmerge = new Docxmerge("API_KEY", "default", "https://api.docxmerge.com");
        HashMap<String, Object> data = new HashMap<>();
        data.put("name", "James Bond");
        data.put("logo", "https://docxmerge.com/assets/android-chrome-512x512.png");
        byte[] bytes = docxmerge.renderTemplate(
                "hello-world",
                data,
                "PDF",
                "latest" // version, can be ommited, just for reference
        );
        FileOutputStream outputStream = new FileOutputStream("./hello_world_java.pdf");
        outputStream.write(bytes);
        outputStream.close();
    }

}
<?php
require_once('vendor/autoload.php');

use Docxmerge\Docxmerge;

$docxmerge = new Docxmerge("API_KEY");

$fp = fopen("./hello_world_template_php.pdf", "w");

$docxmerge->renderTemplate(
    $fp,
    "hello-world",
    array(
        "name" => "James bond",
        "logo" => "https://docxmerge.com/assets/android-chrome-512x512.png"
    ),
    "PDF",
    "latest" // version, can be ommited, just for reference
);
// step 1, install docxmerge
// npm install docxmerge

// Step 2, import libraries
const Docxmerge = require("docxmerge") // npm i docxmerge
const fs = require("fs")

// Step 3, execute
const docxmerge = new Docxmerge("API_KEY", "default")
docxmerge
  .renderTemplate(
    "hello-world",
    {
      logo: "https://docxmerge.com/assets/android-chrome-512x512.png",
      name: "James Bond",
    },
    "PDF",
    "latest" // version, can be ommited, just for reference
  )
  .then(stream => stream.pipe(fs.createWriteStream("./hello_world_nodejs.pdf")))
  .catch(err => {
    console.error(err)
  })
package main

import (
	"bytes"
	docxmerge_go "github.com/docxmerge/docxmerge-go"
	"io/ioutil"
	"log"
)

func main() {
	data := map[string]interface{}{
		"name": "David Viejo",
		"logo": "https://docxmerge.com/assets/android-chrome-512x512.png",
	}
	docxmerge := docxmerge_go.NewDocxmerge(docxmerge_go.DocxmergeOptions{
		BaseUrl: "https://api.docxmerge.com",
		ApiKey:  "API_KEY",
		Tenant:  "default",
	})

	pdf, err := docxmerge.RenderTemplate(
		"hello-world",
		data,
		"PDF",
		"latest", // version, can be ommited, just for reference
	)
	if err != nil {
		panic(err)
	}
	buf := new(bytes.Buffer)
	_, err = buf.ReadFrom(pdf)
	if err != nil {
		panic(err)
	}
	output := "./hello_world_template_golang.pdf"
	err = ioutil.WriteFile(output, buf.Bytes(), 0644)
	if err != nil {
		panic(err)
	}
	log.Printf("Check %s", output)
}
require "docxmerge"

docxmerge = Docxmerge::Docxmerge.new("API_KEY", "default", "https://api.docxmerge.com")
response = docxmerge.render_template(
    "hello-world",
    {
        :logo => "https://docxmerge.com/assets/android-chrome-512x512.png",
        :name => "James Bond",
    },
    "PDF",
    "latest" # version, can be ommited, just for reference
)

file_output = "./hello_world_template_ruby.pdf"

f = File.open(file_output, "wb")
f << response
f.close
puts "Check #{file_output}"
using System.Collections.Generic;
using System.IO;

namespace DocxmergeExample
{
  class Program
  {
    static void Main(string[] args)
    {
      var docxmerge = new Docxmerge.Docxmerge("API_KEY");
      var output = docxmerge.RenderTemplate(
          "hello-world",
          new Dictionary<string, object>{
              {"name", "James Bond"},
              {"logo", "https://docxmerge.com/assets/android-chrome-512x512.png"}
          },
          "PDF",
          "latest" // version, can be ommited, just for reference
      ).Result;

      using (var ms = new MemoryStream())
      {
        output.CopyTo(ms);
        var outputFile = "./hello_world_template_dotnet.pdf";
        File.WriteAllBytes(outputFile, ms.ToArray());
        System.Console.WriteLine($"Check {outputFile}");
      }
    }
  }
}
Resumen