@Test public void testImageMerge() throws IOException { BatchUpdatePresentationResponse response = this.snippets.imageMerging(TEMPLATE_PRESENTATION_ID, IMAGE_URL, CUSTOMER_NAME); String presentationId = response.getPresentationId(); assertNotNull(presentationId); assertEquals(2, response.getReplies().size()); int numReplacements = 0; for(Response resp: response.getReplies()) { numReplacements += resp.getReplaceAllShapesWithImage().getOccurrencesChanged(); } assertEquals(2, numReplacements); this.deleteFileOnCleanup(presentationId); }
public BatchUpdatePresentationResponse imageMerging(String templatePresentationId, String imageUrl, String customerName) throws IOException { Slides slidesService = this.service; Drive driveService = this.driveService; String logoUrl = imageUrl; String customerGraphicUrl = imageUrl; String copyTitle = customerName + " presentation"; File content = new File().setName(copyTitle); File presentationFile = driveService.files().copy(templatePresentationId, content).execute(); String presentationId = presentationFile.getId(); List<Request> requests = new ArrayList<>(); requests.add(new Request() .setReplaceAllShapesWithImage(new ReplaceAllShapesWithImageRequest() .setImageUrl(logoUrl) .setReplaceMethod("CENTER_INSIDE") .setContainsText(new SubstringMatchCriteria() .setText("{{company-logo}}") .setMatchCase(true)))); requests.add(new Request() .setReplaceAllShapesWithImage(new ReplaceAllShapesWithImageRequest() .setImageUrl(customerGraphicUrl) .setReplaceMethod("CENTER_INSIDE") .setContainsText(new SubstringMatchCriteria() .setText("{{customer-graphic}}") .setMatchCase(true)))); BatchUpdatePresentationRequest body = new BatchUpdatePresentationRequest().setRequests(requests); BatchUpdatePresentationResponse response = slidesService.presentations().batchUpdate(presentationId, body).execute(); int numReplacements = 0; for(Response resp: response.getReplies()) { numReplacements += resp.getReplaceAllShapesWithImage().getOccurrencesChanged(); } System.out.println("Created merged presentation with ID: " + presentationId); System.out.println("Replaced " + numReplacements + " shapes instances with images."); return response; }
Snippets { public BatchUpdatePresentationResponse imageMerging(String templatePresentationId, String imageUrl, String customerName) throws IOException { Slides slidesService = this.service; Drive driveService = this.driveService; String logoUrl = imageUrl; String customerGraphicUrl = imageUrl; String copyTitle = customerName + " presentation"; File content = new File().setName(copyTitle); File presentationFile = driveService.files().copy(templatePresentationId, content).execute(); String presentationId = presentationFile.getId(); List<Request> requests = new ArrayList<>(); requests.add(new Request() .setReplaceAllShapesWithImage(new ReplaceAllShapesWithImageRequest() .setImageUrl(logoUrl) .setReplaceMethod("CENTER_INSIDE") .setContainsText(new SubstringMatchCriteria() .setText("{{company-logo}}") .setMatchCase(true)))); requests.add(new Request() .setReplaceAllShapesWithImage(new ReplaceAllShapesWithImageRequest() .setImageUrl(customerGraphicUrl) .setReplaceMethod("CENTER_INSIDE") .setContainsText(new SubstringMatchCriteria() .setText("{{customer-graphic}}") .setMatchCase(true)))); BatchUpdatePresentationRequest body = new BatchUpdatePresentationRequest().setRequests(requests); BatchUpdatePresentationResponse response = slidesService.presentations().batchUpdate(presentationId, body).execute(); int numReplacements = 0; for(Response resp: response.getReplies()) { numReplacements += resp.getReplaceAllShapesWithImage().getOccurrencesChanged(); } System.out.println("Created merged presentation with ID: " + presentationId); System.out.println("Replaced " + numReplacements + " shapes instances with images."); return response; } }
Snippets { public BatchUpdatePresentationResponse imageMerging(String templatePresentationId, String imageUrl, String customerName) throws IOException { Slides slidesService = this.service; Drive driveService = this.driveService; String logoUrl = imageUrl; String customerGraphicUrl = imageUrl; String copyTitle = customerName + " presentation"; File content = new File().setName(copyTitle); File presentationFile = driveService.files().copy(templatePresentationId, content).execute(); String presentationId = presentationFile.getId(); List<Request> requests = new ArrayList<>(); requests.add(new Request() .setReplaceAllShapesWithImage(new ReplaceAllShapesWithImageRequest() .setImageUrl(logoUrl) .setReplaceMethod("CENTER_INSIDE") .setContainsText(new SubstringMatchCriteria() .setText("{{company-logo}}") .setMatchCase(true)))); requests.add(new Request() .setReplaceAllShapesWithImage(new ReplaceAllShapesWithImageRequest() .setImageUrl(customerGraphicUrl) .setReplaceMethod("CENTER_INSIDE") .setContainsText(new SubstringMatchCriteria() .setText("{{customer-graphic}}") .setMatchCase(true)))); BatchUpdatePresentationRequest body = new BatchUpdatePresentationRequest().setRequests(requests); BatchUpdatePresentationResponse response = slidesService.presentations().batchUpdate(presentationId, body).execute(); int numReplacements = 0; for(Response resp: response.getReplies()) { numReplacements += resp.getReplaceAllShapesWithImage().getOccurrencesChanged(); } System.out.println("Created merged presentation with ID: " + presentationId); System.out.println("Replaced " + numReplacements + " shapes instances with images."); return response; } Snippets(Slides service, Drive driveService, Sheets sheetsService); }
Snippets { public BatchUpdatePresentationResponse imageMerging(String templatePresentationId, String imageUrl, String customerName) throws IOException { Slides slidesService = this.service; Drive driveService = this.driveService; String logoUrl = imageUrl; String customerGraphicUrl = imageUrl; String copyTitle = customerName + " presentation"; File content = new File().setName(copyTitle); File presentationFile = driveService.files().copy(templatePresentationId, content).execute(); String presentationId = presentationFile.getId(); List<Request> requests = new ArrayList<>(); requests.add(new Request() .setReplaceAllShapesWithImage(new ReplaceAllShapesWithImageRequest() .setImageUrl(logoUrl) .setReplaceMethod("CENTER_INSIDE") .setContainsText(new SubstringMatchCriteria() .setText("{{company-logo}}") .setMatchCase(true)))); requests.add(new Request() .setReplaceAllShapesWithImage(new ReplaceAllShapesWithImageRequest() .setImageUrl(customerGraphicUrl) .setReplaceMethod("CENTER_INSIDE") .setContainsText(new SubstringMatchCriteria() .setText("{{customer-graphic}}") .setMatchCase(true)))); BatchUpdatePresentationRequest body = new BatchUpdatePresentationRequest().setRequests(requests); BatchUpdatePresentationResponse response = slidesService.presentations().batchUpdate(presentationId, body).execute(); int numReplacements = 0; for(Response resp: response.getReplies()) { numReplacements += resp.getReplaceAllShapesWithImage().getOccurrencesChanged(); } System.out.println("Created merged presentation with ID: " + presentationId); System.out.println("Replaced " + numReplacements + " shapes instances with images."); return response; } Snippets(Slides service, Drive driveService, Sheets sheetsService); String createPresentation(String title); String copyPresentation(String presentationId, String copyTitle); BatchUpdatePresentationResponse createSlide(String presentationId); BatchUpdatePresentationResponse createTextBoxWithText(
            String presentationId, String slideId); BatchUpdatePresentationResponse createImage(String presentationId,
                                                       String slideId,
                                                       GoogleCredential credential); List<BatchUpdatePresentationResponse> textMerging(
            String templatePresentationId, String dataSpreadsheetId); BatchUpdatePresentationResponse imageMerging(String templatePresentationId,
                                                        String imageUrl,
                                                        String customerName); BatchUpdatePresentationResponse simpleTextReplace(
            String presentationId, String shapeId, String replacementText); BatchUpdatePresentationResponse textStyleUpdate(String presentationId, String shapeId); BatchUpdatePresentationResponse createBulletedText(String presentationId,
                                                              String shapeId); BatchUpdatePresentationResponse createSheetsChart(
            String presentationId, String pageId, String spreadsheetId, Integer sheetChartId); BatchUpdatePresentationResponse refreshSheetsChart(
            String presentationId, String presentationChartId); }
Snippets { public BatchUpdatePresentationResponse imageMerging(String templatePresentationId, String imageUrl, String customerName) throws IOException { Slides slidesService = this.service; Drive driveService = this.driveService; String logoUrl = imageUrl; String customerGraphicUrl = imageUrl; String copyTitle = customerName + " presentation"; File content = new File().setName(copyTitle); File presentationFile = driveService.files().copy(templatePresentationId, content).execute(); String presentationId = presentationFile.getId(); List<Request> requests = new ArrayList<>(); requests.add(new Request() .setReplaceAllShapesWithImage(new ReplaceAllShapesWithImageRequest() .setImageUrl(logoUrl) .setReplaceMethod("CENTER_INSIDE") .setContainsText(new SubstringMatchCriteria() .setText("{{company-logo}}") .setMatchCase(true)))); requests.add(new Request() .setReplaceAllShapesWithImage(new ReplaceAllShapesWithImageRequest() .setImageUrl(customerGraphicUrl) .setReplaceMethod("CENTER_INSIDE") .setContainsText(new SubstringMatchCriteria() .setText("{{customer-graphic}}") .setMatchCase(true)))); BatchUpdatePresentationRequest body = new BatchUpdatePresentationRequest().setRequests(requests); BatchUpdatePresentationResponse response = slidesService.presentations().batchUpdate(presentationId, body).execute(); int numReplacements = 0; for(Response resp: response.getReplies()) { numReplacements += resp.getReplaceAllShapesWithImage().getOccurrencesChanged(); } System.out.println("Created merged presentation with ID: " + presentationId); System.out.println("Replaced " + numReplacements + " shapes instances with images."); return response; } Snippets(Slides service, Drive driveService, Sheets sheetsService); String createPresentation(String title); String copyPresentation(String presentationId, String copyTitle); BatchUpdatePresentationResponse createSlide(String presentationId); BatchUpdatePresentationResponse createTextBoxWithText(
            String presentationId, String slideId); BatchUpdatePresentationResponse createImage(String presentationId,
                                                       String slideId,
                                                       GoogleCredential credential); List<BatchUpdatePresentationResponse> textMerging(
            String templatePresentationId, String dataSpreadsheetId); BatchUpdatePresentationResponse imageMerging(String templatePresentationId,
                                                        String imageUrl,
                                                        String customerName); BatchUpdatePresentationResponse simpleTextReplace(
            String presentationId, String shapeId, String replacementText); BatchUpdatePresentationResponse textStyleUpdate(String presentationId, String shapeId); BatchUpdatePresentationResponse createBulletedText(String presentationId,
                                                              String shapeId); BatchUpdatePresentationResponse createSheetsChart(
            String presentationId, String pageId, String spreadsheetId, Integer sheetChartId); BatchUpdatePresentationResponse refreshSheetsChart(
            String presentationId, String presentationChartId);  }