第一次提交

master
zhanghai 2 years ago
commit 6889df9761

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="SwSoft" />
</profile>
</annotationProcessing>
</component>
</project>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="central" />
<option name="url" value="https://maven.aliyun.com/nexus/content/groups/public" />
</remote-repository>
<remote-repository>
<option name="id" value="rdc-snapshots" />
<option name="name" value="rdc-snapshots" />
<option name="url" value="https://packages.aliyun.com/maven/repository/2360197-snapshot-rKvQJZ/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="rdc-releases" />
<option name="name" value="rdc-releases" />
<option name="url" value="https://packages.aliyun.com/maven/repository/2360197-release-kcpW7u/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="snapshots" />
<option name="name" value="snapshots" />
<option name="url" value="https://maven.aliyun.com/nexus/content/groups/public" />
</remote-repository>
<remote-repository>
<option name="id" value="com.e-iceblue" />
<option name="name" value="e-iceblue" />
<option name="url" value="https://repo.e-iceblue.cn/repository/maven-public/" />
</remote-repository>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JpaBuddyIdeaProjectConfig">
<option name="renamerInitialized" value="true" />
</component>
</project>

@ -0,0 +1,16 @@
<component name="libraryTable">
<library name="MigLayout">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/miglayout-swing.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/miglayout-core.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$PROJECT_DIR$/lib/miglayout-swing-javadoc.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/miglayout-core-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$PROJECT_DIR$/lib/miglayout-swing-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/miglayout-core-sources.jar!/" />
</SOURCES>
</library>
</component>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="ProjectType">
<option name="id" value="jpab" />
</component>
</project>

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -0,0 +1,8 @@
file.mode=图片
file.read.url=C:\jiahsi-saomiao\缩微\ddd_0001\
a3.length=3000
plate.size=2800
a3.width=3000
file.save.url=C:\jiahsi-saomiao\缩微\分盘结果\档案图\
zong.name.prefix=南方医院
Split.mode=copy/cut

@ -0,0 +1,8 @@
zong.name.prefix=南方医院
a3.length=3000
a3.width=3000
file.mode=pic/pdf/word
file.save.url=C:\jiahsi-saomiao\缩微\分盘结果\档案图\
file.read.url=C:\jiahsi-saomiao\缩微\ddd_0001\
plate.size=2800
Split.mode=copy/cut

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>SwSoft</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-imaging -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-imaging</artifactId>
<version>1.0-alpha3</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13.3</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
<!--主要用到Pair类-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.23</version>
<type>bundle</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,24 @@
package com.docus;
import com.alibaba.excel.util.FileUtils;
import com.docus.sw.*;
import com.docus.sw.fenpan.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.Imaging;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
public class Main {
}

@ -0,0 +1,85 @@
package com.docus.sw;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
public class Config {
private static Map<String, String> stringStringMap = new HashMap<>();
public static String getParam(String key){
return stringStringMap.get(key);
}
public static void loadConfig() throws IOException {
//从classpath 读取配置文件。将日志写入到result中。
Map<String, String> stringStringMaplocal = readParam("config.ini");
stringStringMap = stringStringMaplocal;
}
private static Map<String,String> readParam(String file) throws IOException {
Map<String,String> params = new HashMap<>();
BufferedReader in = new BufferedReader(new FileReader(file));
String str;
while ((str = in.readLine()) != null) {
String[] split = str.split("=");
params.put(split[0],split[1]);
}
in.close();
return params;
}
public static void updateConfig(String key,String value) throws IOException {
if(stringStringMap==null){
throw new RuntimeException("先加载配置文件");
}
stringStringMap.put(key,value);
Files.write(Paths.get("config.ini"), new byte[0]);
try (BufferedWriter writer = new BufferedWriter(new FileWriter("config.ini"))) {
// 写入内容到文件
for(String keyN: stringStringMap.keySet()){
writer.write(keyN+"="+stringStringMap.get(keyN));
writer.newLine(); // 换行
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void updateConfig(Map<String,String> keyvalue) throws IOException {
if(stringStringMap==null){
throw new RuntimeException("先加载配置文件");
}
stringStringMap.putAll(keyvalue);
Files.write(Paths.get("config.ini"), new byte[0]);
try (BufferedWriter writer = new BufferedWriter(new FileWriter("config.ini"))) {
// 写入内容到文件
for(String keyN: stringStringMap.keySet()){
writer.write(keyN+"="+stringStringMap.get(keyN));
writer.newLine(); // 换行
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,15 @@
package com.docus.sw.fenpan;
import lombok.Getter;
/**
* A3
*/
@Getter
public class A3Attribute {
private Integer width;
private Integer length;
}

@ -0,0 +1,33 @@
package com.docus.sw.fenpan;
import com.docus.sw.Config;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class Document {
/**
*
*/
private Integer width;
/**
*
*/
private Integer longTh;
private Integer dpi;
//写一个方法判断是 A3 还是 A4
public Boolean isA3() {
if (width > Integer.parseInt(Config.getParam("a3.width")) || longTh > Integer.parseInt(Config.getParam("a3.length"))) {
return true;
}
return false;
}
}

@ -0,0 +1,220 @@
package com.docus.sw.fenpan;
import com.alibaba.excel.util.FileUtils;
import com.docus.sw.Config;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.Imaging;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
public class FenpanService {
public void fenpan(String saveUrl,String readUrl){
try {
FenpanService main = new FenpanService();
Map<String, Zong> zongMap = main.readFile(readUrl);
Map<Zong, List<Plate>> zongListMap = new HashMap<>();
//读取需要转宗的文件夹
Integer i = 0;
for (String key : zongMap.keySet()) {
List<Plate> plateList = new ArrayList<>();
Zong zong = zongMap.get(key);
List<Roll> rollList = zong.getRollList();
Plate plate = new Plate(Integer.parseInt(Config.getParam("plate.size")), "盘" + i++);
for (Roll roll : rollList) {
Boolean put = plate.put(roll);
if (!put) {
//磁盘放不进去了
plateList.add(plate);
plate = new Plate(Integer.parseInt(Config.getParam("plate.size")), "盘" + i++);
}
}
plateList.add(plate);
zongListMap.put(zong, plateList);
}
//copy 文件到新的目录
for (Zong zong : zongListMap.keySet()) {
File saveUrlFile = new File(saveUrl + zong.getName());
if (!saveUrlFile.exists()) {
FileUtils.createDirectory(saveUrlFile);
}
for (Plate plate : zongListMap.get(zong)) {
for (Roll roll : plate.getRollList()) {
copyFolder(new File(roll.getAbsolutePath()), new File(saveUrlFile + "/" + plate.getName() + "/" + roll.getName()));
}
}
}
//输出text
for (Zong zong : zongListMap.keySet()) {
System.out.println(zong.getName());
for (Plate plate : zongListMap.get(zong)) {
System.out.print(plate.getName() + " --- ");
for (Roll roll : plate.getRollList()) {
System.out.print(roll.getName() + ",");
}
System.out.println();
}
}
//转换成 宗。卷,件 。
//放到 宗,盘 下面
//输出目录结构
} catch (IOException e) {
log.error("读取配置文件失败!", e);
throw new RuntimeException(e);
}
}
public static void main(String[] args) throws IOException {
//读取配置文件。
Config.loadConfig();
String saveUrl = Config.getParam("file.save.url");
String readUrl = Config.getParam("file.read.url");
new FenpanService().fenpan(saveUrl,readUrl);
}
public Map<String, Zong> readFile(String readUrl) {
//读取文件夹。
List<Pieces> pieces = new ArrayList<>();
Map<String, Roll> rollMap = new HashMap<>();
Map<String, Zong> zongMap = new HashMap<>();
this.findAllDir(readUrl, pieces);
//写入文件
for (Pieces piece : pieces) {
//根据文件类型
if (piece.getFileTypeEnum() == FileTypeEnum.WORD) {
//从word 直接提取图片
} else if (piece.getFileTypeEnum() == FileTypeEnum.PDF) {
// 从pdf 提取图片
} else {
//是图片,直接从图片提取
List<Document> documentList = new ArrayList<>();
File sourceFile = new File(piece.getAbsolutePath());
File[] files = sourceFile.listFiles();
for (File file : files) {
try {
ImageInfo imageInfo = Imaging.getImageInfo(file);
int height = imageInfo.getHeight();
int width = imageInfo.getWidth();
int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
Document document = new Document(width, height, physicalHeightDpi);
documentList.add(document);
} catch (IOException e) {
FileUtils.delete(file);
throw new RuntimeException("非图片格式", e);
} catch (ImageReadException e) {
FileUtils.delete(file);
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
FileUtils.delete(file);
}
}
piece.put(documentList);
}
//填充卷
File file = new File(piece.getAbsolutePath());
File parentFile = file.getParentFile();
String name = parentFile.getName();
// System.out.println(name);
Roll roll = rollMap.get(name);
if (roll == null) {
roll = new Roll(name, parentFile.getAbsolutePath());
}
roll.putPieces(piece);
rollMap.put(name, roll);
}
//填充宗
for (String name : rollMap.keySet()) {
Roll roll = rollMap.get(name);
File file = new File(roll.getAbsolutePath());
String zongName = file.getParentFile().getName();
Zong zong = zongMap.get(zongName);
if (zong == null) {
zong = new Zong(file.getParentFile().getAbsolutePath(), file.getParentFile().getName());
}
zong.put(rollMap.get(name));
zongMap.put(zongName, zong);
}
return zongMap;
}
private void findAllDir(String absolutePath, List<Pieces> allDirectory) {
File sourceFile = new File(absolutePath);
File[] files = sourceFile.listFiles();
for (File o : files) {
if (o.isDirectory()) {
findAllDir(o.getAbsolutePath(), allDirectory);
}
if (o.isFile()) {
//判断是word,pdf,pic
if (o.getName().endsWith(".pdf")) {
Pieces pieces = new Pieces(FileTypeEnum.PDF, o.getAbsolutePath(), o.getName());
allDirectory.add(pieces);
} else if (o.getName().endsWith(".docx") || o.getName().endsWith(".doc")) {
Pieces pieces = new Pieces(FileTypeEnum.WORD, o.getAbsolutePath(), o.getName());
allDirectory.add(pieces);
} else if (o.getName().endsWith(".jpg") || o.getName().endsWith(".png")
|| o.getName().endsWith(".jpeg") || o.getName().endsWith(".tif")
|| o.getName().endsWith(".tiff")) {
Pieces pieces = new Pieces(FileTypeEnum.JPG, o.getParentFile().getAbsolutePath(), o.getParentFile().getName());
allDirectory.add(pieces);
} else {
FileUtils.delete(new File(o.getAbsolutePath()));
System.out.println("请删除无效的文件:" + o.getAbsolutePath());
throw new RuntimeException("请删除无效的文件:" + o.getAbsolutePath());
}
break;
}
}
}
public static void copyFolder(File sourceFolder, File destinationFolder) throws IOException {
if (!destinationFolder.exists()) {
destinationFolder.mkdirs();
}
for (File file : sourceFolder.listFiles()) {
if (file.isDirectory()) {
copyFolder(file, newFile(destinationFolder, file));
} else {
Path sourcePath = file.toPath();
Path destinationPath = newFile(destinationFolder, file).toPath();
Files.copy(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING);
}
}
}
public static File newFile(File parentDir, File childFile) {
return new File(parentDir, childFile.getName());
}
}

@ -0,0 +1,7 @@
package com.docus.sw.fenpan;
public enum FileTypeEnum {
WORD,
PDF,
JPG
}

@ -0,0 +1,45 @@
package com.docus.sw.fenpan;
import javax.swing.*;
import java.awt.*;
/**
* @author EdwinD
* @create 2020.08.19 08:31
* @desc Swing
**/
public class JFrameDemo1 {
public static void main(String[] args) {
new JFrameDemo1().init();
}
// init()初始化。
public void init() {
JFrame jFrame = new JFrame("这是我们的JFrame窗口。");
jFrame.setVisible(true);
jFrame.setBackground(Color.BLUE);
jFrame.setBounds(100, 100, 1024, 900);
jFrame.setLayout(new FlowLayout());
Panel panel2 = new Panel();
panel2.setLayout(new FlowLayout());
JLabel jl=new JLabel();
jl.setBounds(10,50,500,300);
JTextField jtf =new JTextField();
jtf.setBounds(10,10,150,30);
panel2.add(jtf);
JButton jButton2 = new JButton("启动");
panel2.add(jButton2);
jFrame.add(panel2);
// 关闭事件
jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}

@ -0,0 +1,38 @@
package com.docus.sw.fenpan;
import net.miginfocom.swing.MigLayout;
import javax.swing.*;
import java.awt.*;
public class MainJFrame extends JFrame {
public void init(){
JFrame jFrame = new JFrame("这是我们的JFrame窗口。");
jFrame.setVisible(true);
jFrame.setBackground(Color.BLUE);
jFrame.setBounds(0, 0, 1324, 900);
MigLayout layout = new MigLayout("wrap 2");
JPanel panel = new JPanel(layout);
panel.setVisible(true);
panel.add(new JLabel("Name"));
panel.add(new JTextField(""), "growx");
panel.add(new JLabel("Age"));
panel.add(new JTextField(""), "growx");
panel.add(new JLabel("Address"));
panel.add(new JTextArea(5, 20), "growx");
panel.add(new Button("提交"));
panel.add(new Button("关闭"));
jFrame.add(panel);
// 关闭事件
jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MainJFrame().init();
}
}

@ -0,0 +1,324 @@
package com.docus.sw.fenpan;
import com.docus.sw.Config;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class MyApplication {
public static void main(String[] args) throws IOException {
Config.loadConfig();
// 获取系统支持的外观信息
UIManager.LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();
// 遍历可用的外观并设置所选外观
for (UIManager.LookAndFeelInfo info : lookAndFeels) {
if ("Nimbus".equals(info.getName())) { // 选择Nimbus外观
try {
UIManager.setLookAndFeel(info.getClassName());
break;
} catch (Exception e) {
e.printStackTrace();
}
}
}
SwingUtilities.invokeLater(() -> createAndShowGUI());
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("缩微工具");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 400);
JTabbedPane tabbedPane = new JTabbedPane();
// 参数设置标签页
JPanel paramPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(5, 5, 5, 5);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.WEST;
paramPanel.add(new JLabel("宗前缀名:"), gbc);
gbc.gridx = 1;
gbc.anchor = GridBagConstraints.CENTER;
JTextField zongPreJtf = new JTextField(20);
paramPanel.add(zongPreJtf, gbc);
JPanel sizePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
sizePanel.add(new JLabel("A3大小尺寸 长:"));
JTextField a3LongJtf = new JTextField(5);
sizePanel.add(a3LongJtf);
sizePanel.add(new JLabel("宽:"));
JTextField a3WidthJtf = new JTextField(5);
sizePanel.add(a3WidthJtf);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.WEST;
paramPanel.add(sizePanel, gbc);
gbc.gridx = 0;
gbc.gridy = 2;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.WEST;
paramPanel.add(new JLabel("盘大小:"), gbc);
gbc.gridx = 1;
gbc.anchor = GridBagConstraints.CENTER;
JTextField plateSizeJtf = new JTextField(20);
paramPanel.add(plateSizeJtf, gbc);
JPanel modePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
modePanel.add(new JLabel("模式选择:"));
String[] modes = {"图片", "word", "pdf"};
JComboBox<String> modeComboBox = new JComboBox<>(modes);
modePanel.add(modeComboBox);
gbc.gridx = 0;
gbc.gridy = 3;
gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.WEST;
paramPanel.add(modePanel, gbc);
gbc.gridx = 0;
gbc.gridy = 4;
gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.CENTER;
JButton jButton = new JButton("保存设置");
paramPanel.add(jButton, gbc);
//添加事件
jButton.addActionListener(e -> {
//宗名
System.out.println(zongPreJtf.getText());
//模式
String selectedValue = (String) modeComboBox.getSelectedItem();
System.out.println(selectedValue);
//a3 图片大小
System.out.println(a3LongJtf.getText());
System.out.println(a3WidthJtf.getText());
//盘大小
String text = plateSizeJtf.getText();
System.out.println(text);
Map<String,String> keyvalue = new HashMap<>();
keyvalue.put("zong.name.prefix",zongPreJtf.getText());
keyvalue.put("file.mode",selectedValue);
keyvalue.put("a3.length",a3LongJtf.getText());
keyvalue.put("a3.width",a3WidthJtf.getText());
keyvalue.put("plate.size",plateSizeJtf.getText());
try {
Config.updateConfig(keyvalue);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
// 分盘工具标签页
JPanel splitPanel = new JPanel(new BorderLayout());
JPanel leftPanel = new JPanel(new GridBagLayout());
GridBagConstraints leftGbc = new GridBagConstraints();
leftGbc.insets = new Insets(5, 5, 5, 5);
leftGbc.gridx = 0;
leftGbc.gridy = 0;
leftPanel.add(new JLabel("分盘目录:"), leftGbc);
JTextField folderField = new JTextField(20);
leftGbc.gridx = 1;
leftGbc.gridwidth = 1;
leftPanel.add(folderField, leftGbc);
JButton folderChooserButton = new JButton("选择文件夹");
folderChooserButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
folderField.setText(selectedFile.getAbsolutePath());
}
}
});
leftGbc.gridx = 2;
leftPanel.add(folderChooserButton, leftGbc);
leftGbc.gridx = 0;
leftGbc.gridy = 1;
leftPanel.add(new JLabel("保存路径:"), leftGbc);
JTextField savePathField = new JTextField(20);
leftGbc.gridx = 1;
leftPanel.add(savePathField, leftGbc);
JButton savePathChooserButton = new JButton("选择文件夹");
savePathChooserButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
savePathField.setText(selectedFile.getAbsolutePath());
}
}
});
leftGbc.gridx = 2;
leftPanel.add(savePathChooserButton, leftGbc);
leftGbc.gridx = 0;
leftGbc.gridy = 2;
leftGbc.gridwidth = 2;
leftGbc.anchor = GridBagConstraints.CENTER;
JButton fenpanJbtn = new JButton("开始分盘");
leftPanel.add(fenpanJbtn, leftGbc);
JTextArea logTextArea = new JTextArea();
JScrollPane logScrollPane = new JScrollPane(logTextArea);
logScrollPane.setPreferredSize(new Dimension(200, 200));
JPanel rightPanel = new JPanel(new BorderLayout());
rightPanel.add(logScrollPane, BorderLayout.CENTER);
fenpanJbtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 在EDT上执行更新操作
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
logTextArea.append(df.format(new Date())+": 开始分盘。。。"+ "\n");
}
});
// 启动一个异步任务
Thread workerThread = new Thread(() -> {
// 执行长时间运行的业务操作
// 模拟耗时操作
String saveUrl = savePathField.getText();
String readUrl = folderField.getText();
new FenpanService().fenpan(saveUrl,readUrl);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// 在EDT上更新UI
logTextArea.append(df.format(new Date())+": 分盘结束。。。"+ "\n");
}
});
});
workerThread.start(); // 启动线程
}
});
splitPanel.add(leftPanel, BorderLayout.WEST);
splitPanel.add(rightPanel, BorderLayout.CENTER);
tabbedPane.addTab("参数设置", paramPanel);
tabbedPane.addTab("分盘工具", splitPanel);
tabbedPane.addTab("索引工具", createIndexPanel());
frame.add(tabbedPane);
frame.setVisible(true);
//加载数据
zongPreJtf.setText(Config.getParam("zong.name.prefix"));
a3LongJtf.setText(Config.getParam("a3.length"));
a3WidthJtf.setText(Config.getParam("a3.width"));
plateSizeJtf.setText(Config.getParam("plate.size"));
}
private static JPanel createIndexPanel() {
JPanel indexPanel = new JPanel(new BorderLayout());
JPanel leftIndexPanel = new JPanel(new GridBagLayout());
GridBagConstraints leftIndexGbc = new GridBagConstraints();
leftIndexGbc.insets = new Insets(5, 5, 5, 5);
leftIndexGbc.gridx = 0;
leftIndexGbc.gridy = 0;
leftIndexGbc.anchor = GridBagConstraints.WEST;
leftIndexPanel.add(new JLabel("文件路径选择:"), leftIndexGbc);
JTextField filePathField = new JTextField(20);
leftIndexGbc.gridx = 1;
leftIndexGbc.gridwidth = 1;
leftIndexPanel.add(filePathField, leftIndexGbc);
JButton fileChooserButton = new JButton("选择文件");
leftIndexGbc.gridx = 2;
leftIndexPanel.add(fileChooserButton, leftIndexGbc);
// 文件选择按钮的动作监听器,打开文件选择对话框
fileChooserButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
filePathField.setText(selectedFile.getAbsolutePath());
}
}
});
leftIndexGbc.gridx = 0;
leftIndexGbc.gridy = 1;
leftIndexGbc.anchor = GridBagConstraints.WEST;
leftIndexPanel.add(new JLabel("图片dpi:"), leftIndexGbc);
leftIndexGbc.gridx = 1;
JTextField dpiField = new JTextField(5);
leftIndexPanel.add(dpiField, leftIndexGbc);
// ... 其他标签左对齐,与前面的代码相同 ...
leftIndexGbc.gridx = 0;
leftIndexGbc.gridy = 2;
leftIndexGbc.gridwidth = 2;
leftIndexGbc.anchor = GridBagConstraints.CENTER;
leftIndexPanel.add(new JButton("开始生成索引"), leftIndexGbc);
JTextArea indexLogTextArea = new JTextArea();
JScrollPane indexLogScrollPane = new JScrollPane(indexLogTextArea);
indexLogScrollPane.setPreferredSize(new Dimension(200, 200));
JPanel rightIndexPanel = new JPanel(new BorderLayout());
rightIndexPanel.add(indexLogScrollPane, BorderLayout.CENTER);
indexPanel.add(leftIndexPanel, BorderLayout.WEST);
indexPanel.add(rightIndexPanel, BorderLayout.CENTER);
return indexPanel;
}
}

@ -0,0 +1,48 @@
package com.docus.sw.fenpan;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.IOException;
public class MyJFrame extends JFrame {
JPanel center =new JPanel();
public MyJFrame()throws IOException {
init();
this.setVisible(true);
}
private void init(){
this.setSize(800,600);
this.setTitle("随机小游戏");
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null); //设置为空布局
this.setResizable(false);
this.setBackground(Color.BLUE);
JLabel jl=new JLabel();
jl.setBounds(10,50,500,300);
JTextField jtf =new JTextField(); //文本框
jtf.setBounds(10,10,150,30);
JButton jb=new JButton("搜索"); //鼠标单击监听器
jb.setBounds(180,10,60,30);
jb.addActionListener(
(ActionListener) ->{
String text =jtf.getText();
jl.setText(text+"是个难得的人才");
});
jtf.addActionListener((ActionEvent e)->{ //常用键enter 用addActionListener
jb.doClick();
});
this.add(jl);
this.add(jtf);
this.add(jb);
}
public static void main(String[] args) throws IOException {
new MyJFrame().init();
}
}

@ -0,0 +1,51 @@
package com.docus.sw.fenpan;
import lombok.Getter;
import java.util.List;
/**
*
*/
@Getter
public class Pieces {
/**
*
*/
private Integer size;
/**
*
*/
private FileTypeEnum fileTypeEnum;
private String name;
private String absolutePath;
List<Document> documentList;
public Pieces(FileTypeEnum fileTypeEnum, String absolutePath, String name) {
this.fileTypeEnum = fileTypeEnum;
this.absolutePath = absolutePath;
this.name = name;
}
public void put(List<Document> documentList) {
this.documentList = documentList;
int size = 0;
for (Document document : documentList) {
if (document.isA3()) {
size += 2;
} else {
size += 1;
}
}
this.size = size;
}
}

@ -0,0 +1,48 @@
package com.docus.sw.fenpan;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
@Getter
public class Plate {
/**
* 2800
*/
private Integer totalLength;
/**
*
*/
private Integer already;
private List<Roll> rollList;
private String name;
//是否还可以放下新的卷
public Boolean put(Roll roll) {
if(already + roll.getSize() - totalLength >= 0){
return false;
}
this.already = already+roll.getSize();
rollList.add(roll);
return true;
}
public Plate(Integer totalLength,String name){
this.totalLength = totalLength;
this.rollList = new ArrayList<>();
this.already = 0;
this.name = name;
}
}

@ -0,0 +1,43 @@
package com.docus.sw.fenpan;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
@Getter
@AllArgsConstructor
public class Roll {
private String name;
private List<Pieces> piecesList;
private String absolutePath;
public Integer getSize(){
Integer size = 0;
for(Pieces pieces:piecesList){
size+= pieces.getSize();
}
return size;
}
public Roll(String name, String absolutePath) {
this.name = name;
this.absolutePath = absolutePath;
piecesList = new ArrayList<>();
}
public void putPieces(Pieces pieces){
piecesList.add(pieces);
}
}

@ -0,0 +1,28 @@
package com.docus.sw.fenpan;
import com.docus.sw.Config;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
@Getter
public class Zong {
private String name;
private List<Roll> rollList;
private String absolutePath;
public Zong(String absolutePath,String name){
this.name = Config.getParam("zong.name.prefix")+name;
this.absolutePath = absolutePath;
rollList = new ArrayList<>();
}
public void put(Roll roll){
rollList.add(roll);
}
}

@ -0,0 +1,64 @@
package com.docus.sw.souyin;
import com.itextpdf.text.Font;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import org.apache.poi.ss.usermodel.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class ExcelToPdfDemo {
public static void main(String[] args) {
try (Workbook workbook = WorkbookFactory.create(new File("C:\\jiahsi-saomiao\\缩微\\test\\test.xls"));
FileOutputStream fos = new FileOutputStream("C:\\jiahsi-saomiao\\缩微\\test\\example.pdf")) {
// 获取第一个工作表
Sheet sheet = workbook.getSheetAt(0);
// 创建PDF文档对象
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// 创建PDF输出流
PdfWriter writer = PdfWriter.getInstance(document, fos);
// 打开PDF文档
document.open();
// 创建PDF表格对象
PdfPTable table = new PdfPTable(sheet.getRow(0).getLastCellNum());
// 设置表格宽度
table.setWidthPercentage(100);
// 设置表格标题
Font font = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED,10f, Font.NORMAL, BaseColor.BLACK);
Paragraph title = new Paragraph("",font);
title.setAlignment(Element.ALIGN_CENTER);
document.add(title);
// 添加表格内容
for (Row row : sheet) {
for (Cell cell : row) {
PdfPCell pdfCell = new PdfPCell(new Paragraph(cell.getStringCellValue(), new Font(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 12)));
pdfCell.setBorderWidth(1f);
pdfCell.setHorizontalAlignment(Element.ALIGN_CENTER);
pdfCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(pdfCell);
}
}
// 添加表格到PDF文档
document.add(table);
// 关闭PDF文档
document.close();
writer.close();
} catch (IOException | DocumentException e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,88 @@
package com.docus.sw.souyin;
import com.alibaba.excel.EasyExcel;
import com.itextpdf.text.pdf.PdfWriter;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
/**
* @author
*/
public class ExcelUtil {
public static void easyExcelTest() throws Exception {
String fileName = "C:\\jiahsi-saomiao\\缩微\\test\\test.xls";
//查询出导出的数据
List<MesEasyExcel> mesEasyExcels = getData();
try {
EasyExcel.write(fileName, MesEasyExcel.class).sheet("test").doWrite(mesEasyExcels);
} catch (Exception e) {
System.out.println(e.getMessage());
}
;
try {
FileInputStream excelFile = new FileInputStream(new File(fileName));
Workbook workbook = new HSSFWorkbook(excelFile);
// 选择要转换的工作表(这里假设你选择第一个工作表)
Sheet sheet = workbook.getSheetAt(0);
// 创建一个输出流用于将Excel内容写入PDF文件
FileOutputStream pdfOutput = new FileOutputStream("C:\\jiahsi-saomiao\\缩微\\test\\output.pdf");
// 使用iText库创建一个PDF文档
com.itextpdf.text.Document pdfDocument = new com.itextpdf.text.Document();
PdfWriter.getInstance(pdfDocument, pdfOutput);
pdfDocument.open();
// 读取Excel单元格内容并将其写入PDF
for (Row row : sheet) {
for (Cell cell : row) {
pdfDocument.add(new com.itextpdf.text.Paragraph(cell.toString()));
}
}
pdfDocument.close();
pdfOutput.close();
System.out.println("Excel文件已成功转换为PDF文件。");
} catch (Exception e) {
e.printStackTrace();
}
}
private static List<MesEasyExcel> getData() throws Exception {
List<MesEasyExcel> list = new ArrayList<MesEasyExcel>();
for (int i = 0; i < 100; i++) {
MesEasyExcel m = new MesEasyExcel();
m.setZongName("全宗名" + i);
m.setPlateName("盘2");
m.setRollName("卷名");
m.setPieces("档号");
m.setNums("80");
m.setStartNum("28");
list.add(m);
}
return list;
}
public static void main(String[] args) throws Exception {
ExcelUtil.easyExcelTest();
}
}

@ -0,0 +1,24 @@
package com.docus.sw.souyin;
import lombok.AllArgsConstructor;
import lombok.Data;
@AllArgsConstructor
@Data
public class IndexPageRow {
private String zongName;
private String phNum;
private String rollName;
private String piecesName;
private String nums;
private Integer start;
}

@ -0,0 +1,14 @@
package com.docus.sw.souyin;
import lombok.AllArgsConstructor;
import lombok.Data;
@AllArgsConstructor
@Data
public class IndexPlate {
private String absolutePath;
private String name;
}

@ -0,0 +1,30 @@
package com.docus.sw.souyin;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
/**
* @author
*/
@Data
public class MesEasyExcel {
@ExcelProperty("全宗名")
private String zongName;
@ExcelProperty("盘号")
private String plateName;
@ExcelProperty("卷名")
private String rollName;
@ExcelProperty("档号")
private String pieces;
@ExcelProperty("数量")
private String nums;
@ExcelProperty("起始缩微号")
private String startNum;
}

@ -0,0 +1,34 @@
package com.docus.sw.souyin;
import org.apache.commons.lang3.tuple.Pair;
import java.util.List;
public class PdfToPic {
public static void main(String[] args) {
new PdfToPic().pdfDocumentToImage2();
}
/**
* PDF
* :org.junit.Test
*/
public void pdfDocumentToImage2() {
String source = "C:\\jiahsi-saomiao\\缩微\\test\\example.pdf";
String desFileName = "example";
String desFilePath = "C:\\jiahsi-saomiao\\缩微\\test\\";
String imageType = "png";
Pair<Boolean, Object> pair = PdfUtil.pdfToImage(source, desFilePath, desFileName, imageType);
System.out.println("PDF文档转化为图片结果" + pair.getLeft());
if (!pair.getLeft()) {
System.out.println("" + pair.getRight());
} else {
List<String> fileList = (List<String>) pair.getRight();
System.out.println("转化的文件的内容:");
fileList.forEach(System.out::println);
}
}
}

@ -0,0 +1,73 @@
package com.docus.sw.souyin;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class PdfUtil {
/**
* @param source
* @param desFilePath
* @param desFileName +线+1
* @param imageType
* @return
*/
public static Pair<Boolean, Object> pdfToImage(String source, String desFilePath, String desFileName, String imageType) {
//通过给定的源路径名字符串创建一个File实例
File file = new File(source);
if (!file.exists()) {
return Pair.of(false, "文件不存在,无法转化");
}
//目录不存在则创建目录
File destination = new File(desFilePath);
if (!destination.exists()) {
boolean flag = destination.mkdirs();
System.out.println("创建文件夹结果:" + flag);
}
PDDocument doc = null;
try {
//加载PDF文件
doc = PDDocument.load(file);
PDFRenderer renderer = new PDFRenderer(doc);
//获取PDF文档的页数
int pageCount = doc.getNumberOfPages();
System.out.println("文档一共" + pageCount + "页");
List<Object> fileList = new ArrayList<>();
for (int i = 0; i < pageCount; i++) {
//只有一页的时候文件名为传入的文件名大于一页的文件名为文件名_自增加数字(从1开始)
String realFileName = pageCount > 1 ? desFileName + "_" + (i + 1) : desFileName;
//每一页通过分辨率和颜色值进行转化
BufferedImage bufferedImage = renderer.renderImageWithDPI(i, 96 * 2, ImageType.RGB);
String filePath = desFilePath + File.separator + realFileName + "." + imageType;
//写入文件
ImageIO.write(bufferedImage, imageType, new File(filePath));
//文件名存入list
fileList.add(filePath);
}
return Pair.of(true, fileList);
} catch (IOException e) {
e.printStackTrace();
return Pair.of(false, "PDF转化图片异常");
} finally {
try {
if (doc != null) {
doc.close();
}
} catch (IOException e) {
System.out.println("关闭文档失败");
e.printStackTrace();
}
}
}
}

@ -0,0 +1,78 @@
package com.docus.sw.souyin;
import com.alibaba.excel.util.FileUtils;
import com.docus.sw.fenpan.FileTypeEnum;
import com.docus.sw.fenpan.Pieces;
import com.docus.sw.fenpan.Plate;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class SuoyinService {
//读取分盘后的结果。
//宗,盘,卷,件
//输出目录文件
//生成片头,片尾
//统计出需要使用的 胶片量
public static void main(String[] args) {
}
public void test(){
ArrayList<IndexPlate> indexPlates = new ArrayList<>();
findAllDir("",indexPlates);
//计算出宗
//计算出每个盘的目录。
//读取片头
//读取片尾
//生成excel
//生成图片
//
}
private void findAllDir(String absolutePath, List<IndexPlate> allDirectory) {
File sourceFile = new File(absolutePath);
File[] files = sourceFile.listFiles();
for (File o : files) {
if (o.isDirectory()) {
findAllDir(o.getAbsolutePath(), allDirectory);
}
if (o.isFile()) {
//判断是word,pdf,pic
if (o.getName().endsWith(".pdf")) {
// new Plate()
} else if (o.getName().endsWith(".docx") || o.getName().endsWith(".doc")) {
} else if (o.getName().endsWith(".jpg") || o.getName().endsWith(".png")
|| o.getName().endsWith(".jpeg") || o.getName().endsWith(".tif")
|| o.getName().endsWith(".tiff")) {
//件
File parentFile = o.getParentFile()
//卷
.getParentFile()
//盘
.getParentFile();
IndexPlate indexPlate = new IndexPlate(parentFile.getAbsolutePath(), parentFile.getName());
allDirectory.add(indexPlate);
} else {
FileUtils.delete(new File(o.getAbsolutePath()));
System.out.println("请删除无效的文件:" + o.getAbsolutePath());
throw new RuntimeException("请删除无效的文件:" + o.getAbsolutePath());
}
break;
}
}
}
}
Loading…
Cancel
Save