Using QR Codes to Open Documents in Document Portals
This sample application shows how to add QR codes to documents that open the document in a document portal using the DocumentViewer.

One of the major applications for Text Control digital document processing components is the creation and processing of invoices and other document types.
Documents can be send as attachments in e-mails, a link can be provided to view the documents online or access to a document portal can be granted. By providing users a streamlined way to access documents, you gain additional advantages such as document tracking. You receive the ability to know when an document has been opened and accessed.
Hybrid: Combining Offline and Online
Over the next couple years, there might be still a requirement to send out printed documents. Whether this is required for legal reasons or a customer request to receive printed versions of documents. By providing a combination of both offline and online, users are getting best of both worlds and can adjust to the electronic deployment strategies.
The easiest way to achieve this is to provide users access to all their documents in a portal. On the printed version, simply place a QR code that opens the document directly in your portal using the Text Control DocumentViewer.
With TX Text Control, creating QR codes is an integrated feature and is as simple as merging text into merge field placeholders. QR codes can be used as placeholders in reporting templates. Each barcode object is assigned a unique ID and Name in order to visualize actual data during the merge process.
Sample Application
For demo purposes, a very simple dummy document can be generated in the demo portal by clicking the button Create Dummy Document:
The requested Company Name is only used to generate a document from a template that contains some form fields to demonstrate that the documents are dynamically created. When clicking Create, the data is merged into the template and a unique ID is generated. This unique ID is added to an URL that opens the stored document in another view whenever this QR code is scanned. This URL is merged into the QR Code placeholder field.
[HttpPost]
public bool CreateDummyDocument(string CompanyName) {
// create a unique ID
string guid = Guid.NewGuid().ToString();
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
// create ServerTextControl and load template
tx.Create();
tx.Load("App_Data/vendor.tx", TXTextControl.StreamType.InternalUnicodeFormat);
using (TXTextControl.DocumentServer.MailMerge mailMerge = new TXTextControl.DocumentServer.MailMerge()) {
mailMerge.TextComponent = tx;
// flatten PDF
mailMerge.FormFieldMergeType = TXTextControl.DocumentServer.FormFieldMergeType.Replace;
// create dummy merge data with barcode URL
VendorData data = new VendorData() {
vendor_name = CompanyName,
document_qr = Url.Action("View", "Home", new { id = guid }, protocol: Request.Scheme)
};
// merge template
mailMerge.MergeObject(data);
}
// save results and store in database
byte[] results;
tx.Save(out results, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
using (MemoryStream ms = new MemoryStream(results)) {
using (var db = new LiteDatabase("App_Data/MyData.db")) {
var col = db.GetCollection<Document>("documents");
var document = new Document {
Name = "dummy_" + guid + ".tx",
DocumentId = guid,
Created = DateTime.Now
};
col.Insert(document);
var fs = db.FileStorage;
fs.Upload("$/documents/" + "dummy_" + guid + ".tx", "dummy_" + guid + ".tx", ms);
}
}
return true;
}
}
The document is stored in a database and the overview lists all stored documents:
When the QR code is scanned, a URL is opened that loads the requested document by the given ID into the DocumentViewer:
The view is using the DocumentViewer to render the document that is loaded from the database:
public IActionResult View(string id) {
// retrieve document by id and return document as model
using (var db = new LiteDatabase("App_Data/MyData.db")) {
var fs = db.FileStorage;
using (MemoryStream ms = new MemoryStream()) {
fs.Download("$/documents/dummy_" + id + ".tx", ms);
var fileBytes = ms.ToArray();
ViewDocument viewDoc = new ViewDocument() {
Name = "dummy" + id + ".tx",
BinaryData = Convert.ToBase64String(fileBytes)
};
return View(viewDoc);
}
}
}
You can test this on your own by downloading the sample application from our GitHub repository.
Conclusion
Using Text Control digital document processing components, you get a complete set of tools to fully integrate invoice processing and deployment strategies into your business applications. Talk to our engineers, if you would like to learn more about how Text Control can help you with your document processing requirements.
Download and Fork This Sample on GitHub
We proudly host our sample code on github.com/TextControl.
Please fork and contribute.
Requirements for this sample
- TX Text Control .NET Server
- Visual Studio 2022
ASP.NET
Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.
- Angular
- Blazor
- React
- JavaScript
- ASP.NET MVC, ASP.NET Core, and WebForms
Related Posts
Enhancing Documents with QR Codes and Barcodes in .NET C#: A Comprehensive Guide
QR codes and barcodes can be highly beneficial on various documents or PDFs, providing a convenient way to access information, verify authenticity, track items, and enhance user interaction. This…
Adding QR Codes to PDF Documents in C# .NET
This article explains how to add QR codes to PDF documents with the Text Control .NET Server component in C#. It provides the necessary steps and code snippets for effectively implementing this…
Merging Barcodes with JSON Data in C#
Barcodes are used in various applications to connect the electronic world with a paper document or to gain access to additional information. This article shows how to merge JSON data into barcode…