Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
O
ofd-service
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
位宇华
ofd-service
Commits
ce625f1d
Commit
ce625f1d
authored
Jun 24, 2024
by
位宇华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码提交
parent
313c45c3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
12 deletions
+45
-12
src/main/java/com/tianyi/service/impl/PdfToOfdServiceImpl.java
...ain/java/com/tianyi/service/impl/PdfToOfdServiceImpl.java
+45
-12
No files found.
src/main/java/com/tianyi/service/impl/PdfToOfdServiceImpl.java
View file @
ce625f1d
...
@@ -16,9 +16,7 @@ import org.springframework.stereotype.Service;
...
@@ -16,9 +16,7 @@ import org.springframework.stereotype.Service;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.net.URI
;
import
java.net.*
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
...
@@ -44,19 +42,54 @@ public class PdfToOfdServiceImpl implements PdfToOfdService {
...
@@ -44,19 +42,54 @@ public class PdfToOfdServiceImpl implements PdfToOfdService {
pdfRender
.
renderPageToGraphics
(
pageIndex
,
ofdPageG2d
);
pdfRender
.
renderPageToGraphics
(
pageIndex
,
ofdPageG2d
);
}
}
}
}
Path
out
=
null
;
Path
out
;
String
os
=
System
.
getProperty
(
"os.name"
).
toLowerCase
();
String
os
=
System
.
getProperty
(
"os.name"
).
toLowerCase
();
log
.
error
(
"系统类别:{}"
,
os
);
log
.
error
(
"系统类别:{}"
,
os
);
if
(
StringUtils
.
contains
(
os
,
"linux"
)){
if
(
StringUtils
.
contains
(
os
,
"linux"
))
{
out
=
Paths
.
get
(
"/home/ofd/ofddir/"
+
System
.
currentTimeMillis
()
+
".ofd"
);
out
=
Paths
.
get
(
"/home/ofd/ofddir/"
+
System
.
currentTimeMillis
()
+
".ofd"
);
Files
.
write
(
out
,
outputStream
.
toByteArray
());
Path
absolutePath
=
out
.
toAbsolutePath
();
return
convertToHttpUrl
(
absolutePath
.
toString
(),
"http"
,
8848
,
"/ofd-service"
);
}
}
if
(
StringUtils
.
contains
(
os
,
"windows"
))
{
if
(
StringUtils
.
contains
(
os
,
"windows"
))
{
out
=
Paths
.
get
(
"target"
,
System
.
currentTimeMillis
()
+
".ofd"
);
out
=
Paths
.
get
(
"target"
,
System
.
currentTimeMillis
()
+
".ofd"
);
Files
.
write
(
out
,
outputStream
.
toByteArray
());
Files
.
write
(
out
,
outputStream
.
toByteArray
());
URI
uri
=
out
.
toUri
();
return
uri
.
getPath
();
}
}
assert
out
!=
null
;
return
null
;
URI
uri
=
out
.
toUri
();
return
uri
.
getPath
();
}
}
@SneakyThrows
public
static
String
convertToHttpUrl
(
String
absolutePath
,
String
scheme
,
int
serverPort
,
String
contextPath
)
{
// 将绝对路径转换为URI对象
URI
uri
=
URI
.
create
(
absolutePath
);
// 构建HTTP URL
StringBuilder
httpUrl
=
new
StringBuilder
();
httpUrl
.
append
(
scheme
).
append
(
"://"
)
.
append
(
"192.168.111.229"
).
append
(
":"
)
.
append
(
serverPort
).
append
(
contextPath
);
// 如果URI中包含路径,则添加到HTTP URL中
String
path
=
uri
.
getPath
();
if
(
path
!=
null
&&
!
path
.
isEmpty
())
{
httpUrl
.
append
(
path
.
startsWith
(
"/"
)
?
path
:
"/"
.
concat
(
path
));
}
// 如果URI中包含查询参数,则添加到HTTP URL中
String
query
=
uri
.
getQuery
();
if
(
query
!=
null
)
{
httpUrl
.
append
(
"?"
).
append
(
query
);
}
// 如果URI中包含片段标识符,则添加到HTTP URL中
String
fragment
=
uri
.
getFragment
();
if
(
fragment
!=
null
)
{
httpUrl
.
append
(
"#"
).
append
(
fragment
);
}
return
httpUrl
.
toString
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment