Xamarin Forms, PDF ListView Using PDFSampleListRendererDelegate

Amasu 96 Reputation points
2021-01-26T22:17:15.57+00:00

Hi Xamarin Forms Community,

I am desing a PDF from a listview, but I have a question about the margin of the image attachment 60630-imagen1.png

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

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,336 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,842 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.