Commit ce625f1d authored by 位宇华's avatar 位宇华

代码提交

parent 313c45c3
......@@ -16,9 +16,7 @@ import org.springframework.stereotype.Service;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
......@@ -44,19 +42,54 @@ public class PdfToOfdServiceImpl implements PdfToOfdService {
pdfRender.renderPageToGraphics(pageIndex, ofdPageG2d);
}
}
Path out = null;
String os=System.getProperty("os.name").toLowerCase();
log.error("系统类别:{}",os);
if (StringUtils.contains(os,"linux")){
out=Paths.get("/home/ofd/ofddir/"+System.currentTimeMillis() + ".ofd");
Path out;
String os = System.getProperty("os.name").toLowerCase();
log.error("系统类别:{}", os);
if (StringUtils.contains(os, "linux")) {
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");
Files.write(out, outputStream.toByteArray());
}
assert out != null;
URI uri=out.toUri();
URI uri = out.toUri();
return uri.getPath();
}
return null;
}
@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();
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment