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 qpdfpandoc -s eg1.md -o eg1.pdfqpdf eg1.pdf --add-attachment eg1.md -- out.pdfqpdf --list-attachments ../out.pdfeg1.md -> 146,0
qpdf --show-attachment=eg1.md ../out.pdf > fromPDF.mddiff fromPDF.md ../eg1.mdI'm very grateful to Brian for pointing out QPDF to me when I went asking about attaching files to PDFs. Thanks, Brian!