How do I export the smallest bounding rectangle that contains content to JPEG?

Q: While rasterizing a PDF to jpeg how would I

1. Export the full page to jpg (including will the whitespace)
2. Export the smallest bounding rectangle that contains all of the
data

I am currently doing this (which would this produce?)

                    using (PDFDraw draw = new PDFDraw())
                    {
                        try
                        {
                            using (PDFDoc doc = new
PDFDoc(file.FullName))
                            {
                                doc.InitSecurityHandler();

                                draw.SetDPI(dpi);
                                Page pg = doc.GetPage(1);
                                draw.Export(pg, newfile, "JPEG");
                            }
                        }
                        catch (PDFNetException e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
---------------
A: How about using page.GetBoundingBox()?

GetBoundingBox() returns that content bounding box which is defined as
the smallest rectangle that includes all the visible content on the
page.

For example:

Page pg = doc.GetPage(1);
pg.SetCropBox(pg GetBoundingBox());
draw.Export(pg, newfile, "JPEG");