Skip to content
This repository was archived by the owner on Jul 21, 2021. It is now read-only.

Commit fd1467a

Browse files
koleslenaegorovpavel
authored andcommitted
added print pdf temp code (#25)
1 parent 67ec53c commit fd1467a

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
},
1818
"homepage": "https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-Java-Spring#readme",
1919
"dependencies": {
20-
"@groupdocs.examples.jquery/common": "^0.11.0",
21-
"@groupdocs.examples.jquery/viewer": "^0.11.0"
20+
"@groupdocs.examples.jquery/common": "^0.12.0",
21+
"@groupdocs.examples.jquery/viewer": "^0.12.0"
2222
},
2323
"devDependencies": {
2424
"gulp": "^4.0.0"

src/main/java/com/groupdocs/ui/viewer/ViewerController.java

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class ViewerController {
5252
* Get viewer page
5353
*
5454
* @param request http request
55-
* @param model model data for template
55+
* @param model model data for template
5656
* @return template name
5757
*/
5858
@RequestMapping(method = RequestMethod.GET)
@@ -68,53 +68,92 @@ public String getView(HttpServletRequest request, Map<String, Object> model) {
6868

6969
/**
7070
* Get files and directories
71+
*
7172
* @return files and directories list
7273
*/
7374
@RequestMapping(method = RequestMethod.POST, value = "/loadFileTree",
7475
consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
7576
@ResponseBody
76-
public List<FileDescriptionEntity> loadFileTree(@RequestBody FileTreeRequest fileTreeRequest){
77+
public List<FileDescriptionEntity> loadFileTree(@RequestBody FileTreeRequest fileTreeRequest) {
7778
return viewerService.getFileList(fileTreeRequest.getPath());
7879
}
7980

8081
/**
8182
* Get document description
83+
*
8284
* @return document description
8385
*/
8486
@RequestMapping(method = RequestMethod.POST, value = "/loadDocumentDescription", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
8587
@ResponseBody
86-
public LoadDocumentEntity loadDocumentDescription(@RequestBody LoadDocumentRequest loadDocumentRequest){
88+
public LoadDocumentEntity loadDocumentDescription(@RequestBody LoadDocumentRequest loadDocumentRequest) {
8789
return viewerService.loadDocument(loadDocumentRequest, viewerService.getViewerConfiguration().getPreloadPageCount() == 0);
8890
}
8991

9092
/**
9193
* Get all pages for thumbnails
94+
*
9295
* @param loadDocumentRequest
9396
* @return
9497
*/
9598
@RequestMapping(method = RequestMethod.POST, value = "/loadThumbnails", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
9699
@ResponseBody
97-
public LoadDocumentEntity loadThumbnails(@RequestBody LoadDocumentRequest loadDocumentRequest){
100+
public LoadDocumentEntity loadThumbnails(@RequestBody LoadDocumentRequest loadDocumentRequest) {
101+
return viewerService.loadDocument(loadDocumentRequest, true);
102+
}
103+
104+
/**
105+
* Get document for printing
106+
*
107+
* @param loadDocumentRequest
108+
* @return
109+
*/
110+
@RequestMapping(method = RequestMethod.POST, value = "/loadPrint", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
111+
@ResponseBody
112+
public LoadDocumentEntity loadPrint(@RequestBody LoadDocumentRequest loadDocumentRequest) {
98113
return viewerService.loadDocument(loadDocumentRequest, true);
99114
}
100115

116+
/**
117+
* Get pdf document for printing
118+
*
119+
* @return
120+
*/
121+
@RequestMapping(method = RequestMethod.POST, value = "/printPdf", consumes = APPLICATION_JSON_VALUE)
122+
public void printPdf(@RequestBody LoadDocumentRequest loadDocumentRequest, HttpServletResponse response) {
123+
String documentGuid = loadDocumentRequest.getGuid();
124+
File file = new File(documentGuid);
125+
// set response content info
126+
Utils.addFileDownloadHeaders(response, file.getName(), file.length());
127+
// download the document
128+
try (InputStream inputStream = new BufferedInputStream(new FileInputStream(documentGuid));
129+
ServletOutputStream outputStream = response.getOutputStream()) {
130+
131+
IOUtils.copyLarge(inputStream, outputStream);
132+
} catch (Exception ex) {
133+
logger.error("Exception in opening document", ex);
134+
throw new TotalGroupDocsException(ex.getMessage(), ex);
135+
}
136+
}
137+
101138
/**
102139
* Get document page
140+
*
103141
* @return document page info
104142
*/
105143
@RequestMapping(method = RequestMethod.POST, value = "/loadDocumentPage", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
106144
@ResponseBody
107-
public PageDescriptionEntity loadDocumentPage(@RequestBody LoadDocumentPageRequest loadDocumentPageRequest){
145+
public PageDescriptionEntity loadDocumentPage(@RequestBody LoadDocumentPageRequest loadDocumentPageRequest) {
108146
return viewerService.loadDocumentPage(loadDocumentPageRequest);
109147
}
110148

111149
/**
112150
* Rotate page(s)
151+
*
113152
* @return rotated pages list (each object contains page number and rotated angle information)
114153
*/
115154
@RequestMapping(method = RequestMethod.POST, value = "/rotateDocumentPages", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
116155
@ResponseBody
117-
public List<RotatedPageEntity> rotateDocumentPages(@RequestBody RotateDocumentPagesRequest rotateDocumentPagesRequest){
156+
public List<RotatedPageEntity> rotateDocumentPages(@RequestBody RotateDocumentPagesRequest rotateDocumentPagesRequest) {
118157
return viewerService.rotateDocumentPages(rotateDocumentPagesRequest);
119158
}
120159

@@ -131,14 +170,15 @@ public void downloadDocument(@RequestParam(name = "path") String documentGuid, H
131170
ServletOutputStream outputStream = response.getOutputStream()) {
132171

133172
IOUtils.copyLarge(inputStream, outputStream);
134-
} catch (Exception ex){
173+
} catch (Exception ex) {
135174
logger.error("Exception in downloading document", ex);
136175
throw new TotalGroupDocsException(ex.getMessage(), ex);
137176
}
138177
}
139178

140179
/**
141180
* Upload document
181+
*
142182
* @return uploaded document object (the object contains uploaded document guid)
143183
*/
144184
@RequestMapping(method = RequestMethod.POST, value = "/uploadDocument",

0 commit comments

Comments
 (0)