How can I export an iMessage conversation to .txt or .pdf from Mac?
First, make an iTunes backup, then find your iTunes backup folder:

macOS

~/Library/Application Support/MobileSync/Backup/


Windows

%appdata%/Roaming/Apple Computer/MobileSync/Backup


There will be one randomly named folder, except you have backed up more devices with iTunes. In that folder, there is database file with your messages.

You can open it using free SQLite database viewer and/or export the contents to CSV file format.



If you have a mac, you can simply


open Messages app
sign in (if you are not)
select the particular conversation
File > Print > Save (output will be in PDF)


The result doesn't look great, but it does contain all the images and the text is searchable.

Your messages database is stored in ~/Library/Messages/ under chat.db, so you can export it  using SQLite database viewer as stated above, but the pictures and other files are stored in ~/Library/Messages/Attachments.