//Create a new PDF document
PdfDocument pdfDocument = new PdfDocument();
var options = new PdfExportingOptions();
var pdfPage = pdfDocument.Pages.Add();
var PDFGrid = sfDataGrid.ExportToPdfGrid(sfDataGrid.View, options);
var format = new PdfGridLayoutFormat()
{
Layout = PdfLayoutType.Paginate,
Break = PdfLayoutBreakType.FitPage
};
PDFGrid.Draw(pdfPage, new PointF(0, 100), format);
//Create a header and draw the image
RectangleF bounds = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 50);
PdfPageTemplateElement header = new PdfPageTemplateElement(bounds);
PdfImage image = new PdfBitmap(@"../../Data/Logo.png");
//Draw the image in the header
header.Graphics.DrawImage(image, new PointF(0, 0), new SizeF(100, 50));
//Add the header at the top
pdfDocument.Template.Top = header;
//Barcode
PdfCode128BBarcode barcode = new PdfCode128BBarcode();
barcode.Text = "VVPU DPO";
barcode.TextDisplayLocation = TextLocation.Bottom;
barcode.BarHeight = 30;
barcode.Draw(pdfPage, new PointF(400, 0));
//Save and close the document
pdfDocument.Save("Output.pdf");
pdfDocument.Close(true);
Process.Start("Output.pdf"); |