public void GenerateChart(bool showBarCode, string extraData, Stream output) { var pageRect = new Rectangle((float) ConvertUtil.INToPdf(10.5), (float) ConvertUtil.INToPdf(12.48)); var maxElements = CalculateTotalPatchesPerPage(pageRect); var barSize = (float) maxElements.ColumnNumber * PatchSize; var dataProvider = new ExcelDataProvider(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\pe34483.xls")); bool firstPage = true; using (var pdfDoc = new Document(pageRect)) { var writer = PdfWriter.GetInstance(pdfDoc, output); pdfDoc.Open(); using (var reader = dataProvider.GetDataReader()) { if (!reader.Read()) return; while (reader.Read()) { if (!firstPage) { pdfDoc.NewPage(); } var canvas = writer.DirectContent; var upBarPoint = DrawUpperRectangle(canvas, pageRect, barSize); var chartPoint = new Point(upBarPoint.X, (upBarPoint.Y - PosBar2Chart) + BarHeight); var endUpBarPoint = new Point(upBarPoint.X + barSize, upBarPoint.Y); DrawPatches(pageRect, canvas, chartPoint, endUpBarPoint, maxElements, reader); DrawPageBorder(writer, pdfDoc, canvas); if (showBarCode) { DrawBarCode(canvas, pageRect); } firstPage = false; } } pdfDoc.Close(); } }