|
|
Call this method to find out the coordinates of PDF page boxes.
If the image is not a PDF document a null rectangle will be
returned.
The rectangle coordinates are top down.
By default when drawing PDF documents the media box is used. The
image bounding box is set to the media box shifted to zero, zero,
i.e. the bounding box is 0,0, mediabox.width, mediabox.height.
You can set the PDF box returned by this method as the selection
in the draw options. If you set the canvas size to the size of the
desired box and position your image as shown in the example you can
draw a specific PDF box.
|
|
|
Here we draw a PDF document twice: using the crop box and the
media box. Note the difference in the output.
[C#]
using (XImage image = XImage.FromFile(Server.MapPath("rez/acrobat.pdf"))) {
DrawOptions drawOpts = new DrawOptions();
XRect pdfBox = image.GetPDFBox(XImage.PdfBoxType.Cropbox);
drawOpts.Selection = pdfBox;
using (Canvas canvas = new Canvas(pdfBox.Width, pdfBox.Height)) {
canvas.DrawImage(image, new XPoint(-pdfBox.X, -pdfBox.Y), drawOpts);
canvas.SaveAs(Server.MapPath("DrawOptions_PdfBox_84_1.png"));
}
pdfBox = image.GetPDFBox(XImage.PdfBoxType.Mediabox);
drawOpts.Selection = pdfBox;
using (Canvas canvas = new Canvas(pdfBox.Width, pdfBox.Height)) {
canvas.DrawImage(image, new XPoint(-pdfBox.X, -pdfBox.Y), drawOpts);
canvas.SaveAs(Server.MapPath("DrawOptions_PdfBox_84_2.png"));
}
}
[Visual Basic]
Using image As XImage = XImage.FromFile(Server.MapPath("rez/acrobat.pdf"))
Dim drawOpts As New DrawOptions()
Dim pdfBox As XRect = image.GetPDFBox(XImage.PdfBoxType.Cropbox)
drawOpts.Selection = pdfBox
Using canvas As New Canvas(pdfBox.Width, pdfBox.Height)
canvas.DrawImage(image, New XPoint(-pdfBox.X, -pdfBox.Y), drawOpts)
canvas.SaveAs(Server.MapPath("DrawOptions_PdfBox_84_1.png"))
End Using
pdfBox = image.GetPDFBox(XImage.PdfBoxType.Mediabox)
drawOpts.Selection = pdfBox
Using canvas As New Canvas(pdfBox.Width, pdfBox.Height)
canvas.DrawImage(image, New XPoint(-pdfBox.X, -pdfBox.Y), drawOpts)
canvas.SaveAs(Server.MapPath("DrawOptions_PdfBox_84_2.png"))
End Using
End Using

DrawOptions_PdfBox_84_1.png

DrawOptions_PdfBox_84_2.png
|