We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PDF Layer is Empty

Hi
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)
                    page.Layers.Remove(oldLayer);
            }

            setImageSize(s);
            FileStream imageStream = new FileStream(s.filepath, FileMode.Open);
            page.Resources.Images.Add(imageStream);
            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>();
            page.Layers.Add(layer);
            imageStream.Close();

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?

@PoweRDeaD

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)

@PoweRDeaD

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.