I am able to genarte the pdf from the content fragment using a APi, but when Mine pdf is getting generated at the specific location I want o deploy it automatically without manual publish. | Community
Skip to main content
Level 2
March 22, 2024
Solved

I am able to genarte the pdf from the content fragment using a APi, but when Mine pdf is getting generated at the specific location I want o deploy it automatically without manual publish.

  • March 22, 2024
  • 2 replies
  • 566 views

Hi 

I am able to generate the PDF at specific location when I am hitting the api, but after PDF is getting generated I want to deploy it to publisher instance without publishing it manually. 

 

Thank You

 

@1709464 @estebanbustamante 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by anupampat

Hi @dear_at ,

 

1. Once you generate the PDF post hitting the API, get the path lets say at /content/somelocation/generatedPdf.pdf, save the path/resource using session.save() if you are using Node API or resourceResolver.commit() if you want to use Resource API.

2. Then simply publish the same path using  com.day.cq.replication.Replicator API

 

public void replicateAsset(ResourceResolver resourceResolver, String assetPath) throws ReplicationException { replicator.replicate(resourceResolver.adaptTo(Session.class), ReplicationActionType.ACTIVATE, pathToGeneratedPdf); }

 

2 replies

anupampat
Community Advisor
anupampatCommunity AdvisorAccepted solution
Community Advisor
March 22, 2024

Hi @dear_at ,

 

1. Once you generate the PDF post hitting the API, get the path lets say at /content/somelocation/generatedPdf.pdf, save the path/resource using session.save() if you are using Node API or resourceResolver.commit() if you want to use Resource API.

2. Then simply publish the same path using  com.day.cq.replication.Replicator API

 

public void replicateAsset(ResourceResolver resourceResolver, String assetPath) throws ReplicationException { replicator.replicate(resourceResolver.adaptTo(Session.class), ReplicationActionType.ACTIVATE, pathToGeneratedPdf); }

 

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
March 22, 2024

Hi, 
As explained @anupampat you need to use the Replicator API to achieve that. You can try something like below

@Reference private Replicator replicator; .. .. replicator.replicate(session, ReplicationActionType.ACTIVATE, assetPath);

 You can learn more here: 

https://dev.to/jerinraj55551/replication-api-in-aem-adobe-experience-manager-405n  

https://developer.adobe.com/experience-manager/reference-materials/6-4/javadoc/com/day/cq/replication/Replicator.html 


Hope this helps

Esteban Bustamante