# Barcode fields with hyperref forms

Does a hyperrefextension package exist that allows barcode fields in a hyperrefform?

The barcodefield description can be seen at page 45 in the PDF ISO documentation: ISO3200 barcode fields.

Here is an attempt to generate a qrcode:

\RequirePackage{luatex85}
\documentclass{article}
\usepackage{hyperref}

\begin{document}

\begin{Form}

\TextField{Test}

\pdfannot{%
/P 3
/T(barcode)
/V(foo)
/DA(/Helv 10 Tf 0 0 0 rg)
/DataPrep 0
/MK<</BC[1 0 0]/BG[1 1 1]>>
/PDM<<
/ECC 1
/Symbology/QRCode
/Height 1.0
/Caption()
/Width 1.0
/XSymWidth 5
/XSymHeight 5
/Resolution 300.0
/Version 1
>>
/Subtype/Widget
/F 4
/FT/Tx
}

\end{Form}

\end{document}


However, I am missing something as this only generates a text input field and no barcode.

• You mean as a static image to be scanned? You could probably fake it by wrapping a hyperref around an \includeimage or tikz. Or do you mean dynamic, as referenced in the documentation, "A barcode field dynamically acquires its value through user input into one or more text fields that are referenced in a calculate dictionary". I'm not aware of something for the latter behaviour. – Huang_d Jul 3 '18 at 13:59
• I mean the dynamic version that genereres the Barfoed from data entered in the form. I normally use pst-barcode to generate static barcodes. – Martin Heller Jul 3 '18 at 20:53
• @MartinHeller The problem with your posted code is a simple typo: It has to be /PMD instead of /PDM. Another problem which is ignored by Acrobat: After /P you need a indirect reference to the page object containing the annotation, this would have to look like 3 0 R instead of just 3. Then your barcode is displayed but it is in the middle of the page and distorted... There are some additional smaller problems but there is an easy fix: Some hours ago I uploaded a new package hyperbar for barcode fields to the CTAN. Once it is available I will add an answer. – Marcel Krüger Jul 5 '18 at 0:36
• @MarcelKrüger thank you for identifying the problem and for providing a package fixing the issue! – Martin Heller Jul 5 '18 at 5:04
• @MarcelKrüger I trues the hyperbar package and it works as expected. However, I can only view the barcodes in PDF-XChangeViewer. In Adobe Reader I ser only gray squares/rectangles. Do you know if a special configuration of Adobe Reader is required for rendering the barcodes? – Martin Heller Jul 5 '18 at 18:10

You can use the package hyperbar:

\ifx\pdfobj\undefined
\RequirePackage{luatex85}
\fi
\documentclass{article}
\usepackage{hyperref,hyperbar}

\begin{document}

\begin{Form}

\TextField{Test}

\BarcodeField[qr,width=3cm,height=3cm,tsv={Test}]{Some Name}

\end{Form}

\end{document}


Here the tsv={Test} indicates to encode the value of the Test field in the barcode. If you want to encode a static value, you can use value={Some value} instead, but then I would recommend using another package generating static barcodes instead.

Sadly barcode form fields are not part of ISO PDF. The specification mentioned in the uestion is not the ISO PDF documentation, it is the documentation for the third set of proprietary Adobe extensions to PDF 1.7. While some features from this document became part of the new PDF/2 standard, this does not apply to barcode fields according to PDFlib.

As an Adobe extension support for these fields in PDF viewers is poor. In a comment you mentioned being able to view the barcodes in PDF-XChangeViewer, so this may be the only free reader supporting barcode fields. While barcode fields work with the commercial versions of Acrobat, the functionality is disabled in Adobe's free Acrobat Reader.