Properties are a great addition to Obsidian! Nevertheless, it would be great to have the option to export them to PDF, too, as some stuff we used to keep on the note body we can put on metadata (e.g., tags, related notes, etc.), potentially losing track of them on exported PDFs.
Proposed solution
Implementing the “Include file properties” option in the PDF modal would be great!
First one using DQL listing all fields as a table:
TABLE WITHOUT ID file.frontmatter AS Properties
WHERE file.name = this.file.name
Second one using JavaScript (more versatile as you can exclude certain fields that you do not want to export, but also much more involved):
// Retrieve the current file's frontmatter
let frontmatter = dv.current().file.frontmatter;
// Define fields to exclude (adapt as necessary)
let excludeFields = ['tags', 'created']
// Extract and filter the keys and values based on the exclusion list
let filtered_keys = Object.keys(frontmatter).filter(key => ! excludeFields.includes(key));
let filtered_values = filtered_keys.map(key => frontmatter[key]);
// Define an array to hold each row of the table
let rows = [];
// Populate the rows array with key-value pairs
for (let i = 0; i < filtered_keys.length; i++) {
// Convert array values (e.g. tags) to a single string separated by commas
let value = Array.isArray(filtered_values[i]) ? filtered_values[i].join(', ') : filtered_values [i];
rows.push([filtered_keys[i], value])
}
// Generate a table with two columns and populate with rows
dv.table(['Properties', 'Values'], rows)