Output graphics rendered by glBegin () and glEnd () as PDF

For example,

ofApp.cpp

glBegin(GL_LINES);
glVertex2f(10, 15);
glVertex2f(20, 200);
glEnd();

How can I output this code written in ofApp.cpp in PDF like this.