@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