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

Free Support Forum - aspose.com

Hierarchy of the layers created using ASPOSE pdf for Java

We are trying to create a pdf with 2 layers ASPOSE.pdf for java . The layers are getting created but they are not the top level layers as we expected.
The layers created are under Layer1 when pdf is opened in Adobe Illustrator.(shown in current layers.png)

The hierarchy we are trying to achieve with layering is shown in (expected.png). Please let us know if/how we can achieve this.Current Layers.PNG (9.3 KB)
Expected.PNG (6.1 KB)

Thanks

@asposeaugusta

Can you please share the source code and PDF file so that we may try to reproduce the same on our end.

@mudassir.fayyaz,

Please find below the code:
//ASPOSE code starts here
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document();
//SvgLoadOptions option = new SvgLoadOptions();
//Path _dataDir = Paths.get(“C:/output”);
//String svgDocumentFileName= Paths.get(_dataDir.toString(),“new-prod-228137-s-front.pdf”).toString();
com.aspose.pdf.Document designDoc = new com.aspose.pdf.Document(“C:/output/new-prod-228137-s-front.pdf”);
// Get access to first page of PDF file
Page page = pdfDocument.getPages().add();
PdfPageStamp pageStamp = new PdfPageStamp(designDoc.getPages().get_Item(1));
pageStamp.setBackground(false);
page.setPageSize(pageStamp.getWidth(), pageStamp.getHeight());
Layer layer = new Layer(“OL”, “Outline Layer”);
layer.getContents().add(new com.aspose.pdf.operators.SetRGBColorStroke(1, 0, 0));
layer.getContents().add(new com.aspose.pdf.operators.MoveTo(500, 700));
layer.getContents().add(new com.aspose.pdf.operators.LineTo(400, 700));
layer.getContents().add(new com.aspose.pdf.operators.Stroke());
page.setLayers(new ArrayList());
page.getLayers().add(layer);
layer = new Layer(“DL”, “Design Layer”);
designDoc.setAllowReusePageContent(true);

            pdfDocument.getPages().get_Item(1).addStamp(pageStamp);
            //layer.getContents().add(designDoc.getTaggedContent());
            
            page.getLayers().add(layer);
            pdfDocument.save("C:/output/asposetest.pdf");

The initial pdf that we use have layers as shown in the screenshot :
image.jpg (320.7 KB)

the final generated pdf layers looks like this :
image.png (543.8 KB)

We are trying to maintain the same layer names and structure.

Also we are looking at an option of converting from org.w3c.dom.Document of SVG to PDF.

Please let us know how/if we can maintain same layer structure if we open the generated pdf in adobe illustrator.

Thanks

@asposeaugusta

I request you to share this PDF file with us.

new-prod-228137-s-front-PDF.pdf (924.9 KB)

@asposeaugusta

A ticket with ID PDFJAVA-40627 has been created in our issue tracking system to investigate the issue on our end. We will notify you once any update will be available.