> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/get-started/samples/webviewer-mendix-module.md).

# Integrate WebViewer into a Mendix Web Module

This sample provides a server side Mendix Web Module for WebViewer.

This sample provides a Mendix backend module that facilitates server side operations that work with WebViewer

WebViewer provides a slick out-of-the-box responsive UI that enables you to view, annotate and manipulate PDFs and other document types inside any web project.

Click the button below to view the full project in GitHub.

{% tabs %}
{% tab title="GetFileId.java" %}
{% code title="GetFileId.java" lineNumbers="true" %}

```java
// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.

package webviewer.actions;

import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import com.mendix.systemwideinterfaces.core.IMendixObject;

public class GetFileId extends CustomJavaAction<java.lang.String>
{
	/** @deprecated use inputFile.getMendixObject() instead. */
	@java.lang.Deprecated(forRemoval = true)
	private final IMendixObject __inputFile;
	private final webviewer.proxies.File inputFile;

	public GetFileId(
		IContext context,
		IMendixObject _inputFile
	)
	{
		super(context);
		this.__inputFile = _inputFile;
		this.inputFile = _inputFile == null ? null : webviewer.proxies.File.initialize(getContext(), _inputFile);
	}

	@java.lang.Override
	public java.lang.String executeAction() throws Exception
	{
		// BEGIN USER CODE
		return "" + this.inputFile.getMendixObject().getId().toLong();
		// END USER CODE
	}

	/**
	 * Returns a string representation of this action
	 * @return a string representation of this action
	 */
	@java.lang.Override
	public java.lang.String toString()
	{
		return "GetFileId";
	}

	// BEGIN EXTRA CODE
	// END EXTRA CODE
}

```

{% endcode %}
{% endtab %}

{% tab title="SaveDocument.java" %}
{% code title="SaveDocument.java" lineNumbers="true" %}

```java
// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.

package webviewer.actions;

import java.io.InputStream;
import com.mendix.core.Core;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.systemwideinterfaces.core.IMendixIdentifier;
import com.mendix.webui.CustomJavaAction;
import com.mendix.systemwideinterfaces.core.IMendixObject;

public class SaveDocument extends CustomJavaAction<java.lang.String>
{
	/** @deprecated use fileData.getMendixObject() instead. */
	@java.lang.Deprecated(forRemoval = true)
	private final IMendixObject __fileData;
	private final webviewer.proxies.File fileData;

	public SaveDocument(
		IContext context,
		IMendixObject _fileData
	)
	{
		super(context);
		this.__fileData = _fileData;
		this.fileData = _fileData == null ? null : webviewer.proxies.File.initialize(getContext(), _fileData);
	}

	@java.lang.Override
	public java.lang.String executeAction() throws Exception
	{
		// BEGIN USER CODE
		// Get the file data we got from the request to write into the original object
		InputStream stream = Core.getFileDocumentContent(getContext(), this.fileData.getMendixObject());
		Core.storeFileDocumentContent(getContext(), __fileData, stream);
		// Create the new file object
		this.fileData.commit();

		// With the file ID we got from the request, create an identifier object
		IMendixIdentifier id = this.fileData.getMendixObject().getId();

		return String.valueOf(id.toLong());
		// END USER CODE
	}

	/**
	 * Returns a string representation of this action
	 * @return a string representation of this action
	 */
	@java.lang.Override
	public java.lang.String toString()
	{
		return "SaveDocument";
	}

	// BEGIN EXTRA CODE
	// END EXTRA CODE
}

```

{% endcode %}
{% endtab %}

{% tab title="UpdateDocument.java" %}
{% code title="UpdateDocument.java" lineNumbers="true" %}

```java
// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.

package webviewer.actions;

import java.io.InputStream;
import com.mendix.core.Core;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.systemwideinterfaces.core.IMendixIdentifier;
import com.mendix.webui.CustomJavaAction;
import webviewer.proxies.File;
import com.mendix.systemwideinterfaces.core.IMendixObject;

public class UpdateDocument extends CustomJavaAction<java.lang.Void>
{
	private final java.lang.String fileId;
	/** @deprecated use Parameter.getMendixObject() instead. */
	@java.lang.Deprecated(forRemoval = true)
	private final IMendixObject __Parameter;
	private final webviewer.proxies.File Parameter;

	public UpdateDocument(
		IContext context,
		java.lang.String _fileId,
		IMendixObject _parameter
	)
	{
		super(context);
		this.fileId = _fileId;
		this.__Parameter = _parameter;
		this.Parameter = _parameter == null ? null : webviewer.proxies.File.initialize(getContext(), _parameter);
	}

	@java.lang.Override
	public java.lang.Void executeAction() throws Exception
	{
		// BEGIN USER CODE
		// With the file ID we got from the request, create an identifier object
		IMendixIdentifier id = Core.createMendixIdentifier(fileId);
		// Load the original object from the context
		File origFile = File.load(getContext(), id);
		// Get the file data we got from the request to write into the original object
		InputStream stream = Core.getFileDocumentContent(getContext(), this.Parameter.getMendixObject());
		origFile.setContents(getContext(), stream, this.Parameter.getSize());
		origFile.commit();
		// Delete the new file object created when we sent the update request
		this.Parameter.delete();
		this.Parameter.commit();

		return null;
		// END USER CODE
	}

	/**
	 * Returns a string representation of this action
	 * @return a string representation of this action
	 */
	@java.lang.Override
	public java.lang.String toString()
	{
		return "UpdateDocument";
	}

	// BEGIN EXTRA CODE
	// END EXTRA CODE
}

```

{% endcode %}
{% endtab %}
{% endtabs %}

[View the full sample on GitHub](https://github.com/ApryseSDK/webviewer-samples/tree/main/webviewer-mendix-module)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/get-started/samples/webviewer-mendix-module.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
