Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
149448 | Nov 26,2019 08:10 PM UTC | Jan 3,2020 11:32 AM UTC | Xamarin.Forms | 3 |
![]() |
Tags: PDF |
//Create a new PDF document
PdfDocument document = new PdfDocument();
//Add a page
PdfPage page = document.Pages.Add();
//Create a PdfLightTable
PdfLightTable pdfLightTable = new PdfLightTable();
//Create a data table
DataTable dataTable = new DataTable();
//Add columns to data table
dataTable.Columns.Add("Text");
dataTable.Columns.Add("Image");
//Add rows to data table
dataTable.Rows.Add("Adventure Cycle", "");
//Assign data source
pdfLightTable.DataSource = dataTable;
pdfLightTable.BeginCellLayout += pdfLightTable_BeginCellLayout;
pdfLightTable.BeginRowLayout += PdfLightTable_BeginRowLayout;
pdfLightTable.Style.ShowHeader = true;
//Draw light table to the page of PDF document
pdfLightTable.Draw(page, new RectangleF(0, 50, page.GetClientSize().Width, page.GetClientSize().Height)); |
private void PdfLightTable_BeginRowLayout(object sender, BeginRowLayoutEventArgs args)
{
if (args.RowIndex == 0)
args.MinimalHeight = 100;
}
private void pdfLightTable_BeginCellLayout(object sender, BeginCellLayoutEventArgs args)
{
//Draw image in the same cell
if (args.RowIndex==0 && args.CellIndex == 1)
{
//Load the image as stream
Stream imageStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Image.jpg");
PdfBitmap image = new PdfBitmap(imageStream);
//Draw image
args.Graphics.DrawImage(image, args.Bounds.X, args.Bounds.Y , args.Bounds.Width, args.Bounds.Height);
}
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.