Expand my Community achievements bar.

Print multiple assets

Avatar

Level 1

Is it possible to select multiple assets and print? Or select entire folder and print??

1 Reply

Avatar

Level 1

I have find the way to bring content of specific folder into the page. Still the folder was chosen statically. Let me know if anyone know how to get the selected folder in API? Please find the code below.

 

<%@include file="/libs/foundation/global.jsp"%> <%@page session="false" %> <%@page import="com.day.cq.tagging.*,com.day.cq.wcm.api.*"%> <%@ page import="java.util.*, javax.jcr.*, org.apache.sling.api.resource.*, org.apache.sling.api.scripting.*, org.apache.sling.jcr.api.*, com.day.cq.search.*, com.day.cq.search.result.*" %> <%@page import="com.day.cq.dam.api.Asset"%> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <title>Print Assets</title> <style type="text/css"> img .print{ display: inline-block; page-break-after: always; } img .print:last-child { page-break-after: auto; } #imageDiv { position: absolute; top: 20px; left: 200px; } </style> <body> <script> function printImage(imagePath){ var popup; function closePrint () { if ( popup ) { popup.close(); } } popup = window.open(imagePath); popup.onbeforeunload = closePrint; popup.onafterprint = closePrint; popup.focus(); // Required for IE popup.print(); } </script> <% SlingRepository slingRep = sling.getService(SlingRepository.class); Session session = slingRep.loginAdministrative(null); QueryBuilder qb ; Map<String, String> map = new HashMap<String,String>(); map.put("type", "dam:Asset"); //map.put("property", "jcr:content/metadata/dc:format"); // Static approach map.put("path", "/content/dam/tasks/internalassets"); //map.put("property.value", "image/jpeg"); qb=resource.getResourceResolver().adaptTo(QueryBuilder.class); Query query = qb.createQuery(PredicateGroup.create(map), session); SearchResult sr= query.getResult(); String assetPath=null; String assetName=null; // iterating over the results for (Hit hit : sr.getHits()) { String path = hit.getPath(); Resource rs = resourceResolver.getResource(path); Asset asset = rs.adaptTo(Asset.class); assetPath = asset.getPath(); assetName= asset.getName(); %> <script> function viewImage(path){ $("#something").html(); var img = $("<img />").attr('src', path) .on('load', function() { if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) { alert('broken image!'); } else { $("#imageDiv").html(img); } }); } </script> <div> <div class="print"> <p><%= assetName %></p> <button onclick="viewImage('<%= assetPath %>');">View</button> <button onclick="printImage('<%= assetPath %>');">Print</button> <div style="clear: both;"></div> </div> </div> <% } %> <div id="imageDiv"></div> </body>