# Printing ID Cards

**URL:** <https://forum.getodk.org/t/printing-id-cards/6904>\
**Category:** Ideas\
**Tags:** odk-collect\
**Created:** [June 16, 2017, 12:46pm UTC](https://forum.getodk.org/t/printing-id-cards/6904 "2017-06-16T12:46:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![henrik.giz](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/h/82dd89/32.png) [@henrik.giz](https://forum.getodk.org/u/henrik.giz)\
**Post date:** [June 16, 2017, 12:46pm UTC](https://forum.getodk.org/t/printing-id-cards/6904/1 "2017-06-16T12:46:24Z")

</div>

Dear all,

I use ODK collect for the registration of farmers. In my Form I enter information on Name, Area, ID-Number and Photo.

Now I would like to use this information and a mobile ID-Card-Printer to print Farmer-ID-Cards visualizing the collected data directly in the field. Is there any option to print further information (Name, Photo, etc.) with the Zebra QR-Code Printing tool? Can the format-dimensions be adjusted? Does anyone know a mobile ID Card printer which could be connected to ODK?

Thanks for your help and warm regards!

---

<div class="post-metadata">

**Author:** ![yanokwa](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/yanokwa/32/1695_2.png) [@yanokwa](https://forum.getodk.org/u/yanokwa)\
**Post date:** [June 16, 2017, 9:57pm UTC](https://forum.getodk.org/t/printing-id-cards/6904/2 "2017-06-16T21:57:53Z")

</div>

In ye olde days of ODK Clinic, I was able to generate a PDF and send that to a printer on the network and it was super useful.

It looks like it's definitely possible to print from Android these days using [CloudPrint](https://www.howtogeek.com/165778/everything-you-need-to-know-about-printing-from-your-android-phone-or-tablet/), so it's just a matter of seeing who else wants this feature and how best to implement it.

@margaret_wambui would a feature like this be useful to you?

---

<div class="post-metadata">

**Author:** ![Margaret\_Wambui](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/margaret_wambui/32/8146_2.png) [@Margaret\_Wambui](https://forum.getodk.org/u/Margaret_Wambui)\
**Post date:** [June 18, 2017, 12:50pm UTC](https://forum.getodk.org/t/printing-id-cards/6904/3 "2017-06-18T12:50:20Z")

</div>

I would definitely use this feature. The best part is I get to print many  
records at once.  
This is a good feature to implement.  
Thanks Yaw

---

<div class="post-metadata">

**Author:** ![LN](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ln/32/1605_2.png) [@LN](https://forum.getodk.org/u/LN)\
**Post date:** [November 30, 2023, 1:14am UTC](https://forum.getodk.org/t/printing-id-cards/6904/6 "2023-11-30T01:14:37Z")

</div>

🖨 We have now picked this up and are planning to add a form field that makes it possible to render and print HTML to any connected printer. Form designers will build HTML strings using the `concat` function and references to other form fields. They will be able to use any HTML functionality including styling, images, tables, etc. @grzegorz has built a nice prototype already!

## QR codes

We are planning to add a custom `qrcode` element. Any text between the opening and closing `qrcode` tags would be encoded as a QR code and embedded into the HTML.

We want to make it possible to specify the pixel size of the QR code. Although QR codes must always be square, we are currently thinking we'll have users specify values for standard `width` and `height` image attributes so we can pass them through to the `img` that we generate.

For example, to include values for the `first_name` and `last_name` fields separated by a space and display it as a 150x150 square, the following expression would go in `calculate`:

```java
concat("<qrcode width='150' height='150'>", 
${first_name}, " ", ${last_name}, 
"</qrcode>")

```

Form designers would be able to specify full HTML including `html`, `body`, etc or just a snippet like the one above.

## More complex example

Here's an example that includes a QR code with form data, an image, and a summary table:

```html
concat(""
<qrcode width='150' height='150'>First name: "", ${first_name}, ""Last name: "", ${last_name}, ""Age: "", ${age}, ""Email: "", ${email}, ""Phone number: "", ${phone_number}, ""</qrcode></br>
<img width='150' height='150' src=’”, ${photo}, “’>
<table>
<tr>
<td>First name</td>
<td>"", ${first_name}, ""</td>
</tr>
<tr>
<td>Last name</td>
<td>"", ${last_name}, ""</td>
</tr>
<tr>
<td>Age</td>
<td>"", ${age}, ""</td>
</tr>
<tr>
<td>Email</td>
<td>"", ${email}, ""</td>
</tr>
<tr>
<td>Phone number</td>
<td>"", ${phone_number}, ""</td>
</tr>
</table>""
)

```

## User experience

After tapping the `Print` button, users would see a preview using the standard Android print dialog:

 ![Screenshot_20231129_170231](https://getodk.b-cdn.net/uploads/default/original/3X/5/d/5d472d16e0379906f1adbee3517f2db653ea5634.png)

They would have the option to print to any connected printer or save as PDF.

## Future enhancements

It's not very fun to write HTML using the `concat` function. 🙈 One thing we'd like to eventually do is to make it easier to express template strings in which form data should be filled in. This will not only benefit this new feature but also make it easier to write things like `instance_name` expressions.

## Questions

- Does the `qrcode` custom element seem like a reasonable way of specifying a qr code?
- Does specifying the width and height of qr codes seem overly confusing if they're always intended to be the same? Is it worth doing something more custom here?
- We initially thought of also making it possible to generate traditional barcodes but it seems like qr codes are almost always preferable. Is there a good reason to consider barcodes as well?
- Do you or someone you know have a special-format printer that can be added as an Android printer (e.g. a label printer) that they would be willing to test with?

---

<div class="post-metadata">

**Author:** ![Xiphware](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/xiphware/32/2587_2.png) [@Xiphware](https://forum.getodk.org/u/Xiphware)\
**Post date:** [November 30, 2023, 3:01am UTC](https://forum.getodk.org/t/printing-id-cards/6904/7 "2023-11-30T03:01:20Z")

</div>

> [@LN](#):
>
> Does the `qrcode` custom element seem like a reasonable way of specifying a qr code?

Being able to _generate_ a QRcode seems like something that could potentially be useful in a bunch of different contexts; eg generating and uploading a QRCode. Have you considered using the regular XLSForm `image` type [actually, XForm `type='binary'` binding], with perhaps a suitable calculate using your new `qrcode(<string>)` function that generates binary image data?

Generating a QRcode image _inside HTML_ with a special new element feels a bit odd/non-orthogonal wrt XForms. 🤔 Although in this specific case it would serve the purpose.

---

<div class="post-metadata">

**Author:** ![LN](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ln/32/1605_2.png) [@LN](https://forum.getodk.org/u/LN)\
**Post date:** [November 30, 2023, 10:37pm UTC](https://forum.getodk.org/t/printing-id-cards/6904/8 "2023-11-30T22:37:09Z")

</div>

> [@Xiphware](#):
>
> Have you considered using the regular XLSForm `image` type [actually, XForm `type='binary'` binding], with perhaps a suitable calculate using your new `qrcode(<string>)` function that generates binary image data?

We had not considered that! I agree with you that QR codes can be used in a lot of different ways. I wonder, though, whether users would really want to have them be created by Collect if they're going to use them after submission. It seems they'd need to take some other action with submitted data and they could generate the barcodes then. I'd be interested in more concrete examples of use cases if we consider that route.

> [@Xiphware](#):
>
> Generating a QRcode image _inside HTML_ with a special new element feels a bit odd/non-orthogonal wrt XForms. 🤔

I agree that it's not very connected to the XForms spec. I think that's ok? It's more like we're using an existing spec (HTML) to do formatting for printing and we're introducing a [custom element](https://developer.mozilla.org/en-US/docs/Web/API/Web_components#custom_elements) as part of that.

If we introduced a `qrcode` function that returns binary instead I imagine we'd need form authors to build up HTML for an img with a data URL for its src? We'd need to introduce `base64-encode` as well, I think. That feels like it could be more complex.

---

<div class="post-metadata">

**Author:** ![ahblake](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ahblake/32/22392_2.png) [@ahblake](https://forum.getodk.org/u/ahblake)\
**Post date:** [December 17, 2023, 7:30am UTC](https://forum.getodk.org/t/printing-id-cards/6904/9 "2023-12-17T07:30:47Z")

</div>

> [@LN](#):
>
> They would have the option to print to any connected printer or **save as PDF**.

My mind is running away a little with half baked possibilities for this function and I probably shouldn't, but...

Would this work with a repeat with an unknown count (for each repeat, show the choice/text/image etc) - some kind of loop n times where n = repeat count.

If so, I could produce a fairly bare bones PDF summary report of the submission / part of the submission, if it was needed locally, outside of uploading and other systems producing that report.

I'm not convinced this is a good use case for me, but I'm interested in looking at the ability to create a formatted print output further.

---

<div class="post-metadata">

**Author:** ![ashnoor](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ashnoor/32/23987_2.png) [@ashnoor](https://forum.getodk.org/u/ashnoor)\
**Post date:** [December 17, 2023, 8:07pm UTC](https://forum.getodk.org/t/printing-id-cards/6904/10 "2023-12-17T20:07:03Z")

</div>

This feature addition really looks awesome to me, can you please give some use case instances in places like Nigeria and India especially on health or humanitarian data collection?

---

<div class="post-metadata">

**Author:** ![Grzesiek2010](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/grzesiek2010/32/2881_2.png) [@Grzesiek2010](https://forum.getodk.org/u/Grzesiek2010)\
**Post date:** [December 29, 2023, 3:23pm UTC](https://forum.getodk.org/t/printing-id-cards/6904/11 "2023-12-29T15:23:40Z")

</div>

> [@ahblake](#):
>
> Would this work with a repeat with an unknown count (for each repeat, show the choice/text/image etc) - some kind of loop n times where n = repeat count.

I believe this should be possible. This would require for example generating a single row for every repeat that afterwards would be put together and create a table (in HTML). Such a table could be printed. This is a nice example of what we can achieve with this feature so once it is released I will try to provide such a sample form with repeats.

---

<div class="post-metadata">

**Author:** ![LN](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ln/32/1605_2.png) [@LN](https://forum.getodk.org/u/LN)\
**Post date:** [January 4, 2024, 11:38pm UTC](https://forum.getodk.org/t/printing-id-cards/6904/12 "2024-01-04T23:38:11Z")

</div>

> [@ashnoor](#):
>
> can you please give some use case instances in places like Nigeria and India especially on health or humanitarian data collection?

One specific use case we are aiming to support is an offline clinical trial in which samples need to go from a clinic to a lab facility. Two forms will be used: an intake form in the clinic and a sample processing form at the lab. The intake form will be used to print out information about the sample(s) collected including a qrcode. The lab will scan the qr code in the sample processing form. This will make it possible for the sample processing form to use information from the intake form. In analysis, it will also enable linking submissions to the two forms about the same sample.

This is closely related to the work that we are doing with [Entities](https://docs.getodk.org/central-entities/) which help represent a person/place/thing across form submissions. In a context with reliable internet, Entities could be used to meet the same need. Later this year it will be possible to link form submissions through Entities within a single device but using a printout as outlined above will continue to be useful for workflows that have multiple steps performed by different people who are all offline.

This functionality is now available in [Collect v2024.1](https://forum.getodk.org/t/odk-collect-v2024-1/45170). You can find its documentation [here](https://docs.getodk.org/form-question-types/#printer-widget).
