Hi,
I have used your sample code Embed a Grid into a Grid Cell in PDF at the https://www.e-iceblue.com/Knowledgebase/Spire.PDF/Spire.PDF-Program-Guide/Table/Embed-a-Grid-into-a-Grid-Cell-in-PDF-in-C.html and it worked fine when writing direclty to the pdf page. However when I added PdfPageTemplateElement, I got exception below. Same code works fine when I use grid.draw(page, 0,50); rather than grid.draw(topSpace.getGraphics());. I have also attached the code for your reference and validation.
java.lang.NullPointerException: Cannot invoke "com.spire.pdf.PdfPageLayer.getPage()" because "this.spr‼" is null
at com.spire.pdf.graphics.PdfCanvas.spr╻℡(Unknown Source)
at com.spire.pdf.grid.PdfGridCell.spr◐–—(Unknown Source)
at com.spire.pdf.grid.PdfGridCell.spr┆⅟(Unknown Source)
at com.spire.pdf.grid.PdfGridCell.spr┐–—(Unknown Source)
at com.spire.office.packages.sprgnw.spr⅚℠(Unknown Source)
at com.spire.office.packages.sprgnw.spr▅℠(Unknown Source)
at com.spire.office.packages.sprgnw.spr∬——(Unknown Source)
at com.spire.office.packages.sprgnw.spr§⅟(Unknown Source)
at com.spire.office.packages.sprgnw.spr㈬⃝℡(Unknown Source)
at com.spire.office.packages.sprgnw.spr⌬℠(Unknown Source)
at com.spire.pdf.grid.PdfGrid.spr┻⅞(Unknown Source)
at com.spire.pdf.graphics.PdfGraphicsWidget.draw(Unknown Source)
at com.spire.pdf.graphics.PdfGraphicsWidget.spr≃⅞(Unknown Source)
at com.spire.pdf.graphics.PdfGraphicsWidget.draw(Unknown Source)
at com.alfatech.lab.PDFDiagnosticReport.main(PDFDiagnosticReport.java:105)