The exported pdf is dependent on the width of the plot window. Remove code related to change of resolution when exporting to PDF. This makes the PDF export consistent and independent to width of view.
Crash seen on Windows related to theme change as part of export to PDF. This is related to export of plots to PDF in dark mode. Investigate other solution.