Step-by-Step Guide to Add QR Code to Document in Alfresco

Step-by-Step Guide to Add QR Code to Document in Alfresco

The QR code is no longer a new term for techies as well as non-technical persons. Out of many possible applications of QR code, one is to apply it to the documents that have stored or associated information. For those who want a technical definition of a QR code, we can mention here what Wikipedia says: A QR code is an optical and machine-readable representation of data; here, the data describes something about the object that carries the QR code.

Alfresco, as a document management system, requires the documents to be printed with QR codes. These QR codes contain some associated data of the said documents.

We, at ContCentric, have developed a solution wherein you can directly pick the document metadata from PDF files in the form of the QR code in Alfresco.

Related Blog: How to Add Barcode to Documents in Alfresco

Here is the technical approach on how to generate a QR code in Alfresco:

  • Java action – To allow users to generate and decide where to place the QR code in the document
  • Evaluator – To show action only on PDF documents (share side class)
  • A Java PDF library (iText) – Provides classes and functions to edit PDF documents

Java Action

Create a Java class with following code at alfresco/src/main/java

public class BarcodeQRCodePdfActionExecuter extends ActionExecuterAbstractBase {
	private static Log logger = LogFactory.getLog(BarcodeQRCodePdfActionExecuter.class);
	private ServiceRegistry serviceRegistry;

	public static final String PARAM_PAGE_NO = "page-no";

	public void setServiceRegistry(ServiceRegistry serviceRegistry) {
		this.serviceRegistry = serviceRegistry;

	protected void addParameterDefinitions(List paramList) {
		for (String s : new String[] {PARAM_PAGE_NO}) {
			paramList.add(new ParameterDefinitionImpl(s, DataTypeDefinition.TEXT, true, getParamDisplayLabel(s)));

	protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {

		logger.debug("Page No " + action.getParameterValue(PARAM_PAGE_NO));
		Map<QName, Serializable> props = serviceRegistry.getNodeService().getProperties(actionedUponNodeRef);
		String qrCodeString = new String();
		for (Map.Entry<QName,Serializable> entry : props.entrySet()){ 
            qrCodeString += entry.getKey().getLocalName()+" : "+entry.getValue()+"\n";
		ContentWriter writer = serviceRegistry.getContentService().getWriter(actionedUponNodeRef,
				ContentModel.PROP_CONTENT, true);
		ContentReader reader = serviceRegistry.getContentService().getReader(actionedUponNodeRef,
		int pageNo = Integer.parseInt((String) action.getParameterValue(PARAM_PAGE_NO));
		try {

			PdfReader pdfReader = new PdfReader(reader.getContentInputStream());
			PdfStamper stamper = new PdfStamper(pdfReader, writer.getContentOutputStream());
			PdfContentByte over = stamper.getOverContent(pageNo);
			BarcodeQRCode barcodeQRCode = new BarcodeQRCode(qrCodeString, 1, 1, null);
			Image qrcodeImage = barcodeQRCode.getImage();

		} catch (ContentIOException e) {

		} catch (IOException e) {

		} catch (DocumentException e) {


Create a separate <bean> at alfresco/src/main/amp/config/alfresco/module/${project-name}/context/ to register action class.

	<bean id="barcodeQRCode-pdf"
		<property name="serviceRegistry">
			<ref bean="ServiceRegistry" />

Create an extension module at share/src/main/amp/config/alfresco/web-extension/site-data/extensions/ in separate or existing xml file.

<config evaluator="string-compare" condition="DocLibActions">
		<action id="alfresco.doclib.action.barcodeQRCodePdf"
			icon="qrcode" type="javascript"
			<param name="function">onActionFormDialog</param>
			<param name="itemKind">action</param>
			<param name="itemId">barcodeQRCode-pdf</param> <!-- Repository action id = Spring Bean id -->
			<param name="mode">create</param>
			<param name="destination">{node.nodeRef}</param>
			<param name="successMessage">alfresco.doclib.action.barcodeQRCodePdf.msg.success
			<param name="failureMessage">alfresco.doclib.action.barcodeQRCodePdf.msg.failure

		<actionGroup id="document-browse">
			<action index="400" id="alfresco.doclib.action.barcodeQRCodePdf" />
		<actionGroup id="document-details">
			<action index="400" id="alfresco.doclib.action.barcodeQRCodePdf" />

<config evaluator="string-compare" condition="barcodeQRCode-pdf"> ID for the Repository Action that this form is associated with
				<show id="page-no" />
				<field id="page-no"

Create a properties file for Label at share/src/main/amp/config/alfresco/web-extension/messages/

alfresco.doclib.action.barcodeQRCodePdf.label=QRCode Pdf
alfresco.doclib.action.barcodeQRCodePdf.msg.success=Pdf have been QRcoded.
alfresco.doclib.action.barcodeQRCodePdf.msg.failure=Problem in qrcoding Pdf, please contact Administrator
alfresco.doclib.action.barcodeQRCodePdf.form.field.pageNo=Page Number


Note: You have to add images for the action icon at


Evaluator (Shows action only on PDF document)

Create a separate <bean> with the following code at

<bean id="alfresco.barcodeQRCodePdf.evaluator.checkPDFFileType"
	<property name="mimetypes">

iText Library

Add the following dependency to pom.xml to use this library.

<!-- -->




That’s it for now! If you have any feedback or suggestions regarding this approach, we would love to hear from you. We certainly hope that this article will guide you when you need to address QR code document management requirement in Alfresco. Though you must have come across an online barcode generator, we believe that this technique will add value to the Alfresco practice.

What’s more, as Alfresco deals with digitization projects, integration with Ephesoft helps you achieve OCR indexing, i.e. to extract values from the scanned documents and pushing it to the database. The application is widely used in Purchase Document Management and Pharmaceutical Document Management.

ContCentric team would be happy to help! Please feel free to approach us for a free consultation of the high-level requirement understanding.

Thanks for reading. Happy Developing!

    Have a Business Inquiry ?

    Let us collaborate and break yet another barrier to digitalization. Connect with us to discuss the project!

    Let us connect the digital dots!

    We are seeking dynamic professionals and unstoppable talents to craft distinct solutions for our clients to enhance their businesses. Come, join our fair & focused, optimistic & thoughtful world and deliver excellence together.