PDF Layer is Empty

Aspose PDF. NET 22.5
I create a custom layer with an image on the page and save the file - it works

            var nameLayer = "Template_" + templateName;

            if (page.Layers != null && page.Layers.Count > 0)
                var oldLayer = page.Layers.FirstOrDefault(l => l.Name == nameLayer);
                if (oldLayer != null)

            FileStream imageStream = new FileStream(s.filepath, FileMode.Open);
            var marginY = page.MediaBox.Height - s.xyp.h - s.xyp.y;
            Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(s.xyp.x, marginY, s.xyp.x + s.xyp.w, marginY + s.xyp.h);
            Matrix matrix = new Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY });

            Layer layer = new Layer(nameLayer + page.Number.ToString(), nameLayer);
            layer.Contents.Add(new Aspose.Pdf.Operators.GSave());
            layer.Contents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(matrix));

            XImage ximage = page.Resources.Images[page.Resources.Images.Count];
            layer.Contents.Add(new Aspose.Pdf.Operators.Do(ximage.Name));
            layer.Contents.Add(new Aspose.Pdf.Operators.GRestore());
            page.Layers = new List<Layer>();

But when I read this file again, I see my custom layer is there, but its Contents are empty (Layer.Contents.Count= 0). How do I read the contents of my custom layer?


Could you please share your sample PDF as well as the complete code snippet so that we can try to reproduce the issue in our environment and address it accordingly.

LayerTest.zip (67.8 KB)


An issue as PDFNET-53422 has been logged in our issue tracking system for further investigation. We will look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.