Skip to content
This repository was archived by the owner on Oct 18, 2018. It is now read-only.

Commit 032e5dc

Browse files
committed
Fix page numbering
1 parent 76f17e3 commit 032e5dc

File tree

4 files changed

+60
-45
lines changed

4 files changed

+60
-45
lines changed

src/main/java/com/groupdocs/ui/servlet/AnnotationServlet.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.groupdocs.ui.servlet;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.databind.SerializationFeature;
45
import com.groupdocs.annotation.domain.AnnotationInfo;
56
import com.groupdocs.annotation.domain.Point;
67
import com.groupdocs.annotation.domain.TextFieldInfo;
@@ -53,7 +54,8 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
5354
case "fieldtext":
5455
TextFieldInfo info = new ObjectMapper().readValue(request.getInputStream(), TextFieldInfo.class);
5556
SaveAnnotationTextResult result = imageHandler.saveTextField(annotationId, info);
56-
new ObjectMapper().writeValue(response.getOutputStream(), result);
57+
new ObjectMapper().writer().without(SerializationFeature.FAIL_ON_EMPTY_BEANS)
58+
.writeValue(response.getOutputStream(), result);
5759
break;
5860
case "position":
5961
Point point = new ObjectMapper().readValue(request.getInputStream(), Point.class);

src/main/java/com/groupdocs/ui/servlet/PageImageServlet.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
3030

3131
ImageOptions o = new ImageOptions();
3232
int pageNumber = Integer.valueOf(request.getParameter("page"));
33-
o.setPageNumbersToConvert(Arrays.asList(pageNumber - 1));
34-
o.setPageNumber(pageNumber - 1);
33+
o.setPageNumbersToConvert(Arrays.asList(pageNumber));
34+
o.setPageNumber(pageNumber);
3535
o.setCountPagesToConvert(1);
3636
if (request.getParameterMap().containsKey("width")) {
3737
o.setWidth(Integer.valueOf(request.getParameter("width")));
@@ -43,7 +43,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
4343
String filename = request.getParameter("file");
4444

4545
for (PageImage pageImage: handler.getPages(filename, o)) {
46-
if (pageImage.getPageNumber() == pageNumber - 1) {
46+
if (pageImage.getPageNumber() == pageNumber) {
4747
IOUtils.copy(pageImage.getStream(), response.getOutputStream());
4848
break;
4949
}

src/main/webapp/app.directive.gdxAnnoPage.js

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,34 @@
116116
break;
117117
case 'underline':
118118
var start = new ps.Point(event.point);
119-
$rootScope.startRow = getStartRow($rootScope.docInfo,start,attrs);
120-
$rootScope.startText = $rootScope.startRow[0].characterCoordinates.filter(x=>Math.floor(x) > Math.floor(start.x));
121-
if($rootScope.startText.length>1){
119+
$rootScope.startRow = getStartRow($rootScope.docInfo, start, attrs);
120+
$rootScope.startText = $rootScope.startRow[0].characterCoordinates.filter(x = > Math.floor(x) > Math.floor(start.x)
121+
)
122+
;
123+
if ($rootScope.startText.length > 1) {
122124
currentObject = new ps.Path.Line(new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight), new ps.Point($rootScope.startText[1], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight));
123125
currentObject.strokeColor = 'black';
124126
currentObject.strokeWidth = 2;
125127
}
126-
else if($rootScope.startText.length>1){
128+
else if ($rootScope.startText.length > 1) {
127129
currentObject = new ps.Path.Line(new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight), new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight));
128130
currentObject.strokeColor = 'black';
129131
currentObject.strokeWidth = 2;
130132
}
131133
break;
132134
case 'strikeout':
133135
var start = new ps.Point(event.point);
134-
$rootScope.startRow = getStartRow($rootScope.docInfo,start,attrs);
135-
$rootScope.startText = $rootScope.startRow[0].characterCoordinates.filter(x=>Math.floor(x) > Math.floor(start.x));
136-
if($rootScope.startText.length>1){
137-
currentObject = new ps.Path.Line(new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight/2), new ps.Point($rootScope.startText[1], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight/2));
136+
$rootScope.startRow = getStartRow($rootScope.docInfo, start, attrs);
137+
$rootScope.startText = $rootScope.startRow[0].characterCoordinates.filter(x = > Math.floor(x) > Math.floor(start.x)
138+
)
139+
;
140+
if ($rootScope.startText.length > 1) {
141+
currentObject = new ps.Path.Line(new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight / 2), new ps.Point($rootScope.startText[1], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight / 2));
138142
currentObject.strokeColor = 'black';
139143
currentObject.strokeWidth = 2;
140144
}
141-
else if($rootScope.startText.length>1){
142-
currentObject = new ps.Path.Line(new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight/2), new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight/2));
145+
else if ($rootScope.startText.length > 1) {
146+
currentObject = new ps.Path.Line(new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight / 2), new ps.Point($rootScope.startText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight / 2));
143147
currentObject.strokeColor = 'black';
144148
currentObject.strokeWidth = 2;
145149
}
@@ -172,26 +176,30 @@
172176
currentObject.position.y += event.delta.y;
173177
break;
174178
case 'underline':
175-
if(currentObject){
179+
if (currentObject) {
176180
var end = new ps.Point(event.point);
177-
var endText = $rootScope.startRow[0].characterCoordinates.filter(x=>Math.floor(x) > Math.floor(end.x));
178-
if(endText.length>1){
181+
var endText = $rootScope.startRow[0].characterCoordinates.filter(x = > Math.floor(x) > Math.floor(end.x)
182+
)
183+
;
184+
if (endText.length > 1) {
179185
currentObject.add(new ps.Point(endText[1], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight));
180186
}
181-
else if(endText.length>0){
187+
else if (endText.length > 0) {
182188
currentObject.add(new ps.Point(endText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight));
183189
}
184190
}
185191
break;
186192
case 'strikeout':
187-
if(currentObject){
193+
if (currentObject) {
188194
var end = new ps.Point(event.point);
189-
var endText = $rootScope.startRow[0].characterCoordinates.filter(x=>Math.floor(x) > Math.floor(end.x));
190-
if(endText.length>1){
191-
currentObject.add(new ps.Point(endText[1], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight/2));
195+
var endText = $rootScope.startRow[0].characterCoordinates.filter(x = > Math.floor(x) > Math.floor(end.x)
196+
)
197+
;
198+
if (endText.length > 1) {
199+
currentObject.add(new ps.Point(endText[1], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight / 2));
192200
}
193-
else if(endText.length>0){
194-
currentObject.add(new ps.Point(endText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight/2));
201+
else if (endText.length > 0) {
202+
currentObject.add(new ps.Point(endText[0], $rootScope.startRow[0].lineTop + $rootScope.startRow[0].lineHeight / 2));
195203
}
196204

197205
}
@@ -219,13 +227,13 @@
219227
currentObject.strokeWidth = 2;
220228
break;
221229
case 'distance':
222-
if(currentObject){
230+
if (currentObject) {
223231
currentObject.remove();
224232
}
225233
var start = new ps.Point(event.downPoint);
226234
var end = new ps.Point(event.point);
227-
var textX = (start.x + end.x)/2;
228-
var textY = (start.y + end.y)/2;
235+
var textX = (start.x + end.x) / 2;
236+
var textY = (start.y + end.y) / 2;
229237
var textPoint = new ps.Point(textX, textY);
230238
var tailLine = new ps.Path.Line(start, end);
231239
var textPosition = end.add(start);
@@ -305,10 +313,10 @@
305313
break;
306314
case 'distance':
307315
ant = {
308-
type : 12,
309-
svgPath : currentObject.exportSVG().children[0].getAttribute('d')+ " " + currentObject.exportSVG().children[1].getAttribute('d') + " " + currentObject.exportSVG().children[2].getAttribute('d'),
310-
text : currentObject.children[3].content,
311-
box : {
316+
type: 12,
317+
svgPath: currentObject.exportSVG().children[0].getAttribute('d') + " " + currentObject.exportSVG().children[1].getAttribute('d') + " " + currentObject.exportSVG().children[2].getAttribute('d'),
318+
text: currentObject.children[3].content,
319+
box: {
312320
x: currentObject.children[3].position.x,
313321
y: currentObject.children[3].position.y,
314322
width: 0,
@@ -318,8 +326,8 @@
318326
break;
319327
case 'underline':
320328
ant = {
321-
type : 11,
322-
svgPath : currentObject.exportSVG().getAttribute('d'),
329+
type: 11,
330+
svgPath: currentObject.exportSVG().getAttribute('d'),
323331
box: {
324332
x: currentObject.bounds.x,
325333
y: currentObject.bounds.y,
@@ -330,8 +338,8 @@
330338
break;
331339
case 'strikeout':
332340
ant = {
333-
type : 11,
334-
svgPath : currentObject.exportSVG().getAttribute('d'),
341+
type: 11,
342+
svgPath: currentObject.exportSVG().getAttribute('d'),
335343
box: {
336344
x: currentObject.bounds.x,
337345
y: currentObject.bounds.y,
@@ -345,7 +353,7 @@
345353
if (ant.type) {
346354
ant.pageNumber = attrs.number;
347355
var a = new AnnotationAddFactory(ant);
348-
a.$save({ filename: $rootScope.selectedFile }, function (response) {
356+
a.$save({filename: $rootScope.selectedFile}, function (response) {
349357
currentObject.name = response.guid;
350358
currentObject.selected = true;
351359
currentObject = null;
@@ -466,17 +474,22 @@
466474
}
467475
})
468476
}
469-
function getStartRow(docInfo,start,attrs){
477+
478+
function getStartRow(docInfo, start, attrs) {
470479
var startRow = [];
471-
for(var i = 0; i<30; i++){
472-
startRow = docInfo.pages[attrs.number-1].rows.filter(x => Math.floor(x.lineTop) == (Math.floor(start.y)-i ));
473-
if(startRow.length>0)
480+
for (var i = 0; i < 30; i++) {
481+
startRow = docInfo.pages[attrs.number].rows.filter(x = > Math.floor(x.lineTop) == (Math.floor(start.y) - i )
482+
)
483+
;
484+
if (startRow.length > 0)
474485
return startRow;
475486
}
476-
if(startRow.length == 0)
477-
for(var i = 0; i<30; i++){
478-
startRow = docInfo.pages[attrs.number-1].rows.filter(x => Math.floor(x.lineTop) == (Math.floor(start.y)+i ));
479-
if(startRow.length>0)
487+
if (startRow.length == 0)
488+
for (var i = 0; i < 30; i++) {
489+
startRow = docInfo.pages[attrs.number].rows.filter(x = > Math.floor(x.lineTop) == (Math.floor(start.y) + i )
490+
)
491+
;
492+
if (startRow.length > 0)
480493
return startRow;
481494
}
482495

src/main/webapp/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ <h1>GroupDocs.Annotation for Java</h1>
9595
<md-card ng-repeat="pageInfo in docInfo.pages">
9696
<gdx-anno-page
9797
file="{{ $root.selectedFile }}"
98-
number="{{ pageInfo.number }}"
98+
number="{{ pageInfo.number - 1 }}"
9999
width="{{ pageInfo.width }}"
100100
height="{{ pageInfo.height }}"
101101
oncontextmenu="return false">

0 commit comments

Comments
 (0)