Xamarin Forms, PDF ListView Using PDFSampleListRendererDelegate
Amasu
96
Reputation points
Hi Xamarin Forms Community,
I am desing a PDF from a listview, but I have a question about the margin of the image attachment
I will put the code here:
public class PDFSampleListRendererDelegate : PdfListViewRendererDelegate
{
public override void DrawCell(ListView listView, int section, int row, XGraphics page, XRect bounds, double scaleFactor)
{
var boundPrincipal = new XRect();
boundPrincipal.Width = 170;
boundPrincipal.Height = 100;
var bound2 = new XRect();
bound2.Width = 200;
bound2.Height = 100;
XPen xpen = new XPen(XColor.FromArgb(128, 0, 0));
bounds.Width = 190;
page.DrawRectangle(xpen, bounds);
string producto = "Producto";
string cantidad = "Cantidad";
string precio = "Precio";
string total = "Total";
XFont font = new XFont("times" ?? GlobalFontSettings.FontResolver.DefaultFontName, 8);
page.DrawString(producto, font, XBrushes.Black, boundPrincipal,
new XStringFormat
{
LineAlignment = XLineAlignment.Near,
Alignment = XStringAlignment.Near
});
page.DrawString(cantidad, font, XBrushes.Black, boundPrincipal,
new XStringFormat
{
LineAlignment = XLineAlignment.Near,
Alignment = XStringAlignment.Center
});
page.DrawString(precio, font, XBrushes.Black, boundPrincipal,
new XStringFormat
{
LineAlignment = XLineAlignment.Near,
Alignment = XStringAlignment.Far
});
page.DrawString(total, font, XBrushes.Black, bound2,
new XStringFormat
{
LineAlignment = XLineAlignment.Near,
Alignment = XStringAlignment.Far
});
var yourObject = (listView.ItemsSource as List<Order>).ElementAt(row);
page.DrawString(yourObject.Description, font, XBrushes.Black, bounds,
new XStringFormat
{
Alignment = XStringAlignment.Near
});
page.DrawString(yourObject.Quantity.ToString(), font, XBrushes.Black, bounds,
new XStringFormat
{
Alignment = XStringAlignment.Center
});
page.DrawString("$" + yourObject.Price.ToString(), font, XBrushes.Black, bounds,
new XStringFormat
{
Alignment = XStringAlignment.Far
});
page.DrawString("$" + yourObject.Total.ToString(), font, XBrushes.Black, bounds,
new XStringFormat
{
Alignment = XStringAlignment.Far,
});
}
Thanks
Regards
Sign in to answer