Skip to contentSkip to conversation

Embed files as PDF attachments

RFC PATCH In review Manos Pitsidianakis 2 participants 6 messages Sep 15, 2024

lore
Share & tools
lore
#0 lore raw

cover Embed files as PDF attachments

The PDF specs allow for file attachments to documents. This can be used to make the VIRTIO PDF spec a single source of truth by embedding related files.

This series attaches the virtio-queue.h header file as a proof of concept. It can be inspected and extracted using a compliant PDF viewer such as Adobe's or Firefox's integrated PDF reader.

(Note: I'm not sure if Chrome supports it, my local version does not, neither does Chromium.)

Programmatically extracting files is also possible, allowing for downstream projects to update their headers by accessing the upstream pdf file.

Example using the pdfdetach utility from the Xpdf package of tools (poppler-utils package on debian/ubuntu):

  $ pdfdetach -list virtio-v1.3-csd01.pdf
  1 embedded files
  1: virtio-queue.h
  $ pdfdetach -save 1 virtio-v1.3-csd01.pdf
  $ file virtio-queue.h
  virtio-queue.h: C source, ASCII text

Manos Pitsidianakis (2):
specvars.tex: Add \virtioauthor command
Embed virtio-queue.h as PDF attachment

 commands-html.tex |  7 +++++++
 commands-pdf.tex  | 10 ++++++++++
 headerfile.tex    |  2 ++
 specvars.tex      |  3 ++-
 virtio.tex        |  1 +
 5 files changed, 22 insertions(+), 1 deletion(-)

base-commit: b495841a8e80d12c1130f8868f4128866291142d

Signature · 1 line
γαῖα πυρί μιχθήτω
#1 lore raw

RFC PATCH 1/2 specvars.tex: Add \virtioauthor command

Add a macro that expands to the spec author "OASIS Virtual I/O Device (VIRTIO) TC". This will be used in subsequent commits to define the author of attached files in the pdf build.

---
 specvars.tex | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
specvars.tex +2 -1
index a80557a..7d3c8f7 100644
@@ -1,4 +1,5 @@
 \input{setup-generated.tex}
+\newcommand{\virtioauthor}{OASIS Virtual I/O Device (VIRTIO) TC}
 \newcommand{\virtioversion}{Virtual I/O Device (VIRTIO) Version \virtiorev}
 \newcommand{\virtiospecfile}{virtio-v\virtiorev-\virtiodraftstage\virtioworkingdraft}
 \newcommand{\virtiourlbase}{https://docs.oasis-open.org/virtio/virtio/v\virtiorev/\virtiodraftstage\virtioworkingdraft}
@@ -15,7 +16,7 @@
 
 % PDF setup
 \hypersetup{
-pdfauthor = {OASIS Virtual I/O Device (VIRTIO) TC},
+pdfauthor = {\virtioauthor},
 pdftitle = {Virtual I/O Device (VIRTIO) Version \virtiorev},
 pdfsubject = {Virtual I/O Device (VIRTIO) Version \virtiorev},
 pdfkeywords = {VIRTIO, Virtual I/O Device},
Signature · 1 line
γαῖα πυρί μιχθήτω
#2 lore raw

RFC PATCH 2/2 Embed virtio-queue.h as PDF attachment

In reply to Manos Pitsidianakis

Using the TeX package attachfile2 we're able to attach the C header file as a PDF standards-compliant attachment in the PDF document, allowing it to be a single source of truth for related files.

---
 commands-html.tex |  7 +++++++
 commands-pdf.tex  | 10 ++++++++++
 headerfile.tex    |  2 ++
 virtio.tex        |  1 +
 4 files changed, 20 insertions(+)
commands-html.tex +7 -0
index 488eacb..144bbb2 100644
@@ -180,3 +180,10 @@
 \vspace{0.2in}
 }
 
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%% VIRTIO C header file (.h) PDF attachments - expand to nothing
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\newcommand{\attachsource}[1]{%
+}%
commands-pdf.tex +10 -0
index 23289d8..62d4169 100644
@@ -196,3 +196,13 @@
 \vspace{0.2in}
 }
 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%% VIRTIO C header file (.h) PDF attachments
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\newcommand{\attachsource}[1]{%
+{%
+This file is available as a PDF attachment %
+\attachfile[icon=Paperclip,mimetype=text/x-c,author=\virtioauthor{}]{#1}%
+}%
+}%
headerfile.tex +2 -0
index 767005c..d194031 100644
@@ -1,5 +1,7 @@
 \chapter[virtio_queue.h]{virtio_queue.h}\label{sec:virtio-queue.h}
 \label{sec:virtio-ring.h}
+\attachsource{virtio-queue.h}
+
 This file is also available at the link
 \virtiourlh.
 All definitions in this section are for non-normative reference
virtio.tex +1 -0
index 37e49b1..94f508f 100644
@@ -38,6 +38,7 @@
 \usepackage{underscore}
 \usepackage{xstring}
 \usepackage{enumitem}
+\usepackage{attachfile2}
 \IfFileExists{ellipsis.sty}{\usepackage{ellipsis}}{
 \message{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
 \message{LaTeX Warning: Missing ellipsis.sty: dots (...) will look ugly}
Signature · 1 line
γαῖα πυρί μιχθήτω
#3 lore raw
In reply to Manos Pitsidianakis
Quoted 18 lines · Manos Pitsidianakis

The PDF specs allow for file attachments to documents. This can be used to make the VIRTIO PDF spec a single source of truth by embedding related files.

This series attaches the virtio-queue.h header file as a proof of concept. It can be inspected and extracted using a compliant PDF viewer such as Adobe's or Firefox's integrated PDF reader.

(Note: I'm not sure if Chrome supports it, my local version does not, neither does Chromium.)

Programmatically extracting files is also possible, allowing for downstream projects to update their headers by accessing the upstream pdf file.

Example using the pdfdetach utility from the Xpdf package of tools (poppler-utils package on debian/ubuntu):

Quoted 6 lines
  $ pdfdetach -list virtio-v1.3-csd01.pdf
  1 embedded files
  1: virtio-queue.h
  $ pdfdetach -save 1 virtio-v1.3-csd01.pdf
  $ file virtio-queue.h
  virtio-queue.h: C source, ASCII text

Really cool, thank you Manos!

Quoted 16 lines

Manos Pitsidianakis (2):
specvars.tex: Add \virtioauthor command
Embed virtio-queue.h as PDF attachment

 commands-html.tex |  7 +++++++
 commands-pdf.tex  | 10 ++++++++++
 headerfile.tex    |  2 ++
 specvars.tex      |  3 ++-
 virtio.tex        |  1 +
 5 files changed, 22 insertions(+), 1 deletion(-)

base-commit: b495841a8e80d12c1130f8868f4128866291142d

Signature · 1 line
γαῖα πυρί μιχθήτω
#4 lore raw
Quoted 28 lines · Michael S. Tsirkin
Quoted 18 lines · Manos Pitsidianakis

The PDF specs allow for file attachments to documents. This can be used to make the VIRTIO PDF spec a single source of truth by embedding related files.

This series attaches the virtio-queue.h header file as a proof of concept. It can be inspected and extracted using a compliant PDF viewer such as Adobe's or Firefox's integrated PDF reader.

(Note: I'm not sure if Chrome supports it, my local version does not, neither does Chromium.)

Programmatically extracting files is also possible, allowing for downstream projects to update their headers by accessing the upstream pdf file.

Example using the pdfdetach utility from the Xpdf package of tools (poppler-utils package on debian/ubuntu):

Quoted 6 lines
  $ pdfdetach -list virtio-v1.3-csd01.pdf
  1 embedded files
  1: virtio-queue.h
  $ pdfdetach -save 1 virtio-v1.3-csd01.pdf
  $ file virtio-queue.h
  virtio-queue.h: C source, ASCII text
Quoted 1 line

Really cool, thank you Manos!

Hello Michael,

Forgot to mention on my cover letter: We are interested in this not just for virtio-queue.h but for defining normative definitions of constants and memory layouts of structures for transports/devices. For example if we take all the inline code listings of a device \section and generate a file (to avoid having them checked into source control and have two instances/sources of truth of the definitions, tex and .h files) we can add a final \subsection at the end, for example something like:

(quoted diff) +0 -0

b/device-types/sound/description.tex
index 54c9c8e..d79e66e 100644

device-types/sound/description.tex +0 -0
@@ -1177,3 +1177,9 @@ \subsubsection{Control

Elements}\label{sec:Device Types / Sound Device / Device
\begin{itemize}
\item The device MUST NOT set undefined \field{mask} values. \end{itemize}
+ +\subsection[virtio-snd.h]{virtio-snd.h}\label{sec:virtio-snd.h} +\label{sec:virtio-snd.h}
+\attachsource{virtio-snd.h}
+All definitions in this header file are for normative reference.

Also, I have made changes to show the filename instead of an icon and attached a screenshot of how it appears in my Firefox (with the cursor hovering over the filename link).

Quoted 17 lines
Quoted 16 lines

Manos Pitsidianakis (2):
specvars.tex: Add \virtioauthor command
Embed virtio-queue.h as PDF attachment

 commands-html.tex |  7 +++++++
 commands-pdf.tex  | 10 ++++++++++
 headerfile.tex    |  2 ++
 specvars.tex      |  3 ++-
 virtio.tex        |  1 +
 5 files changed, 22 insertions(+), 1 deletion(-)

base-commit: b495841a8e80d12c1130f8868f4128866291142d --
γαῖα πυρί μιχθήτω

Signature · 2 lines
Manos Pitsidianakis
Emulation and Virtualization Engineer at Linaro Ltd
#5 lore raw
Quoted 52 lines · Manos Pitsidianakis
Quoted 28 lines · Michael S. Tsirkin
Quoted 18 lines · Manos Pitsidianakis

The PDF specs allow for file attachments to documents. This can be used to make the VIRTIO PDF spec a single source of truth by embedding related files.

This series attaches the virtio-queue.h header file as a proof of concept. It can be inspected and extracted using a compliant PDF viewer such as Adobe's or Firefox's integrated PDF reader.

(Note: I'm not sure if Chrome supports it, my local version does not, neither does Chromium.)

Programmatically extracting files is also possible, allowing for downstream projects to update their headers by accessing the upstream pdf file.

Example using the pdfdetach utility from the Xpdf package of tools (poppler-utils package on debian/ubuntu):

Quoted 6 lines
  $ pdfdetach -list virtio-v1.3-csd01.pdf
  1 embedded files
  1: virtio-queue.h
  $ pdfdetach -save 1 virtio-v1.3-csd01.pdf
  $ file virtio-queue.h
  virtio-queue.h: C source, ASCII text
Quoted 1 line

Really cool, thank you Manos!

Hello Michael,

Forgot to mention on my cover letter: We are interested in this not just for virtio-queue.h but for defining normative definitions of constants and memory layouts of structures for transports/devices. For example if we take all the inline code listings of a device \section and generate a file (to avoid having them checked into source control and have two instances/sources of truth of the definitions, tex and .h files) we can add a final \subsection at the end, for example something like:

device-types/sound/description.tex +0 -0
index 54c9c8e..d79e66e 100644
@@ -1177,3 +1177,9 @@ \subsubsection{Control

Elements}\label{sec:Device Types / Sound Device / Device
\begin{itemize}
\item The device MUST NOT set undefined \field{mask} values. \end{itemize}

device-types/sound/description.tex

Quoted 5 lines
device-types/sound/description.tex +5 -0
+
+\subsection[virtio-snd.h]{virtio-snd.h}\label{sec:virtio-snd.h}
+\label{sec:virtio-snd.h}
+\attachsource{virtio-snd.h}
+All definitions in this header file are for normative reference.

Yes, we could import the headers from Linux.

Quoted 3 lines

Also, I have made changes to show the filename instead of an icon and attached a screenshot of how it appears in my Firefox (with the cursor hovering over the filename link).

Sounds good.
Getting ready for LPC so don't have the time to test it properly.

Quoted 23 lines
Quoted 18 lines
Quoted 17 lines

Manos Pitsidianakis (2):
specvars.tex: Add \virtioauthor command
Embed virtio-queue.h as PDF attachment

 commands-html.tex |  7 +++++++
 commands-pdf.tex  | 10 ++++++++++
 headerfile.tex    |  2 ++
 specvars.tex      |  3 ++-
 virtio.tex        |  1 +
 5 files changed, 22 insertions(+), 1 deletion(-)

base-commit: b495841a8e80d12c1130f8868f4128866291142d --
γαῖα πυρί μιχθήτω

Signature · 2 lines
Manos Pitsidianakis
Emulation and Virtualization Engineer at Linaro Ltd