// Create a pdf file stream using FileStream outputStream = new FileStream("ProductProfileReport.pdf", FileMode.Create); //create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); Stream fileStream = this.GetResourceStream("xlsx\\ProductProfile Excel.xlsx"); workbook.Open(fileStream); IWorksheet worksheet = workbook.Worksheets[0]; //NOTE: To use this feature, you should have valid license for Document Solutions for PDF. //Create a pdf document. GrapeCity.Documents.Pdf.GcPdfDocument doc = new GrapeCity.Documents.Pdf.GcPdfDocument(); doc.Load(this.GetResourceStream("Product Profile Blank Table.pdf")); //Create a PrintManager. GrapeCity.Documents.Excel.PrintManager printManager = new GrapeCity.Documents.Excel.PrintManager(); //Draw the contents of the sheet1 to the first page. IRange printArea1 = workbook.Worksheets[0].Range["A2:B15"]; SizeF size1 = printManager.GetSize(printArea1); RectangleF position1 = doc.FindText(new GrapeCity.Documents.Pdf.FindTextParams("Key Information", true, true), new GrapeCity.Documents.Common.OutputRange(1, 1))[0].Bounds[0].ToRect(); printManager.Draw(doc.Pages[0], new RectangleF(position1.X, position1.Y + 30, size1.Width, size1.Height), printArea1); //Draw the contents of the sheet3 to the first page. IRange printArea3 = workbook.Worksheets[2].Range["A2:E7"]; SizeF size3 = printManager.GetSize(printArea3); RectangleF position3 = doc.FindText(new GrapeCity.Documents.Pdf.FindTextParams("Returns after fees (at 31-8-2020)", true, true), new GrapeCity.Documents.Common.OutputRange(1, 1))[0].Bounds[0].ToRect(); printManager.Draw(doc.Pages[0], new RectangleF(position3.X, position3.Y + 35, size3.Width, size3.Height), printArea3); //Draw the contents of the sheet3 to the first page. IRange printArea4 = workbook.Worksheets[2].Range["A12:E14"]; SizeF size4 = printManager.GetSize(printArea4); RectangleF position4 = doc.FindText(new GrapeCity.Documents.Pdf.FindTextParams("Asset allocation (at 31-7-2020)", true, true), new GrapeCity.Documents.Common.OutputRange(1, 1))[0].Bounds[0].ToRect(); printManager.Draw(doc.Pages[0], new RectangleF(position4.X, position4.Y + 25, size4.Width, size4.Height), printArea4); //Draw the contents of the sheet3 to the first page. IRange printArea5 = workbook.Worksheets[2].Range["A17:E22"]; SizeF size5 = printManager.GetSize(printArea5); RectangleF position5 = doc.FindText(new GrapeCity.Documents.Pdf.FindTextParams("Fees", true, true), new GrapeCity.Documents.Common.OutputRange(1, 1))[0].Bounds[0].ToRect(); printManager.Draw(doc.Pages[0], new RectangleF(position5.X, position5.Y + 20, size5.Width, size5.Height), printArea5); //Save the modified pages into pdf file. doc.Save(outputStream); // close the pdf stream outputStream.Close();
' Create a pdf file stream Dim outputStream = File.Create("ProductProfileReport.pdf") ' Create a new Workbook Dim workbook As New Workbook Dim fileStream As Stream = GetResourceStream("ProductProfile Excel.xlsx") workbook.Open(fileStream) Dim worksheet As IWorksheet = workbook.Worksheets(0) 'NOTE: To use this feature, you should have valid license for Document Solutions for PDF. 'Create a pdf document. Dim doc As New GcPdfDocument doc.Load(GetResourceStream("Product Profile Blank Table.pdf")) 'Create a PrintManager. Dim printManager As New Excel.PrintManager 'Draw the contents of the sheet1 to the first page. Dim printArea1 As IRange = workbook.Worksheets(0).Range("A2:B15") Dim size1 As SizeF = printManager.GetSize(printArea1) Dim position1 As RectangleF = doc.FindText( New FindTextParams("Key Information", True, True), New Common.OutputRange(1, 1))(0).Bounds(0).ToRect() printManager.Draw( doc.Pages(0), New RectangleF(position1.X, position1.Y + 30, size1.Width, size1.Height), printArea1) 'Draw the contents of the sheet3 to the first page. Dim printArea3 As IRange = workbook.Worksheets(2).Range("A2:E7") Dim size3 As SizeF = printManager.GetSize(printArea3) Dim position3 As RectangleF = doc.FindText( New FindTextParams("Returns after fees (at 31-8-2020)", True, True), New Common.OutputRange(1, 1))(0).Bounds(0).ToRect() printManager.Draw( doc.Pages(0), New RectangleF(position3.X, position3.Y + 35, size3.Width, size3.Height), printArea3) 'Draw the contents of the sheet3 to the first page. Dim printArea4 As IRange = workbook.Worksheets(2).Range("A12:E14") Dim size4 As SizeF = printManager.GetSize(printArea4) Dim position4 As RectangleF = doc.FindText( New FindTextParams("Asset allocation (at 31-7-2020)", True, True), New Common.OutputRange(1, 1))(0).Bounds(0).ToRect() printManager.Draw( doc.Pages(0), New RectangleF(position4.X, position4.Y + 25, size4.Width, size4.Height), printArea4) 'Draw the contents of the sheet3 to the first page. Dim printArea5 As IRange = workbook.Worksheets(2).Range("A17:E22") Dim size5 As SizeF = printManager.GetSize(printArea5) Dim position5 As RectangleF = doc.FindText( New FindTextParams("Fees", True, True), New Common.OutputRange(1, 1))(0).Bounds(0).ToRect() printManager.Draw( doc.Pages(0), New RectangleF(position5.X, position5.Y + 20, size5.Width, size5.Height), printArea5) 'Save the modified pages into pdf file. doc.Save(outputStream) ' close the pdf stream outputStream.Close()