// Create a pdf file stream FileStream outputStream = new FileStream("RenderExcelRangesInsideAPDF.pdf", FileMode.Create); //create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); Stream fileStream = this.GetResourceStream("xlsx\\FinancialReport.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("Acme-Financial Report 2018.pdf")); if (doc.Pages.Count < 6) { Console.WriteLine("No Document Solutions for PDF product license."); return; } //Create a PrintManager. GrapeCity.Documents.Excel.PrintManager printManager = new GrapeCity.Documents.Excel.PrintManager(); //Draw the contents of the sheet3 to the fourth page. IRange printArea1 = workbook.Worksheets[2].Range["A3:C24"]; SizeF size1 = printManager.GetSize(printArea1); RectangleF position1 = doc.FindText(new GrapeCity.Documents.Pdf.FindTextParams("Proposition enhancements are", true, true), new GrapeCity.Documents.Common.OutputRange(4, 4))[0].Bounds[0].ToRect(); printManager.Draw(doc.Pages[3], new RectangleF(position1.X + position1.Width + 70, position1.Y, size1.Width, size1.Height), printArea1); //Draw the contents of the sheet1 to the fifth page. IRange printArea2 = workbook.Worksheets[0].Range["A4:E29"]; SizeF size2 = printManager.GetSize(printArea2); RectangleF position2 = doc.FindText(new GrapeCity.Documents.Pdf.FindTextParams("expenditure, an improvement in working", true, true), new GrapeCity.Documents.Common.OutputRange(5, 5))[0].Bounds[0].ToRect(); printManager.Draw(doc.Pages[4], new RectangleF(position2.X, position2.Y + position2.Height + 20, size2.Width, size2.Height), printArea2); //Draw the contents of the sheet2 to the sixth page. IRange printArea3 = workbook.Worksheets[1].Range["A2:E28"]; SizeF size3 = printManager.GetSize(printArea3); RectangleF position3 = doc.FindText(new GrapeCity.Documents.Pdf.FindTextParams("company will be able to continue", true, true), new GrapeCity.Documents.Common.OutputRange(6, 6))[0].Bounds[0].ToRect(); printManager.Draw(doc.Pages[5], new RectangleF(position3.X, position3.Y + position3.Height + 20, doc.Pages[5].Size.Width - position3.X * 2 - 10, size3.Height), printArea3); //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("RenderExcelRangesInsideAPDF.pdf") ' Create a new Workbook Dim workbook As New Workbook Dim fileStream As Stream = GetResourceStream("FinancialReport.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("Acme-Financial Report 2018.pdf")) If doc.Pages.Count < 6 Then Console.WriteLine("No Document Solutions for PDF product license.") Return End If 'Create a PrintManager. Dim printManager As New Excel.PrintManager 'Draw the contents of the sheet3 to the fourth page. Dim printArea1 As IRange = workbook.Worksheets(2).Range("A3:C24") Dim size1 As SizeF = printManager.GetSize(printArea1) Dim position1 As RectangleF = doc.FindText( New FindTextParams("Proposition enhancements are", True, True), New Common.OutputRange(4, 4))(0).Bounds(0).ToRect() printManager.Draw( doc.Pages(3), New RectangleF(position1.X + position1.Width + 70, position1.Y, size1.Width, size1.Height), printArea1) 'Draw the contents of the sheet1 to the fifth page. Dim printArea2 As IRange = workbook.Worksheets(0).Range("A4:E29") Dim size2 As SizeF = printManager.GetSize(printArea2) Dim position2 As RectangleF = doc.FindText( New FindTextParams("expenditure, an improvement in working", True, True), New Common.OutputRange(5, 5))(0).Bounds(0).ToRect() printManager.Draw( doc.Pages(4), New RectangleF(position2.X, position2.Y + position2.Height + 20, size2.Width, size2.Height), printArea2) 'Draw the contents of the sheet2 to the sixth page. Dim printArea3 As IRange = workbook.Worksheets(1).Range("A2:E28") Dim size3 As SizeF = printManager.GetSize(printArea3) Dim position3 As RectangleF = doc.FindText( New FindTextParams("company will be able to continue", True, True), New Common.OutputRange(6, 6))(0).Bounds(0).ToRect() printManager.Draw( doc.Pages(5), New RectangleF(position3.X, position3.Y + position3.Height + 20, doc.Pages(5).Size.Width - (position3.X * 2) - 10, size3.Height), printArea3) 'Save the modified pages into pdf file. doc.Save(outputStream)