convert -density 288 test.jpg test.pdf
You can use density higher than 288 to get better quality. But in my experience, 288 should be enough for most cases.
To extract high quality jpeg image from pdf files, we can use the tool Gimp. First import the pdf into gimp, using resolution at least 300 pixels/inch (the default value is 100, which is too low). Use resolution of 600 or 1200 to get very high quality images. Then use the rectangular tool to select and paste the region into a new image, and save it as jpeg file.