pythonpdfflaskmetadatalilypond

Can I scpecify or get Abjad (v3.2) output PDF file's path or name after creating it?


I have a flask server that generates musical PDFs with abjad v3.2.

After using abjad.show(), I would like to get the path to the created file. I can get the output directory, by using abjad.Configuration().abjad_output_directory but not the specific file I created.

My question is how can I get the path to the file (not the folder but the specific file) I just created in order to send it back to the user?

My python code that creates the PDF file:

staff = abjad.Staff(abjad_notes)

# attach BPM to notes file
metronome_mark = abjad.MetronomeMark((1, 4), bpm)
abjad.attach(metronome_mark, staff[0])

# creates lilypond file object
lilypond_file = abjad.LilyPondFile.new(staff)

# notes title
lilypond_file.header_block.title = abjad.Markup(title)

# show PDF on screen
abjad.show(lilypond_file)

Solution

  • In Abjad 3.2, you can use abjad.persist to manually set the output path of the .ly and .pdf files generated by Abjad (as opposed to letting Abjad create them in the default folder ~/.abjad/output).

    To use it, first create a lilypond_file variable which instantiates abjad.LilyPondFile and then use it as abjad.persist.as_pdf(lilypond_file, '/path/to/file.pdf'). In your minimal example above, this becomes:

    staff = abjad.Staff(abjad_notes)
    
    # attach BPM to notes file
    metronome_mark = abjad.MetronomeMark((1, 4), bpm)
    abjad.attach(metronome_mark, staff[0])
    
    # creates lilypond file object
    lilypond_file = abjad.LilyPondFile.new(staff)
    
    # notes title
    lilypond_file.header_block.title = abjad.Markup(title)
    
    # save pdf file at a custom location
    abjad.persist.as_pdf(lilypond_file, '/path/to/file.pdf')