first commit

This commit is contained in:
yangjiyu
2022-07-04 17:53:30 +08:00
commit 6fd95632f7
15 changed files with 1782 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
BIN
View File
Binary file not shown.
+2
View File
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
Vendored
+316
View File
@@ -0,0 +1,316 @@
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /usr/local/etc/mavenrc ] ; then
. /usr/local/etc/mavenrc
fi
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="`/usr/libexec/java_home`"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`\\unset -f command; \\command -v java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=`cd "$wdir/.."; pwd`
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found .mvn/wrapper/maven-wrapper.jar"
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
if [ -n "$MVNW_REPOURL" ]; then
jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
else
jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
fi
while IFS="=" read key value; do
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
esac
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Downloading from: $jarUrl"
fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if $cygwin; then
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
fi
if command -v wget > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
else
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
fi
elif command -v curl > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
curl -o "$wrapperJarPath" "$jarUrl" -f
else
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
# For Cygwin, switch paths to Windows format before running javac
if $cygwin; then
javaClass=`cygpath --path --windows "$javaClass"`
fi
if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Compiling MavenWrapperDownloader.java ..."
fi
# Compiling the Java class
("$JAVA_HOME/bin/javac" "$javaClass")
fi
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
# Running the downloader
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Running MavenWrapperDownloader.java ..."
fi
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" \
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
Vendored
+188
View File
@@ -0,0 +1,188 @@
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
)
) else (
if not "%MVNW_REPOURL%" == "" (
SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
)
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM work with both Windows and non-Windows executions.
set MAVEN_CMD_LINE_ARGS=%*
%MAVEN_JAVA_EXE% ^
%JVM_CONFIG_MAVEN_PROPS% ^
%MAVEN_OPTS% ^
%MAVEN_DEBUG_OPTS% ^
-classpath %WRAPPER_JAR% ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%"=="on" pause
if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
cmd /C exit /B %ERROR_CODE%
+110
View File
@@ -0,0 +1,110 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.aos</groupId>
<artifactId>aos-file-identify</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>aos-file-identify</name>
<description>aos-file-identify</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- swagger -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
<!-- mybatis plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.11</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<!-- pdf处理类 -->
<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>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.71</version>
</dependency>
<!-- excel处理类 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.1.1</version>
</dependency>
<!-- json处理类 -->
<dependency>
<groupId>com.mastfrog</groupId>
<artifactId>jackson</artifactId>
<version>2.8.3</version>
</dependency>
<!-- hutool -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,13 @@
package com.aos.fileidentify;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AosFileIdentifyApplication {
public static void main(String[] args) {
SpringApplication.run(AosFileIdentifyApplication.class, args);
}
}
@@ -0,0 +1,44 @@
package com.aos.fileidentify.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* <p>Company: 成都返空汇网络技术有限公司</p>
* <p>Description: </p>
*
* @author yangjiyu
* @version x.x.x
* @email "mailto:yangjiyu@fkhwl.com"
* @date 2022.07.04 09:50
* @since x.x.x
*/
@Configuration
@EnableSwagger2
public class Knife4jConfiguration {
@Bean(value = "defaultApi2")
public Docket defaultApi2() {
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("AOS&中粮大悦城集团")
.description("# 人力资源中心数据处理")
.version("1.0")
.build())
//分组名称
.groupName("2.X版本")
.select()
//这里指定Controller扫描包路径
.apis(RequestHandlerSelectors.basePackage("com.aos.fileidentify.controller"))
.paths(PathSelectors.any())
.build();
return docket;
}
}
@@ -0,0 +1,44 @@
package com.aos.fileidentify.controller;
import com.aos.fileidentify.service.FileIdentifyService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
/**
* <p>Company: 成都返空汇网络技术有限公司</p>
* <p>Description: </p>
*
* @author yangjiyu
* @version x.x.x
* @email "mailto:yangjiyu@fkhwl.com"
* @date 2022.07.04 09:53
* @since x.x.x
*/
@Api(value = "PDF文件上传识别服务")
@RestController("/fileIdentify")
@AllArgsConstructor
public class FileIdentifyController {
private final FileIdentifyService fileIdentifyService;
/**
* Identify pdf
*
* @param file file
* @since 0.0.1
*/
@ApiOperation(value = "pdf文件解析服务")
@PostMapping(value = "/pdf")
public void identifyPdf(@RequestPart("pdf") MultipartFile file) {
this.fileIdentifyService.process(file);
}
}
@@ -0,0 +1,25 @@
package com.aos.fileidentify.entity.dto;
import lombok.Data;
/**
* <p>Company: 成都返空汇网络技术有限公司</p>
* <p>Description: </p>
*
* @author yangjiyu
* @version 1.0.0
* @email "mailto:yangjiyu@fkhwl.com"
* @date 2022.07.04 10:28
* @since 1.0.0
*/
@Data
public class PdfFileDTO {
/** 姓名 */
private String name;
/** 现任职位 */
private String currentPosition;
/** 曾任职位 */
private String previousPosition;
/** 兼任职位 */
private String partTimePosition;
}
@@ -0,0 +1,23 @@
package com.aos.fileidentify.service;
import org.springframework.web.multipart.MultipartFile;
/**
* <p>Company: 成都返空汇网络技术有限公司</p>
* <p>Description: </p>
*
* @author yangjiyu
* @version x.x.x
* @email "mailto:yangjiyu@fkhwl.com"
* @date 2022.07.04 11:00
* @since x.x.x
*/
public interface FileIdentifyService {
/**
* Process
*
* @param file file
* @since 0.0.1
*/
void process(MultipartFile file);
}
@@ -0,0 +1,70 @@
package com.aos.fileidentify.service.impl;
import com.aos.fileidentify.entity.dto.PdfFileDTO;
import com.aos.fileidentify.service.FileIdentifyService;
import com.aos.fileidentify.util.PdfUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
/**
* <p>Company: 成都返空汇网络技术有限公司</p>
* <p>Description: </p>
*
* @author yangjiyu
* @version 1.0.0
* @email "mailto:yangjiyu@fkhwl.com"
* @date 2022.07.04 11:00
* @since 1.0.0
*/
@Slf4j
@Service
public class FileIdentifyServiceImpl implements FileIdentifyService {
/**
* Process
*
* @param file file
* @since 0.0.1
*/
@Override
public void process(MultipartFile file) {
Assert.notNull(file, "上传数据为空");
try {
String pdfContent = PdfUtils.getPdfContent(file);
String title = pdfContent.replaceAll("任命通知.*", "") + "任命通知";
String mainBody = pdfContent.replaceAll(".*现公布如下:", "").replaceAll("特此通知.*", "");
List<String> tempList = Arrays.stream(mainBody.split("")).collect(Collectors.toList());
log.info(title);
List<PdfFileDTO> pdfFileDTOList = new ArrayList<>();
for (String str : tempList) {
PdfFileDTO pdfFileDTO = new PdfFileDTO();
pdfFileDTO.setName(str.replaceAll("同志.*", ""));
List<String> tempList2 = Arrays.stream(str.split("")).collect(Collectors.toList());
for (String str2 : tempList2) {
if (str2.contains("同志兼任")) {
pdfFileDTO.setPartTimePosition(str2.replaceAll(".*同志兼任", ""));
} else if (str2.contains("同志任")) {
pdfFileDTO.setCurrentPosition(str2.replaceAll(".*同志任", ""));
} else if (str2.contains("不再担任")) {
pdfFileDTO.setPreviousPosition(str2.replaceAll(".*不再担任", ""));
}
}
log.info(pdfFileDTO.toString());
pdfFileDTOList.add(pdfFileDTO);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,893 @@
package com.aos.fileidentify.util;
import com.itextpdf.text.Anchor;
import com.itextpdf.text.Annotation;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chapter;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.List;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.Section;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfAnnotation;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfTransition;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.draw.DottedLineSeparator;
import com.itextpdf.text.pdf.draw.LineSeparator;
import com.itextpdf.text.pdf.draw.VerticalPositionMark;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.StringJoiner;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* <p>Company: 成都返空汇网络技术有限公司</p>
* <p>Description: </p>
*
* @author yangjiyu
* @version 1.0.0
* @email "mailto:yangjiyu@fkhwl.com"
* @date 2022.07.04 11:43
* @since 1.0.0
*/
public class PdfUtils {
public static final String FILE_DIR = "E:\\guor\\itext\\";
public static final String CONST_JPG_JAVA = FILE_DIR + "java.jpg";
public static final String CONST_JPG_NGINX = FILE_DIR + "nginx.jpg";
private static final String CONST_NEZHA = "哪吒编程";
private static final String CONST_NEZHA_PROGRAM = "获取Java学习资料请关注公众号:哪吒编程";
private static final String CONST_BIBIDONG = "比比东";
private static final String CONST_YUNYUN = "云韵";
private static final String CONST_BAIDU = "百度一下 你就知道";
private static final String CONST_BAIDU_URL = "https://www.baidu.com";
private static final String CONST_PAGE_FIRST = "第一页";
private static final String CONST_PAGE_SECOND = "第二页";
private static final String CONST_PAGE_THIRD = "第三页";
private static final String CONST_PAGE_FOUR = "第四页";
private static final String CONST_PAGE_FIVE = "第五页";
private static final String CONST_TITLE_FIRST = "一级标题";
private static final String CONST_TITLE_SECOND = "二级标题";
private static final String CONST_CONTENT = "内容";
// 普通中文字体
public static Font STATIC_FONT_CHINESE = null;
// 超链字体
public static Font STATIC_FONT_LINK = null;
public static Document document;
private static void pdfFontInit() throws IOException, DocumentException {
// 微软雅黑
BaseFont chinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
// 普通中文字体
STATIC_FONT_CHINESE = new Font(chinese, 12, Font.NORMAL);// Font.BOLD为加粗
// 超链字体
STATIC_FONT_LINK = new Font(chinese, 12, Font.NORMAL, BaseColor.BLUE);
}
// public static void main(String[] args) throws Exception {
// pdfFontInit();
// //createPDF();// 生成一个 PDF 文件
// //createPDFWithColor();// 设置PDF的页面大小和背景颜色
// //createPDFWithPassWord();// 创建带密码的PDF
// //createPDFWithNewPages();// 为PDF添加页
// //createPDFWithWaterMark();// 为PDF文件添加水印,背景图
// //createPDFWithContent();//插入块Chunk, 内容Phrase, 段落Paragraph, List
// //createPDFWithExtraContent();//插入Anchor, Image, Chapter, Section
// //draw();//画图
// //createPDFWithAlignment();//设置段落
// //createPDFToDeletePage();//删除 page
// //insertPage();// 插入 page
// //splitPDF();//分割 page
// //mergePDF();// 合并 PDF 文件
// //sortpage();// 排序page
// //setHeaderFooter();// 页眉,页脚
// //addColumnText();// 左右文字
// //setView();// 文档视图
// //pdfToZip();// 压缩PDF到Zip
// addAnnotation();// 注释
// }
/**
* 创建一个 PDF 文件,并添加文本
*/
public static void createPDF() throws IOException, DocumentException {
// 实例化 document
document = new Document();
// 生成文件
String path = FILE_DIR + "createPDF.pdf";
File file = new File(path);
if (!file.exists()) {
file.createNewFile();
}
PdfWriter.getInstance(document, new FileOutputStream(FILE_DIR + "createPDF.pdf"));
// 打开 document
document.open();
// 添加文本 此处无法写入中文 TODO
document.add(new Paragraph(CONST_NEZHA));
document.add(new Paragraph(CONST_NEZHA, STATIC_FONT_CHINESE));
// 关闭 document
document.close();
}
/**
* 创建PDF文件,修改文件的属性
*/
public static void createPDFWithColor() throws FileNotFoundException, DocumentException {
// 页面大小
Rectangle rect = new Rectangle(PageSize.A5.rotate());
// 页面背景色
rect.setBackgroundColor(BaseColor.YELLOW);
document = new Document(rect);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FILE_DIR + "createPDFWithColor.pdf"));
// PDF版本(默认1.4)
writer.setPdfVersion(PdfWriter.VERSION_1_6);
// 文档属性
document.addAuthor(CONST_NEZHA);
document.addTitle("我的第一个pdf");
// 页边空白
document.setMargins(10, 10, 10, 10);
// 打开
document.open();
document.add(new Paragraph(CONST_NEZHA, STATIC_FONT_CHINESE));
// 关闭
document.close();
}
/**
* 创建带密码的PDF
*/
public static void createPDFWithPassWord() throws FileNotFoundException, DocumentException {
// 页面大小
Rectangle rect = new Rectangle(PageSize.A5.rotate());
// 页面背景色
rect.setBackgroundColor(BaseColor.YELLOW);
document = new Document(rect);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FILE_DIR + "createPDFWithPassWord.pdf"));
// userPassword打开密码:"123"
// ownerPassword编辑密码: "123456"
writer.setEncryption("123".getBytes(), "123456".getBytes(), PdfWriter.ALLOW_SCREENREADERS, PdfWriter.STANDARD_ENCRYPTION_128);
document.open();
document.add(new Paragraph(CONST_NEZHA, STATIC_FONT_CHINESE));
document.close();
}
/**
* 为PDF添加页
*/
public static void createPDFWithNewPages() throws FileNotFoundException, DocumentException {
document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FILE_DIR + "createPDFAddNewPages.pdf"));
document.open();
document.add(new Paragraph(CONST_PAGE_FIRST, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_SECOND, STATIC_FONT_CHINESE));
writer.setPageEmpty(true);
document.newPage();
document.add(new Paragraph(CONST_PAGE_THIRD, STATIC_FONT_CHINESE));
document.close();
}
/**
* 为PDF文件添加水印,背景图
*/
public static void createPDFWithWaterMark() throws IOException, DocumentException {
FileOutputStream out = new FileOutputStream(FILE_DIR + "createPDFWithWaterMark.pdf");
document = new Document();
PdfWriter.getInstance(document, out);
document.open();
document.add(new Paragraph(CONST_PAGE_FIRST, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_SECOND, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_THIRD, STATIC_FONT_CHINESE));
document.close();
// 图片水印
PdfReader reader = new PdfReader(FILE_DIR + "createPDFWithWaterMark.pdf");
PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(FILE_DIR + "createPDFWithWaterMark2.pdf"));
Image img = Image.getInstance(CONST_JPG_JAVA);
img.setAbsolutePosition(200, 200);
PdfContentByte under = stamp.getUnderContent(1);
under.addImage(img);
// 文字水印
PdfContentByte over = stamp.getOverContent(2);
// 加载字库来完成对字体的创建
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
over.beginText();
// 设置颜色 默认为蓝色
over.setColorFill(BaseColor.RED);
// 设置字体字号
over.setFontAndSize(bf, 50);
// 设置起始位置
over.setTextMatrix(30, 30);
// 开始写入水印 左-下-倾斜度
over.showTextAligned(Element.ALIGN_LEFT, "nezha", 245, 400, 30);
over.endText();
// 背景图
Image img2 = Image.getInstance(CONST_JPG_NGINX);
img2.setAbsolutePosition(0, 0);
PdfContentByte under2 = stamp.getUnderContent(3);
under2.addImage(img2);
stamp.close();
reader.close();
}
/**
* 插入Chunk, Phrase, Paragraph, List
* Chunk : 块,PDF文档中描述的最小原子元素
* Phrase : 短语,Chunk的集合
* Paragraph : 段落,一个有序的Phrase集合
*/
public static void createPDFWithContent() throws DocumentException, FileNotFoundException {
FileOutputStream out = new FileOutputStream(FILE_DIR + "createPDFWithContent.pdf");
document = new Document();
PdfWriter.getInstance(document, out);
document.open();
// 添加块
document.add(new Chunk(CONST_NEZHA, STATIC_FONT_CHINESE));
Font font = new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD, BaseColor.WHITE);
Chunk id = new Chunk("springboot", font);
id.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f);
id.setTextRise(7);
document.add(id);
Font font2 = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD, BaseColor.WHITE);
Chunk id2 = new Chunk("springcloud", font2);
id2.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f);
id2.setTextRise(3);
id2.setUnderline(0.2f, -2f);
document.add(id2);
document.add(Chunk.NEWLINE);
// 添加一页,添加短语
document.newPage();
document.add(new Phrase("Phrase page"));
// 添加短语
Phrase director = new Phrase();
Chunk name = new Chunk(CONST_BIBIDONG, STATIC_FONT_CHINESE);
// 添加下划线(thickness:下划线的粗细,yPosition:下划线离字的距离)
name.setUnderline(0.5f, -1f);
director.add(name);
director.add(new Chunk(","));
director.add(new Chunk(" "));
director.add(new Chunk(CONST_YUNYUN, STATIC_FONT_CHINESE));
director.setLeading(24);
document.add(director);
// 添加一页
document.newPage();
Phrase director2 = new Phrase();
Chunk name2 = new Chunk(CONST_BIBIDONG, STATIC_FONT_CHINESE);
name2.setUnderline(0.2f, -2f);
director2.add(name2);
director2.add(new Chunk(","));
director2.add(new Chunk(" "));
director2.add(new Chunk(CONST_YUNYUN, STATIC_FONT_CHINESE));
director2.setLeading(24);
document.add(director2);
// 添加段落
document.newPage();
document.add(new Paragraph("Paragraph page"));
Paragraph info = new Paragraph();
info.add(new Chunk(CONST_NEZHA));
info.add(new Chunk(CONST_BIBIDONG));
info.add(Chunk.NEWLINE);
info.add(new Phrase(CONST_NEZHA));
info.add(new Phrase(CONST_NEZHA));
document.add(info);
// 通过循环添加段落信息
document.newPage();
List list = new List(List.ORDERED);
for (int i = 0; i < 5; i++) {
ListItem item = new ListItem(String.format("%s: %d " + CONST_NEZHA, CONST_YUNYUN + (i + 1), (i + 1) * 100),
new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD, BaseColor.WHITE));
List girllist = new List(List.ORDERED, List.ALPHABETICAL);
girllist.setLowercase(List.LOWERCASE);
for (int j = 0; j < 3; j++) {
ListItem girlitem = new ListItem("girls" + (j + 1));
List rolelist = new List(List.UNORDERED);
for (int k = 0; k < 2; k++) {
rolelist.add(String.format("%s, %s", CONST_NEZHA + (k + 1), CONST_BIBIDONG + (k + 1)));
}
girlitem.add(rolelist);
girllist.add(girlitem);
}
item.add(girllist);
list.add(item);
}
document.add(list);
document.close();
}
/**
* 插入锚Anchor, Image, 章节Chapter, 子列表Section
*/
public static void createPDFWithExtraContent() throws DocumentException, MalformedURLException, IOException {
FileOutputStream out = new FileOutputStream(FILE_DIR + "createPDFWithExtraContent.pdf");
document = new Document();
PdfWriter.getInstance(document, out);
document.open();
String content = "you can get anything from : ";
Paragraph paragraph = new Paragraph(content);
// 创建一个链接到外部网站的新锚点
// 并将此锚点添加到段落中。
Anchor anchor = new Anchor(CONST_BAIDU, STATIC_FONT_LINK);
anchor.setReference(CONST_BAIDU_URL);
paragraph.add(anchor);
document.add(paragraph);
// Image对象
document.newPage();
Image img = Image.getInstance(CONST_JPG_NGINX);
img.setAlignment(Image.LEFT | Image.TEXTWRAP);
img.setBorder(Image.BOX);
img.setBorderWidth(10);
img.setBorderColor(BaseColor.WHITE);
img.scaleToFit(800, 50);// 大小
img.setRotationDegrees(-50);// 旋转
document.add(img);
// 章节Chapter -- 目录
document.newPage();
Paragraph title = new Paragraph(CONST_TITLE_FIRST, STATIC_FONT_CHINESE);
// 标题和序号
Chapter chapter = new Chapter(title, 1);
// 子列表Section
title = new Paragraph(CONST_TITLE_SECOND, STATIC_FONT_CHINESE);
Section section = chapter.addSection(title);
section.setBookmarkTitle(CONST_NEZHA);
section.setIndentation(10);
section.setBookmarkOpen(false);
section.setNumberStyle(Section.NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT);
Section subsection1 = section.addSection(new Paragraph(CONST_CONTENT, STATIC_FONT_CHINESE));
subsection1.setIndentationLeft(10);
subsection1.setNumberDepth(1);
document.add(chapter);
document.close();
}
/**
* 画图
*/
public static void draw() throws Exception {
FileOutputStream out = new FileOutputStream(FILE_DIR + "draw.pdf");
document = new Document();
PdfWriter.getInstance(document, out);
document.open();
// 左右箭头
document.add(new VerticalPositionMark() {
@Override
public void draw(PdfContentByte canvas, float llx, float lly, float urx, float ury, float y) {
canvas.beginText();
BaseFont bf = null;
try {
bf = BaseFont.createFont(BaseFont.ZAPFDINGBATS, "", BaseFont.EMBEDDED);
} catch (Exception e) {
e.printStackTrace();
}
canvas.setFontAndSize(bf, 12);
// LEFT
canvas.showTextAligned(Element.ALIGN_CENTER, String.valueOf((char) 220), llx - 10, y, 0);
// RIGHT
canvas.showTextAligned(Element.ALIGN_CENTER, String.valueOf((char) 220), urx + 10, y + 8, 180);
canvas.endText();
}
});
// 直线
Paragraph p1 = new Paragraph(CONST_NEZHA, STATIC_FONT_CHINESE);
p1.add(new Chunk(new LineSeparator()));
p1.add(CONST_BIBIDONG);
document.add(p1);
// 点线
Paragraph p2 = new Paragraph(CONST_NEZHA, STATIC_FONT_CHINESE);
p2.add(new Chunk(new DottedLineSeparator()));
p2.add(CONST_BIBIDONG);
document.add(p2);
// 下滑线
LineSeparator UNDERLINE = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -2);
Paragraph p3 = new Paragraph(CONST_NEZHA_PROGRAM, STATIC_FONT_CHINESE);
p3.add(UNDERLINE);
document.add(p3);
document.close();
}
/**
* 设置段落
*/
public static void createPDFWithAlignment() throws Exception {
FileOutputStream out = new FileOutputStream(FILE_DIR + "createPDFWithAlignment.pdf");
document = new Document();
PdfWriter.getInstance(document, out);
document.open();
Paragraph p = new Paragraph("Never frown, even when you are sad, because you never know who is falling in love with your smile;" +
"You will see exactly what life is worth, when all the rest has gone;" +
"It is very simple to be happy, but it is very difficult to be simple.");
// 默认
p.setAlignment(Element.ALIGN_JUSTIFIED);
document.add(p);
// 慢慢的向右移动
document.newPage();
p.setAlignment(Element.ALIGN_JUSTIFIED);
p.setIndentationLeft(1 * 15f);
p.setIndentationRight((5 - 1) * 15f);
document.add(p);
// 居右
document.newPage();
p.setAlignment(Element.ALIGN_RIGHT);
p.setSpacingAfter(15f);
document.add(p);
// 居左
document.newPage();
p.setAlignment(Element.ALIGN_LEFT);
p.setSpacingBefore(15f);
document.add(p);
// 居中
document.newPage();
p.setAlignment(Element.ALIGN_CENTER);
p.setSpacingAfter(15f);
p.setSpacingBefore(15f);
document.add(p);
document.close();
}
/**
* 删除页
*/
public static void createPDFToDeletePage() throws Exception {
FileOutputStream out = new FileOutputStream(FILE_DIR + "createPDFToDeletePage.pdf");
document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, out);
document.open();
document.add(new Paragraph(CONST_PAGE_FIRST, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_SECOND, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_THIRD, STATIC_FONT_CHINESE));
document.close();
PdfReader reader = new PdfReader(FILE_DIR + "createPDFToDeletePage.pdf");
reader.selectPages("1,3");
PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(FILE_DIR + "createPDFToDeletePage2.pdf"));
stamp.close();
reader.close();
}
/**
* 插入 page
*/
public static void insertPage() throws Exception {
FileOutputStream out = new FileOutputStream(FILE_DIR + "insertPage.pdf");
document = new Document();
PdfWriter.getInstance(document, out);
document.open();
document.add(new Paragraph(CONST_PAGE_FIRST, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_SECOND, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_THIRD, STATIC_FONT_CHINESE));
document.close();
PdfReader reader = new PdfReader(FILE_DIR + "insertPage.pdf");
PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(FILE_DIR + "insertPage2.pdf"));
stamp.insertPage(2, reader.getPageSize(1));
ColumnText ct = new ColumnText(null);
ct.addElement(new Paragraph(24, new Chunk("INSERT PAGE")));
ct.setCanvas(stamp.getOverContent(2));
ct.setSimpleColumn(36, 36, 559, 770);
stamp.close();
reader.close();
}
/**
* 分割 page
*/
public static void splitPDF() throws Exception {
FileOutputStream out = new FileOutputStream(FILE_DIR + "splitPDF.pdf");
document = new Document();
PdfWriter.getInstance(document, out);
document.open();
document.add(new Paragraph(CONST_PAGE_FIRST, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_SECOND, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_THIRD, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_FOUR, STATIC_FONT_CHINESE));
document.close();
PdfReader reader = new PdfReader(FILE_DIR + "splitPDF.pdf");
Document dd = new Document();
PdfWriter writer = PdfWriter.getInstance(dd, new FileOutputStream(FILE_DIR + "splitPDF1.pdf"));
dd.open();
PdfContentByte cb = writer.getDirectContent();
dd.newPage();
cb.addTemplate(writer.getImportedPage(reader, 1), 0, 0);
dd.newPage();
cb.addTemplate(writer.getImportedPage(reader, 2), 0, 0);
dd.close();
writer.close();
Document dd2 = new Document();
PdfWriter writer2 = PdfWriter.getInstance(dd2, new FileOutputStream(FILE_DIR + "splitPDF2.pdf"));
dd2.open();
PdfContentByte cb2 = writer2.getDirectContent();
dd2.newPage();
cb2.addTemplate(writer2.getImportedPage(reader, 3), 0, 0);
dd2.newPage();
cb2.addTemplate(writer2.getImportedPage(reader, 4), 0, 0);
dd2.close();
writer2.close();
}
/**
* 合并 PDF 文件
*/
public static void mergePDF() throws Exception {
PdfReader reader1 = new PdfReader(FILE_DIR + "splitPDF1.pdf");
PdfReader reader2 = new PdfReader(FILE_DIR + "splitPDF2.pdf");
FileOutputStream out = new FileOutputStream(FILE_DIR + "mergePDF.pdf");
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, out);
document.open();
PdfContentByte cb = writer.getDirectContent();
java.util.List<PdfReader> readers = new ArrayList<PdfReader>();
readers.add(reader1);
readers.add(reader2);
int pageOfCurrentReaderPDF = 0;
Iterator<PdfReader> iteratorPDFReader = readers.iterator();
while (iteratorPDFReader.hasNext()) {
PdfReader pdfReader = iteratorPDFReader.next();
// 在目标中为每个源页面创建一个新页面
while (pageOfCurrentReaderPDF < pdfReader.getNumberOfPages()) {
document.newPage();
pageOfCurrentReaderPDF++;
PdfImportedPage page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF);
cb.addTemplate(page, 0, 0);
}
pageOfCurrentReaderPDF = 0;
}
out.flush();
document.close();
out.close();
}
/**
* 排序page
*/
public static void sortpage() throws Exception {
FileOutputStream out = new FileOutputStream(FILE_DIR + "sortpage.pdf");
document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, out);
writer.setLinearPageMode();
document.open();
document.add(new Paragraph(CONST_PAGE_FIRST, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_SECOND, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_THIRD, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_FOUR, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_FIVE, STATIC_FONT_CHINESE));
int[] order = {4, 3, 2, 1};
writer.reorderPages(order);
document.close();
}
/**
* 页眉页脚
*/
public static void setHeaderFooter() throws Exception {
document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FILE_DIR + "setHeaderFooter.pdf"));
writer.setPageEvent(new PdfPageEventHelper() {
@Override
public void onEndPage(PdfWriter writer, Document document) {
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
cb.beginText();
BaseFont bf = null;
try {
bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
} catch (Exception e) {
e.printStackTrace();
}
cb.setFontAndSize(bf, 10);
// Header
float x = document.top(-20);
// 左
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, "H-Left", document.left(), x, 0);
// 中
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, writer.getPageNumber() + " page",
(document.right() + document.left()) / 2, x, 0);
// 右
cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, "H-Right", document.right(), x, 0);
// Footer
float y = document.bottom(-20);
// 左
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, "F-Left", document.left(), y, 0);
// 中
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, writer.getPageNumber() + " page",
(document.right() + document.left()) / 2, y, 0);
// 右
cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, "F-Right", document.right(), y, 0);
cb.endText();
cb.restoreState();
}
});
document.open();
document.add(new Paragraph("1 page"));
document.newPage();
document.add(new Paragraph("2 page"));
document.newPage();
document.add(new Paragraph("3 page"));
document.newPage();
document.add(new Paragraph("4 page"));
document.close();
}
public static void addColumnText() throws Exception {
FileOutputStream out = new FileOutputStream(FILE_DIR + "addColumnText.pdf");
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, out);
document.open();
PdfContentByte canvas = writer.getDirectContent();
Phrase phrase1 = new Phrase(CONST_BIBIDONG + " is a beauty!left", STATIC_FONT_CHINESE);
Phrase phrase2 = new Phrase(CONST_BIBIDONG + " is a beauty!right", STATIC_FONT_CHINESE);
Phrase phrase3 = new Phrase(CONST_BIBIDONG + " is a beauty!center", STATIC_FONT_CHINESE);
ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase1, 200, 700, 0);
ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase2, 200, 600, 0);
ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase3, 200, 500, 0);
document.close();
}
/**
* 文档视图
*/
public static void setView() throws Exception {
FileOutputStream out = new FileOutputStream(FILE_DIR + "setView.pdf");
document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, out);
writer.setPdfVersion(PdfWriter.VERSION_1_5);
writer.setViewerPreferences(PdfWriter.PageModeFullScreen);// 全屏
writer.setPageEvent(new PdfPageEventHelper() {
@Override
public void onStartPage(PdfWriter writer, Document document) {
writer.setTransition(new PdfTransition(PdfTransition.DISSOLVE, 3));
writer.setDuration(5);// 间隔时间
}
});
document.open();
document.add(new Paragraph(CONST_PAGE_FIRST, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_SECOND, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_THIRD, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_FOUR, STATIC_FONT_CHINESE));
document.newPage();
document.add(new Paragraph(CONST_PAGE_FIVE, STATIC_FONT_CHINESE));
document.close();
}
/**
* 压缩PDF到Zip
*/
public static void pdfToZip() throws Exception {
ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(FILE_DIR + "pdfToZip.zip"));
for (int i = 1; i <= 3; i++) {
ZipEntry entry = new ZipEntry(CONST_NEZHA + i + ".pdf");
zip.putNextEntry(entry);
document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, zip);
writer.setCloseStream(false);
document.open();
document.add(new Paragraph(CONST_NEZHA + i, STATIC_FONT_CHINESE));
document.close();
zip.closeEntry();
}
zip.close();
}
/**
* 添加注释
*/
public static void addAnnotation() throws Exception {
FileOutputStream out = new FileOutputStream(FILE_DIR + "addAnnotation.pdf");
Document doc = new Document();
PdfWriter writer = PdfWriter.getInstance(doc, out);
writer.setLinearPageMode();
doc.open();
doc.add(new Paragraph(CONST_PAGE_FIRST, STATIC_FONT_CHINESE));
doc.add(new Annotation("title", "this is a annotation!"));
doc.newPage();
doc.add(new Paragraph(CONST_PAGE_SECOND, STATIC_FONT_CHINESE));
Chunk chunk = new Chunk(CONST_NEZHA);
chunk.setAnnotation(PdfAnnotation.createText(writer, null, "Title", "this is a another annotation!", false, "Comment"));
doc.add(chunk);
// 添加附件
//doc.newPage();
//doc.add(new Paragraph(const_PAGE_THIRD, static_FONT_CHINESE));
//Chunk chunk2 = new Chunk(const_BIBIDONG, static_FONT_CHINESE);
//PdfAnnotation annotation = PdfAnnotation.createFileAttachment(writer, null, "Title", null, const_JPG_JAVA, const_JPG_NGINX);
//annotation.put(PdfName.NAME, new PdfString("Paperclip"));
//chunk2.setAnnotation(annotation);
//doc.add(chunk2);
doc.close();
}
/**
* Gets pdf content *
*
* @param file file
* @return the pdf content
* @throws Exception exception
* @since 0.0.1
*/
public static String getPdfContent(MultipartFile file) throws Exception {
PdfReader pdfReader = new PdfReader(file.getBytes());
StringJoiner stringJoiner = new StringJoiner("");
int pageNum = pdfReader.getNumberOfPages();
for (int i = 1; i <= pageNum; i++) {
stringJoiner.add(PdfTextExtractor.getTextFromPage(pdfReader, i).replace("\n", ""));
}
return stringJoiner.toString();
}
}
+8
View File
@@ -0,0 +1,8 @@
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://wylgyx.top:3306/aos_file_identify?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowMultiQueries=true
username: root
password: Wyl.0629
@@ -0,0 +1,13 @@
package com.aos.fileidentify;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class AosFileIdentifyApplicationTests {
@Test
void contextLoads() {
}
}