Here's a demo that uses QPDF to embed the markdown source code of a file into the PDF generated by pandoc.
Using the example markdown file from the Markdown to reStructuredText example at https://pandoc.org/try/
I'm able to use pandoc to produce eg1.pdf and then attach eg1.md to eg1.pdf creating out.pdf. Notice in step 4 that the list of attachements output is shown:
nix-shell -p pandoc qpdf
pandoc -s eg1.md -o eg1.pdf
qpdf eg1.pdf --add-attachment eg1.md -- out.pdf
qpdf --list-attachments ../out.pdf
eg1.md -> 146,0
qpdf --show-attachment=eg1.md ../out.pdf > fromPDF.md
diff fromPDF.md ../eg1.md
I'm very grateful to Brian for pointing out QPDF to me when I went asking about attaching files to PDFs. Thanks, Brian!