Преглед на файлове

1.打印方式改为excel文件打印。
2.内置浏览器改为selenium浏览器。

lhy преди 1 година
родител
ревизия
e5a4343326
променени са 25 файла, в които са добавени 1341 реда и са изтрити 893 реда
  1. 0 33
      PrintServer/.gitignore
  2. 163 0
      PrintServer/PrintServer.iml
  3. 1 5
      PrintServer/README.md
  4. 45 3
      PrintServer/innoSetup5/template.iss
  5. BIN
      PrintServer/lib/aspose-cells-8.5.2.jar
  6. BIN
      PrintServer/lib/jxbrowser-7.21.jar
  7. BIN
      PrintServer/lib/jxbrowser-javafx-7.21.jar
  8. 0 23
      PrintServer/logs/printServer.log
  9. BIN
      PrintServer/logs/printServer.log.2023-07-13.0.gz
  10. BIN
      PrintServer/logs/printServer.log.2023-07-14.0.gz
  11. 0 308
      PrintServer/mvnw
  12. 0 205
      PrintServer/mvnw.cmd
  13. 30 23
      PrintServer/pom.xml
  14. 6 4
      PrintServer/src/main/java/com/jd/printserver/PrintServerApplication.java
  15. 7 3
      PrintServer/src/main/java/com/jd/printserver/common/constants/Constants.java
  16. 119 42
      PrintServer/src/main/java/com/jd/printserver/controller/PrintServerController.java
  17. 62 4
      PrintServer/src/main/java/com/jd/printserver/javafx/entity/PrintParam.java
  18. 36 3
      PrintServer/src/main/java/com/jd/printserver/utils/FileUtils.java
  19. 383 0
      PrintServer/src/main/java/com/jd/printserver/utils/JacobUtils.java
  20. 0 151
      PrintServer/src/main/java/com/jd/printserver/utils/JxbrowserUtils.java
  21. 106 83
      PrintServer/src/main/java/com/jd/printserver/utils/PrintUtils.java
  22. 265 0
      PrintServer/src/main/java/com/jd/printserver/utils/SeleniumUtils.java
  23. 13 3
      PrintServer/src/main/resources/application.yml
  24. 105 0
      PrintServer/src/main/resources/logback-spring.xml
  25. BIN
      PrintServer/src/main/resources/selenium/Chrome.zip

+ 0 - 33
PrintServer/.gitignore

@@ -1,33 +0,0 @@
-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/

+ 163 - 0
PrintServer/PrintServer.iml

@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="web" name="Web">
+      <configuration>
+        <webroots />
+        <sourceRoots>
+          <root url="file://$MODULE_DIR$/lib" />
+          <root url="file://$MODULE_DIR$/src/main/java" />
+          <root url="file://$MODULE_DIR$/src/main/resources" />
+        </sourceRoots>
+      </configuration>
+    </facet>
+    <facet type="Spring" name="Spring">
+      <configuration />
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
+    <output url="file://$MODULE_DIR$/target/classes" />
+    <output-test url="file://$MODULE_DIR$/target/test-classes" />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/lib" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/target" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.7.1" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.7.1" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.7.1" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.7.1" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.7.1" level="project" />
+    <orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.11" level="project" />
+    <orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.11" level="project" />
+    <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.17.2" level="project" />
+    <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.17.2" level="project" />
+    <orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.36" level="project" />
+    <orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:1.3.5" level="project" />
+    <orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.30" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.7.1" level="project" />
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.13.3" level="project" />
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.13.3" level="project" />
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.13.3" level="project" />
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.13.3" level="project" />
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.3" level="project" />
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.13.3" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.7.1" level="project" />
+    <orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.64" level="project" />
+    <orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:9.0.64" level="project" />
+    <orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.64" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-web:5.3.21" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-beans:5.3.21" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.3.21" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-aop:5.3.21" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-context:5.3.21" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-expression:5.3.21" level="project" />
+    <orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.24" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:2.7.1" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test:2.7.1" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:2.7.1" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: com.jayway.jsonpath:json-path:2.7.0" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: net.minidev:json-smart:2.4.8" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: net.minidev:accessors-smart:2.4.8" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.ow2.asm:asm:9.1" level="project" />
+    <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.36" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: jakarta.xml.bind:jakarta.xml.bind-api:2.3.3" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: jakarta.activation:jakarta.activation-api:1.2.2" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.assertj:assertj-core:3.22.0" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest:2.2" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.8.2" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.8.2" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.8.2" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.2" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.8.2" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.8.2" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.8.2" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:4.5.1" level="project" />
+    <orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.12.11" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.12.11" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:3.2" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-junit-jupiter:4.5.1" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.skyscreamer:jsonassert:1.5.0" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-core:5.3.21" level="project" />
+    <orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.3.21" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:5.3.21" level="project" />
+    <orderEntry type="library" scope="TEST" name="Maven: org.xmlunit:xmlunit-core:2.9.0" level="project" />
+    <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.12.0" level="project" />
+    <orderEntry type="library" name="Maven: cn.hutool:hutool-all:5.8.16" level="project" />
+    <orderEntry type="library" name="Maven: org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0" level="project" />
+    <orderEntry type="library" name="Maven: de.roskenet:springboot-javafx-support:2.1.6" level="project" />
+    <orderEntry type="library" name="Maven: org.apache.pdfbox:pdfbox:2.0.29" level="project" />
+    <orderEntry type="library" name="Maven: org.apache.pdfbox:fontbox:2.0.29" level="project" />
+    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
+    <orderEntry type="library" name="Maven: com.jacob:jacob:1.20" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-java:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-api:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-chrome-driver:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: com.google.auto.service:auto-service-annotations:1.0.1" level="project" />
+    <orderEntry type="library" name="Maven: com.google.auto.service:auto-service:1.0.1" level="project" />
+    <orderEntry type="library" name="Maven: com.google.auto:auto-common:1.2" level="project" />
+    <orderEntry type="library" name="Maven: com.google.guava:guava:31.1-jre" level="project" />
+    <orderEntry type="library" name="Maven: com.google.guava:failureaccess:1.0.1" level="project" />
+    <orderEntry type="library" name="Maven: com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava" level="project" />
+    <orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.2" level="project" />
+    <orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.12.0" level="project" />
+    <orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.11.0" level="project" />
+    <orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-chromium-driver:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-json:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-devtools-v100:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-devtools-v101:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-devtools-v85:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-devtools-v99:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-edge-driver:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-firefox-driver:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-ie-driver:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-opera-driver:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-remote-driver:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: com.beust:jcommander:1.82" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-codec-http:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-common:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-transport-classes-epoll:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-transport-classes-kqueue:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-transport-native-epoll:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-transport-native-kqueue:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-transport-native-unix-common:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.opentelemetry:opentelemetry-api:1.13.0" level="project" />
+    <orderEntry type="library" name="Maven: io.opentelemetry:opentelemetry-context:1.13.0" level="project" />
+    <orderEntry type="library" name="Maven: io.opentelemetry:opentelemetry-exporter-logging:1.13.0" level="project" />
+    <orderEntry type="library" name="Maven: io.opentelemetry:opentelemetry-sdk-metrics:1.13.0-alpha" level="project" />
+    <orderEntry type="library" name="Maven: io.opentelemetry:opentelemetry-sdk-logs:1.13.0-alpha" level="project" />
+    <orderEntry type="library" name="Maven: io.opentelemetry:opentelemetry-sdk-common:1.13.0" level="project" />
+    <orderEntry type="library" name="Maven: io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:1.13.0" level="project" />
+    <orderEntry type="library" name="Maven: io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:1.13.0-alpha" level="project" />
+    <orderEntry type="library" name="Maven: io.opentelemetry:opentelemetry-sdk-trace:1.13.0" level="project" />
+    <orderEntry type="library" name="Maven: io.opentelemetry:opentelemetry-sdk:1.13.0" level="project" />
+    <orderEntry type="library" name="Maven: io.opentelemetry:opentelemetry-semconv:1.13.0-alpha" level="project" />
+    <orderEntry type="library" name="Maven: io.ous:jtoml:2.0.0" level="project" />
+    <orderEntry type="library" name="Maven: org.apache.commons:commons-exec:1.3" level="project" />
+    <orderEntry type="library" name="Maven: org.asynchttpclient:async-http-client:2.12.3" level="project" />
+    <orderEntry type="library" name="Maven: org.asynchttpclient:async-http-client-netty-utils:2.12.3" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-codec-socks:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-handler-proxy:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-transport-native-epoll:linux-x86_64:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: io.netty:netty-transport-native-kqueue:osx-x86_64:4.1.78.Final" level="project" />
+    <orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.4" level="project" />
+    <orderEntry type="library" name="Maven: com.typesafe.netty:netty-reactive-streams:2.0.4" level="project" />
+    <orderEntry type="library" name="Maven: com.sun.activation:jakarta.activation:1.2.2" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-http:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: dev.failsafe:failsafe:3.2.3" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-safari-driver:4.1.4" level="project" />
+    <orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:4.1.4" level="project" />
+  </component>
+</module>

+ 1 - 5
PrintServer/README.md

@@ -2,11 +2,7 @@
 ```bash
 mvn install:install-file -Dfile=G:\WorkSoft\STS\workspace\PrintServer\lib\jacob.jar -DgroupId=com.jacob -DartifactId=jacob  -Dversion=1.20  -Dpackaging=jar
 
-mvn install:install-file -Dfile=G:\WorkSoft\STS\workspace\PrintServer\lib\jxbrowser-7.21.jar -DgroupId=com.teamdev.jxbrowser -DartifactId=jxbrowser  -Dversion=7.21  -Dpackaging=jar
-
-mvn install:install-file -Dfile=G:\WorkSoft\STS\workspace\PrintServer\lib\jxbrowser-win64-7.21.jar -DgroupId=com.teamdev.jxbrowser -DartifactId=jxbrowser-win64  -Dversion=7.21  -Dpackaging=jar
-
-mvn install:install-file -Dfile=G:\WorkSoft\STS\workspace\PrintServer\lib\jxbrowser-javafx-7.21.jar -DgroupId=com.teamdev.jxbrowser -DartifactId=jxbrowser-javafx  -Dversion=7.21  -Dpackaging=jar
+mvn install:install-file -Dfile=G:\WorkSoft\STS\workspace\read_opc\PrintServer\lib\aspose-cells-8.5.2.jar -DgroupId=com.aspose -DartifactId=aspose-cells  -Dversion=8.5.2  -Dpackaging=jar
 
 ```
 ## 启动方式

+ 45 - 3
PrintServer/innoSetup5/template.iss

@@ -69,8 +69,8 @@ Type: filesandordirs; Name: "{app}"
 ; update 5
 [Registry]
 Root: HKCU; Subkey:"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "RUN_FILENAME";ValueData: "{app}\RUN_FILENAME.exe /start"; Flags: deletevalue uninsdeletevalue
-Root: HKLM; Subkey:"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "RUN_FILENAME";ValueData: "{app}\RUN_FILENAME.exe /start"; Flags: deletevalue uninsdeletevalue
-Root: HKLM; Subkey:"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "RUN_FILENAME";ValueData: "{app}\RUN_FILENAME.exe /start"; Flags: deletevalue uninsdeletevalue; Check:IsWin64
+;Root: HKLM; Subkey:"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "RUN_FILENAME";ValueData: "{app}\RUN_FILENAME.exe /start"; Flags: deletevalue uninsdeletevalue
+;Root: HKLM; Subkey:"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "RUN_FILENAME";ValueData: "{app}\RUN_FILENAME.exe /start"; Flags: deletevalue uninsdeletevalue; Check:IsWin64
 ;
 
 [Code]
@@ -91,4 +91,46 @@ begin
 //   if upgrade => check if same app is running and wait for it to exit
 //   Add pack200/unpack200 support? 
   Result := True;
-end;  
+end;
+
+procedure InitializeWizard();
+
+begin
+
+WizardForm.BorderStyle:=bsNone;
+
+end;
+
+function ShouldSkipPage(PageID: Integer): Boolean;
+
+begin
+
+Result := True
+
+end;
+
+procedure CurPageChanged(CurPageID: Integer);
+
+var
+
+indexpageid3:Integer;
+
+begin
+
+WizardForm.ClientWidth := ScaleX(0);
+
+WizardForm.ClientHeight := ScaleY(0);
+
+if CurPageID = wpWelcome then
+
+WizardForm.NextButton.OnClick(WizardForm);
+
+if CurPageID >= wpInstalling then
+
+WizardForm.Visible := False
+
+else
+
+WizardForm.Visible := True;
+
+end;

BIN
PrintServer/lib/aspose-cells-8.5.2.jar


BIN
PrintServer/lib/jxbrowser-7.21.jar


BIN
PrintServer/lib/jxbrowser-javafx-7.21.jar


Файловите разлики са ограничени, защото са твърде много
+ 0 - 23
PrintServer/logs/printServer.log


BIN
PrintServer/logs/printServer.log.2023-07-13.0.gz


BIN
PrintServer/logs/printServer.log.2023-07-14.0.gz


+ 0 - 308
PrintServer/mvnw

@@ -1,308 +0,0 @@
-#!/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.
-# ----------------------------------------------------------------------------
-
-# ----------------------------------------------------------------------------
-# Apache Maven Wrapper startup batch script, version 3.2.0
-#
-# Required ENV vars:
-# ------------------
-#   JAVA_HOME - location of a JDK home dir
-#
-# Optional ENV vars
-# -----------------
-#   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
-        JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME
-      else
-        JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
-      fi
-    fi
-    ;;
-esac
-
-if [ -z "$JAVA_HOME" ] ; then
-  if [ -r /etc/gentoo-release ] ; then
-    JAVA_HOME=$(java-config --jre-home)
-  fi
-fi
-
-# For Cygwin, ensure paths are in UNIX format before anything is touched
-if $cygwin ; then
-  [ -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 "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] &&
-    JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); 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 2>/dev/null; \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
-
-# 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/.." || exit 1; pwd)
-    fi
-    # end of workaround
-  done
-  printf '%s' "$(cd "$basedir" || exit 1; pwd)"
-}
-
-# concatenates all lines of a file
-concat_lines() {
-  if [ -f "$1" ]; then
-    # Remove \r in case we run on Windows within Git Bash
-    # and check out the repository with auto CRLF management
-    # enabled. Otherwise, we may read lines that are delimited with
-    # \r\n and produce $'-Xarg\r' rather than -Xarg due to word
-    # splitting rules.
-    tr -s '\r\n' ' ' < "$1"
-  fi
-}
-
-log() {
-  if [ "$MVNW_VERBOSE" = true ]; then
-    printf '%s\n' "$1"
-  fi
-}
-
-BASE_DIR=$(find_maven_basedir "$(dirname "$0")")
-if [ -z "$BASE_DIR" ]; then
-  exit 1;
-fi
-
-MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR
-log "$MAVEN_PROJECTBASEDIR"
-
-##########################################################################################
-# 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.
-##########################################################################################
-wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar"
-if [ -r "$wrapperJarPath" ]; then
-    log "Found $wrapperJarPath"
-else
-    log "Couldn't find $wrapperJarPath, downloading it ..."
-
-    if [ -n "$MVNW_REPOURL" ]; then
-      wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
-    else
-      wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
-    fi
-    while IFS="=" read -r key value; do
-      # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' )
-      safeValue=$(echo "$value" | tr -d '\r')
-      case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;;
-      esac
-    done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
-    log "Downloading from: $wrapperUrl"
-
-    if $cygwin; then
-      wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath")
-    fi
-
-    if command -v wget > /dev/null; then
-        log "Found wget ... using wget"
-        [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet"
-        if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
-            wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
-        else
-            wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
-        fi
-    elif command -v curl > /dev/null; then
-        log "Found curl ... using curl"
-        [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent"
-        if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
-            curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
-        else
-            curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
-        fi
-    else
-        log "Falling back to using Java to download"
-        javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java"
-        javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class"
-        # For Cygwin, switch paths to Windows format before running javac
-        if $cygwin; then
-          javaSource=$(cygpath --path --windows "$javaSource")
-          javaClass=$(cygpath --path --windows "$javaClass")
-        fi
-        if [ -e "$javaSource" ]; then
-            if [ ! -e "$javaClass" ]; then
-                log " - Compiling MavenWrapperDownloader.java ..."
-                ("$JAVA_HOME/bin/javac" "$javaSource")
-            fi
-            if [ -e "$javaClass" ]; then
-                log " - Running MavenWrapperDownloader.java ..."
-                ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath"
-            fi
-        fi
-    fi
-fi
-##########################################################################################
-# End of extension
-##########################################################################################
-
-# If specified, validate the SHA-256 sum of the Maven wrapper jar file
-wrapperSha256Sum=""
-while IFS="=" read -r key value; do
-  case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;;
-  esac
-done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
-if [ -n "$wrapperSha256Sum" ]; then
-  wrapperSha256Result=false
-  if command -v sha256sum > /dev/null; then
-    if echo "$wrapperSha256Sum  $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then
-      wrapperSha256Result=true
-    fi
-  elif command -v shasum > /dev/null; then
-    if echo "$wrapperSha256Sum  $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then
-      wrapperSha256Result=true
-    fi
-  else
-    echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available."
-    echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties."
-    exit 1
-  fi
-  if [ $wrapperSha256Result = false ]; then
-    echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2
-    echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2
-    echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2
-    exit 1
-  fi
-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 "$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
-
-# shellcheck disable=SC2086 # safe args
-exec "$JAVACMD" \
-  $MAVEN_OPTS \
-  $MAVEN_DEBUG_OPTS \
-  -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
-  "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
-  ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

+ 0 - 205
PrintServer/mvnw.cmd

@@ -1,205 +0,0 @@
-@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 Apache Maven Wrapper startup batch script, version 3.2.0
-@REM
-@REM Required ENV vars:
-@REM JAVA_HOME - location of a JDK home dir
-@REM
-@REM Optional ENV vars
-@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 WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
-
-FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
-    IF "%%A"=="wrapperUrl" SET WRAPPER_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 WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
-    )
-    if "%MVNW_VERBOSE%" == "true" (
-        echo Couldn't find %WRAPPER_JAR%, downloading it ...
-        echo Downloading from: %WRAPPER_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('%WRAPPER_URL%', '%WRAPPER_JAR%')"^
-		"}"
-    if "%MVNW_VERBOSE%" == "true" (
-        echo Finished downloading %WRAPPER_JAR%
-    )
-)
-@REM End of extension
-
-@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file
-SET WRAPPER_SHA_256_SUM=""
-FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
-    IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B
-)
-IF NOT %WRAPPER_SHA_256_SUM%=="" (
-    powershell -Command "&{"^
-       "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^
-       "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^
-       "  Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^
-       "  Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^
-       "  Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^
-       "  exit 1;"^
-       "}"^
-       "}"
-    if ERRORLEVEL 1 goto error
-)
-
-@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%

+ 30 - 23
PrintServer/pom.xml

@@ -12,7 +12,7 @@
     <artifactId>printServer</artifactId>
     <version>1.0.0</version>
     <name>PrintServerApp</name>
-    <description>打印服务App</description>
+    <description>EIAutoPrintApp</description>
     <properties>
         <java.version>8</java.version>
     </properties>
@@ -59,29 +59,26 @@
             <artifactId>springboot-javafx-support</artifactId>
             <version>2.1.6</version>
         </dependency>
-        <dependency>
-            <groupId>com.teamdev.jxbrowser</groupId>
-            <artifactId>jxbrowser</artifactId>
-            <version>7.21</version>
-        </dependency>
-        <dependency>
-            <groupId>com.teamdev.jxbrowser</groupId>
-            <artifactId>jxbrowser-win64</artifactId>
-            <version>7.21</version>
-        </dependency>
-        <dependency>
-            <groupId>com.teamdev.jxbrowser</groupId>
-            <artifactId>jxbrowser-javafx</artifactId>
-            <version>7.21</version>
-        </dependency>
         <!-- PDF文件格式打印实现 -->
         <dependency>
             <groupId>org.apache.pdfbox</groupId>
             <artifactId>pdfbox</artifactId>
             <version>2.0.29</version>
         </dependency>
-    </dependencies>
+        <!--jacob依赖-->
+        <dependency>
+            <groupId>com.jacob</groupId>
+            <artifactId>jacob</artifactId>
+            <version>1.20</version>
+        </dependency>
+        <!--selenium内置浏览器-->
+        <dependency>
+            <groupId>org.seleniumhq.selenium</groupId>
+            <artifactId>selenium-java</artifactId>
+            <version>4.1.4</version>
+        </dependency>
 
+    </dependencies>
     <build>
         <plugins>
             <!--<plugin>
@@ -103,7 +100,7 @@
                 <version>8.8.3</version>
                 <configuration>
                     <!-- 作者/公司名称 -->
-                    <vendor>重庆巨东科技集团有限公司</vendor>
+                    <vendor>cqjudong</vendor>
                     <!-- main方法的类 -->
                     <mainClass>com.jd.printserver.PrintServerApplication</mainClass>
                     <!-- 运行文件名/应用名称 ${project.build.finalName} = ${project.artifactId}-${project.version} -->
@@ -130,18 +127,18 @@
                         <icon>${project.basedir}/src/main/resources/icon/report_print.ico</icon>
                         <!--下面这2个参数搭配,可实现一个特别重要的功能,就是,提示用户手动选择程序安装目录,默认目录是在:C:\Program Files (x86)\appName-->
                         <!--设置为true将在Program Files中安装应用程序。设置为false将应用程序安装到用户的主目录中。默认值为false。-->
-                        <systemWide>true</systemWide>
+                        <systemWide>false</systemWide>
                         <!-- 让用户选择安装目标文件夹 -->
-                        <installdirChooser>true</installdirChooser>
+                        <installdirChooser>false</installdirChooser>
                     </bundleArguments>
                     <!-- 桌面图标 -->
-                    <needShortcut>true</needShortcut>
+                    <needShortcut>false</needShortcut>
                     <!-- 菜单设置 -->
                     <needMenu>true</needMenu>
 
                     <!--添加原生的dll等,因为在打包后,会自带2个java.library.path目录,一个是app目录下,一个是exe所在的目录,只要把dll放到这2个目录的其中一个下,就可以加载dll,可以使用additionalAppResources配置dll目录-->
                     <!--成功实现将项目目录下的dll目录下的所有文件复制到了app目录下,app目录也是java.library.path目录,可以直接加载dll-->
-                    <!--<additionalAppResources>${project.basedir}/dll</additionalAppResources>-->
+                    <additionalAppResources>${project.basedir}/dll</additionalAppResources>
 
                     <!--使用这个additionalBundlerResources,不能实现添加dll到app目录-->
                     <!--<additionalBundlerResources>-->
@@ -190,16 +187,26 @@
                 <!--把src/main/resources目录下的properties、xm文件打包打进程序中-->
                 <directory>src/main/resources</directory>
                 <includes>
-                    <include>**/*.yml</include>
                     <include>**/*.properties</include>
                     <include>**/*.xml</include>
                     <include>**/*.fxml</include>
                     <include>**/*.setting</include>
                     <include>**/*.png</include>
+                    <include>**/*.*</include>
                 </includes>
                 <filtering>false</filtering>
             </resource>
 
+            <resource>
+                <!--把src/main/resources目录下的properties、xm文件打包打进程序中-->
+                <directory>src/main/resources</directory>
+                <includes>
+                    <include>**/*.yml</include>
+                </includes>
+                <!-- 启用过滤器,过滤器会解析需要过滤的的资源文件,将其中的变量替换成真实的值 -->
+                <filtering>true</filtering>
+            </resource>
+
             <!--<resource>-->
                 <!--把lib/目录下第三方jar包打进程序中,如systemPath目录下的jar-->
                 <!--<directory>lib/</directory>

+ 6 - 4
PrintServer/src/main/java/com/jd/printserver/PrintServerApplication.java

@@ -31,6 +31,8 @@ import java.util.Properties;
 @SpringBootApplication
 public class PrintServerApplication extends AbstractJavaFxApplicationSupport {
 
+    public static Stage primaryStage = null;
+
     public static final Logger log = LoggerFactory.getLogger(PrintServerApplication.class);
 
     private static Properties properties = null;
@@ -57,8 +59,8 @@ public class PrintServerApplication extends AbstractJavaFxApplicationSupport {
     }
 
     @Override
-    public void start(Stage primaryStage) throws Exception{
-
+    public void start(Stage primaryStage1) throws Exception{
+        primaryStage = primaryStage1;
         log.info("初始化界面和系统托盘");
         File settingFile = FileUtils.Jar2OutFile(Constants.FXML_SETTING_PATH);
         if(settingFile == null){
@@ -159,8 +161,8 @@ public class PrintServerApplication extends AbstractJavaFxApplicationSupport {
             }
         });
 
-        SystemTray tray = SystemTray.getSystemTray();
-        tray.add(trayIcon);
+        //SystemTray tray = SystemTray.getSystemTray();
+        //tray.add(trayIcon);
 
         //primaryStage.show();
         //不能置顶,不然保存提示弹窗显示不出来

+ 7 - 3
PrintServer/src/main/java/com/jd/printserver/common/constants/Constants.java

@@ -104,6 +104,7 @@ public class Constants
     public static final String FILE_XLSX_SUFFIX = ".xlsx";
 
     //打印纸张尺寸字符串
+    public static final String PRINT_A3 = "A3:297mm X 420mm";
     public static final String PRINT_A4 = "A4:210mm X 297mm";
     public static final String PRINT_A5 = "A5:148mm X 210mm";
     public static final String PRINT_B5 = "B5:182mm X 257mm";
@@ -118,7 +119,7 @@ public class Constants
     public static final String PRINT_SELF_DEFINE = "self define ...";
 
     //打印纸张尺寸字符串集合
-    public static final String[] PRINT_PAPER_STR_ARRAY = {PRINT_A4,PRINT_A5,PRINT_B5,PRINT_DEVELOP_C5,PRINT_DEVELOP_DL,
+    public static final String[] PRINT_PAPER_STR_ARRAY = {PRINT_A3,PRINT_A4,PRINT_A5,PRINT_B5,PRINT_DEVELOP_C5,PRINT_DEVELOP_DL,
             PRINT_DEVELOP_B5,PRINT_DEVELOP_MONARCH,PRINT_DEVELOP_9,PRINT_DEVELOP_10,PRINT_LETTER,PRINT_LEGAL};
 
     // 毫米转像素(mm*0.0394*72=px)
@@ -130,6 +131,9 @@ public class Constants
     public static final double PRINT_PX = 72;
 
     //打印纸张尺寸
+    public static final int PRINT_A3_WIDTH = 297;
+    public static final int PRINT_A3_HEIGHT = 420;
+
     public static final int PRINT_A4_WIDTH = 210;
     public static final int PRINT_A4_HEIGHT = 297;
 
@@ -164,10 +168,10 @@ public class Constants
     public static final int PRINT_LEGAL_HEIGHT = (int)(14  / INCHESPER_MILLIMETER);
 
     //打印纸张尺寸宽度集合
-    public static final int[] PRINT_PAPER_MM_WIDTH_ARRAY = {PRINT_A4_WIDTH,PRINT_A5_WIDTH,PRINT_B5_WIDTH,PRINT_DEVELOP_C5_WIDTH,PRINT_DEVELOP_DL_WIDTH,
+    public static final int[] PRINT_PAPER_MM_WIDTH_ARRAY = {PRINT_A3_WIDTH, PRINT_A4_WIDTH,PRINT_A5_WIDTH,PRINT_B5_WIDTH,PRINT_DEVELOP_C5_WIDTH,PRINT_DEVELOP_DL_WIDTH,
             PRINT_DEVELOP_B5_WIDTH,PRINT_DEVELOP_MONARCH_WIDTH,PRINT_DEVELOP_9_WIDTH,PRINT_DEVELOP_10_WIDTH,PRINT_LETTER_WIDTH,PRINT_LEGAL_WIDTH};
     //打印纸张尺寸高度集合
-    public static final int[] PRINT_PAPER_MM_HEIGHT_ARRAY = {PRINT_A4_HEIGHT,PRINT_A5_HEIGHT,PRINT_B5_HEIGHT,PRINT_DEVELOP_C5_HEIGHT,PRINT_DEVELOP_DL_HEIGHT,
+    public static final int[] PRINT_PAPER_MM_HEIGHT_ARRAY = {PRINT_A3_HEIGHT,PRINT_A4_HEIGHT,PRINT_A5_HEIGHT,PRINT_B5_HEIGHT,PRINT_DEVELOP_C5_HEIGHT,PRINT_DEVELOP_DL_HEIGHT,
             PRINT_DEVELOP_B5_HEIGHT,PRINT_DEVELOP_MONARCH_HEIGHT,PRINT_DEVELOP_9_HEIGHT,PRINT_DEVELOP_10_HEIGHT,PRINT_LETTER_HEIGHT,PRINT_LEGAL_HEIGHT};
 
 

+ 119 - 42
PrintServer/src/main/java/com/jd/printserver/controller/PrintServerController.java

@@ -1,19 +1,32 @@
 package com.jd.printserver.controller;
 
 import cn.hutool.core.codec.Base64Decoder;
+import cn.hutool.core.convert.Convert;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.lang.Snowflake;
+import cn.hutool.core.lang.UUID;
+import cn.hutool.core.util.IdUtil;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.jd.printserver.PrintServerApplication;
 import com.jd.printserver.common.constants.Constants;
 import com.jd.printserver.common.controller.BaseController;
 import com.jd.printserver.common.domain.AjaxResult;
 import com.jd.printserver.javafx.entity.PrintParam;
 import com.jd.printserver.utils.*;
+import javafx.application.Platform;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.*;
 
 
 @RestController
@@ -23,73 +36,137 @@ public class PrintServerController extends BaseController {
 
     public static final Logger log = LoggerFactory.getLogger(PrintServerController.class);
 
+    @Value("${data.app.version}")
+    private String appVersion;
+
+    @RequestMapping(value = "/appVersion")
+    @CrossOrigin
+    public AjaxResult appVersion(){
+        return success((Object) appVersion);
+    }
+
+    @RequestMapping(value = "/testInstalled")
+    @CrossOrigin
+    public AjaxResult testInstalled(){
+        return success();
+    }
+
+    /*@RequestMapping(value = "/settingShow")
+    public AjaxResult settingShow(){
+        Platform.runLater(new Runnable(){
+            @Override
+            public void run() {
+                PrintServerApplication.primaryStage.show();
+                // 显示到前台
+                PrintServerApplication.primaryStage.toFront();
+            }
+        });
+        return success();
+    }*/
+    @PostMapping(value = "/uploadExcel")
+    @CrossOrigin
+    public AjaxResult uploadExcel(@RequestParam("file") MultipartFile file,String randomId) throws IOException {
+        // 判断文件是否存在
+        if (file == null || file.isEmpty()) {
+            log.info("接口参数缺失:{}", file);
+            return error("参数缺失");
+        }
+        String fileName = file.getOriginalFilename();
+        String now = DateUtil.format(new Date(),"yyyyMMddHHmmssSSS");
+        File excelFile = new File( now+ "_" + randomId + ".xlsx");
+        FileUtil.writeFromStream(file.getInputStream(),excelFile);
+
+
+        Map<String, String> map = new HashMap<>();
+        map.put("excelFilePath",excelFile.getAbsolutePath());
+        map.put("id",randomId);
+        Map<String, String> resultData = SeleniumUtils.getResultData("id",randomId);
+        log.info("uploadExcel.resultData:{}", resultData);
+        if(resultData == null){
+            SeleniumUtils.addResultData(map);
+        }else{
+            SeleniumUtils.updateResultData(map,"id");
+        }
+
+        resultData = SeleniumUtils.getResultData("id",randomId);
+        log.info("uploadExcel.resultData:{}", resultData);
+        log.info("上传excel文件的地址:{}", excelFile.getAbsolutePath());
+        return success();
+    }
+
+
     @RequestMapping(value = "/printUrl")
-    public AjaxResult printUrl(String url){
+    @CrossOrigin
+    public AjaxResult printUrl(String excelUrl,String printConfig){
+//        excelUrl = "http://192.168.0.15:8080/static/webview/report-wv.html?id=372";
+//        printConfig = new PrintParam();
         log.info("--------------------------本地打印开始");
-        log.info("数据访问地址:{}", url);
-        if (StringUtils.isEmpty(url)) {
-            log.info("接口参数缺失:{}", url);
+        log.info("数据访问地址:{}", excelUrl);
+        if (StringUtils.isEmpty(excelUrl)) {
+            log.info("接口参数缺失:{}", excelUrl);
             return error("参数缺失");
         }
-        String data = JxbrowserUtils.getResultData(url);
-        if(data == null){
-            log.info("获取报表图片文件失败");
-            return error("获取报表失败");
+        if (StringUtils.isEmpty(printConfig)) {
+            log.info("接口参数缺失:{}", printConfig);
+            return error("参数缺失");
         }
-        String[] imgData = data.split(",");
-        if(!ArrayUtils.contains(Constants.BASE64_IMAGE_PREFIX, imgData[0])){
-            log.info("不是Base64格式图片文件");
-            return error("获取报表格式错误");
+        PrintParam printParam = JSONUtil.toBean(printConfig,PrintParam.class);
+        //PrintParam printParam = FileUtils.readFile2PrintParam();
+        log.info("初始化打印参数:{}", printParam);
+        if(printParam == null){
+            return error("初始化打印参数失败");
         }
+        Map<String, String> urlMap = SeleniumUtils.getURLParameters(excelUrl);
+        //添加打印区域参数
+        urlMap.put("printArea",printParam.getPrintArea().toString());
+        urlMap.put("printAreaValue",printParam.getPrintAreaValue());
 
-        byte[] imgBytes = Base64Decoder.decode(imgData[1]);
-        for (int i = 0; i < imgBytes.length; ++i) {
-            if (imgBytes[i] < 0) {
-                imgBytes[i] += 256;
-            }
-        }
+        Snowflake secondSnow = IdUtil.getSnowflake(1,1);
+        String id = secondSnow.nextIdStr();
 
-        String path = null;
-        if(imgData[0].equals(Constants.BASE64_JPG_PREFIX)){
-            path = FileUtils.newFilePath(Constants.PRINT_URL_DIRECTORY, Constants.IMAGE_JPG_SUFFIX);
-        }else if(imgData[0].equals(Constants.BASE64_PNG_PREFIX)){
-            path = FileUtils.newFilePath(Constants.PRINT_URL_DIRECTORY, Constants.IMAGE_PNG_SUFFIX);
-        }else if(imgData[0].equals(Constants.BASE64_GIF_PREFIX)){
-            path = FileUtils.newFilePath(Constants.PRINT_URL_DIRECTORY, Constants.IMAGE_GIF_SUFFIX);
-        }
-        if(path == null){
-            log.info("不是可处理(jpg/png/gif)的图片文件");
-            return error("访问文件失败");
+        urlMap.put("randomId",id);
+        String baseUrl = excelUrl.substring(0,excelUrl.indexOf("?"));
+        String url = SeleniumUtils.buildUrl(baseUrl, urlMap);
+        log.info("printUrl.url:{}", url);
+
+        Map<String, String> data = SeleniumUtils.getResultDataByUrl(url,"id",id);
+        if(data == null){
+            log.info("获取报表文件失败");
+            return error("获取报表失败");
         }
-        FileUtil.writeBytes(imgBytes, path);
-        log.info("初始化打印文件:{}", path);
-        File inFile = new File(path);
-        if(inFile == null || !inFile.exists()){
+        String excelFilePath = Convert.toStr(data.get("excelFilePath"), "");
+        SeleniumUtils.removeResultData("id", id);
+
+        Map<String, String> resultData = SeleniumUtils.getResultData("id",id);
+        log.info("printUrl.resultData:{}", resultData);
+        File excelFile = new File(excelFilePath);
+        if(excelFile == null || !excelFile.exists()){
             return error("报表文件持久化失败");
         }
+
 //        File outFile = ImageUtils.authCut(inFile);
 //        if(outFile == null || !outFile.exists()){
 //            return error("打印文件去除边界、背景失败");
 //        }
-        PrintParam printParam = FileUtils.readFile2PrintParam();
-        log.info("初始化打印参数:{}", printParam);
-        if(printParam == null){
-            return error("初始化打印参数失败");
-        }
 //        String outPath = outFile.getPath();
         String outPath = null;
         try {
-            outPath = inFile.getCanonicalPath();
+            outPath = excelFile.getCanonicalPath();
         } catch (IOException e) {
             return error("报表文件持久化失败");
         }
         log.info("处理打印文件,适应打印机:{}", outPath);
-        Boolean printFlag = PrintUtils.PDFprint(outPath, printParam);
+        JacobUtils.excelToPDF(outPath, printParam);
+        String outputFilePath = JacobUtils.getPdfFilePath(outPath);
+        Boolean printFlag = PrintUtils.PDFprint(outputFilePath, printParam);
         log.info("打印返回结果:{}", printFlag);
         log.info("--------------------------结束本地打印");
         if(!printFlag){
             return error("打印失败");
         }
+
+        log.info("删除{}天前的打印文件{}", 30, excelFile.getParent());
+        FileUtils.deleteFileDate(excelFile.getParentFile(),30);
         return success();
     }
 

+ 62 - 4
PrintServer/src/main/java/com/jd/printserver/javafx/entity/PrintParam.java

@@ -7,21 +7,30 @@ import lombok.Data;
 public class PrintParam {
 
     /**
+     * (print)
      * 作业名称
      */
-    private String jobName = "川仪打印作业";
+    private String jobName = "EI Auto Print Job  1111111";
 
     /**
-     * 打印方向  0 自动 1 横向 2 纵向
+     * (print)
+     * 打印方向  0 自动(停用) 1 横向 2 纵向
      */
-    private Integer orientation = 0;
+    private Integer orientation = 2;
 
     /**
+     * (print)
      * 打印份数
      */
     private Integer copies = 1;
 
     /**
+     * (jacob)
+     * 打印页面类型 1 A3  2 A4 ...
+     */
+    private Integer pageType=1;
+    /**
+     * (print/jacob)
      * 打印区域
      */
     private Integer width = Constants.PRINT_A4_WIDTH;
@@ -32,26 +41,71 @@ public class PrintParam {
     private Integer marginBottom = 10;
 
     /**
+     * 未使用
      * 纸张单位类型 1 毫米 2 英寸
      */
     private Integer unit = 1;
 
     /**
+     * 未使用(print)
      * 单双面 1 单面打印 2 双面打印,长边翻转 3 双面打印,短边翻转
      */
     private Integer sides = 1;
 
     /**
+     * 未使用
      * 颜色 1 黑白打印 2 彩打
      */
     private Integer chromaticity = 1;
 
     /**
-     * 缩放比例 0 自适应  x x%
+     * (jacob)
+     * 缩放比例 0 自适应(停用)  x x%
+     * 打印缩放fitToPages=4时,scale参数有用
      */
     private Float scale = 0f;
 
     /**
+     * (print)
+     * 页码范围类型 1 全部 2 部分页码
+     */
+    private Integer pageRange=1;
+
+
+    /**
+     * (print)
+     * 页码范围类型pageRange=2时,pageRangeStart参数有用
+     * 页码范围 开始页码 1 。。。
+     */
+    private Integer pageRangeStart=1;
+
+    /**
+     * (print)
+     * 页码范围类型pageRange=2时,pageRangeEnd参数有用
+     * pageRangeEnd > pageRangeStart时,取pageRangeStart~pageRangeEnd
+     * pageRangeEnd <= pageRangeStart时,取pageRangeStart时
+     * 页码范围 结束页码 1 。。。
+     */
+    private Integer pageRangeEnd=1;
+
+    /**
+     * 打印区域  1 整个工作表 2 选定区域
+     */
+    private Integer printArea=1;
+
+    /**
+     * 打印区域参数 A1:H6
+     * 打印区域printArea=2时,printAreaValue参数有用
+     */
+    private String printAreaValue="";
+
+    /**
+     * (jacob)
+     * 打印缩放  1 无打印缩放 2 将所有列打印在一页 3 将所有行打印在一页 4 自定义缩放
+     */
+    private Integer fitToPages = 1;
+
+    /**
      * 毫米转像素
      *  px = mm * 72 / 25.4
      * @return int
@@ -60,4 +114,8 @@ public class PrintParam {
         return (int)(value * Constants.PRINT_PX / Constants.MM2INCH);
     }
 
+    public static void main(String[] args) {
+        System.err.println(new PrintParam());
+    }
+
 }

+ 36 - 3
PrintServer/src/main/java/com/jd/printserver/utils/FileUtils.java

@@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Date;
 
 public class FileUtils {
 
@@ -65,8 +66,7 @@ public class FileUtils {
             fileSuffix = "";
         }
         String path = fileDirectory
-                + Constants.RESOURCE_SEPARATOR + DateUtils.dateTimeNow(DateUtils.YYYYMMDDHHMMSS.substring(0, 8))
-                + Constants.RESOURCE_SEPARATOR + DateUtils.dateTimeNow(DateUtils.YYYYMMDDHHMMSS.substring(8))
+                + Constants.RESOURCE_SEPARATOR + DateUtils.dateTimeNow(DateUtils.YYYYMMDDHHMMSS)
                 + Constants.RESOURCE_BOTTOM_SEPARATOR + snowflake.nextIdStr() + fileSuffix;
         try {
             File file = newFile(path);
@@ -135,5 +135,38 @@ public class FileUtils {
         }
     }
 
-
+    /**
+     * 删除指定目录下几天前生成的文件
+     *
+     * @return
+     */
+    public static void deleteFileDate(File folder, int days) {
+        try {
+            //得到文件里面全部的文件及文件夹
+            File[] files = folder.listFiles();
+            for(File f : files) {
+                //得到绝对路径下的文件及文件夹
+                File absFile = f.getAbsoluteFile();
+                //计算时间
+                long hour = 24;
+                long minute = 60;
+                long second = 60;
+                long mmcond = 1000;
+                //当前时间
+                long currTime = System.currentTimeMillis();
+                //文件被最后一次修改的时间
+                long lastTime = absFile.lastModified();
+                //时间差
+                long diffen = currTime - lastTime;
+
+                long thDay = days * hour * minute * second * mmcond;
+
+                if (diffen > thDay) {
+                    absFile.delete();
+                }
+            }
+        }catch (Exception e){
+            log.error("删除"+days+"天前打印文件失败", e);
+        }
+    }
 }

+ 383 - 0
PrintServer/src/main/java/com/jd/printserver/utils/JacobUtils.java

@@ -0,0 +1,383 @@
+package com.jd.printserver.utils;
+
+import com.jacob.activeX.ActiveXComponent;
+import com.jacob.com.ComThread;
+import com.jacob.com.Dispatch;
+import com.jacob.com.Variant;
+import com.jd.printserver.common.constants.Constants;
+import com.jd.printserver.javafx.entity.PrintParam;
+import lombok.extern.slf4j.Slf4j;
+
+import java.math.BigDecimal;
+
+@Slf4j
+public class JacobUtils {
+
+    public static void main(String[] args) {
+        String excelFilePath = "C:\\Users\\Administrator\\Desktop\\test.xlsx";
+        PrintParam printParam = new PrintParam();
+        excelToPDF(excelFilePath,printParam);
+    }
+
+
+    /**
+     * 获取 生成的 pdf 文件路径,默认与源文件同一目录
+     *
+     * @param excelFilePath excel文件
+     * @return 生成的 pdf 文件
+     */
+    public static String getPdfFilePath(String excelFilePath) {
+        String[] s = excelFilePath.split("\\.");
+        return s[0] + ".pdf";
+    }
+
+    public static String excelToPDF(String inputFilePath, PrintParam printParam){
+        String outputFilePath = getPdfFilePath(inputFilePath);
+        return excelToPDF(inputFilePath, outputFilePath, printParam);
+    }
+
+    /**
+     * 使用jacob实现excel转PDF
+     *
+     * @param inputFilePath  导入Excel文件路径
+     * @param outputFilePath 导出PDF文件路径
+     */
+    public static String excelToPDF(String inputFilePath, String outputFilePath, PrintParam printParam) {
+        ActiveXComponent ax = null;
+        Dispatch excel = null;
+        try {
+            ComThread.InitSTA();
+            ax = new ActiveXComponent("Excel.Application");
+            // 这里Visible是控制文档打开后是可见还是不可见,若是静默打印,那么第三个参数就设为false就好了
+            ax.setProperty("Visible", new Variant(false));
+            //禁用宏
+            ax.setProperty("AutomationSecurity", new Variant(3));
+
+            Dispatch excels = ax.getProperty("Workbooks").toDispatch();
+
+            Object[] obj = {
+                    inputFilePath,
+                    new Variant(false),
+                    new Variant(false)
+            };
+            //将excel表格 设置成A4的大小
+            //A3是8,A4是9,A5是11等等
+            //excel = Dispatch.invoke(excels, "Open", Dispatch.Method, obj, new int[9]).toDispatch();
+            excel = Dispatch.call(excels, "Open", inputFilePath, new Integer(0), Boolean.FALSE).toDispatch();
+            //获取到sheets的集合对象
+            Dispatch sheets = Dispatch.get(excel, "sheets").toDispatch();
+            //获取到总表数
+            int count = Dispatch.get(sheets, "count").changeType(Variant.VariantInt).getInt();
+            if(count < 1){
+                log.error("EXCEL数据为空");
+                return null;
+            }
+            //获取到sheet页
+            // new Object[]{1}  第一个sheet
+            Dispatch sheet = Dispatch.invoke(sheets, "Item", Dispatch.Get, new Object[]{1}, new int[1]).toDispatch();
+
+            setPrintParam2Worksheet(sheet,printParam);
+
+            //转换格式
+            Object[] obj2 = {
+                    //PDF格式等于0
+                    new Variant(0),
+                    outputFilePath,
+                    //0=标准(生成的PDF图片不会模糊),1=最小的文件
+                    new Variant(0)
+            };
+            Dispatch.invoke(excel, "ExportAsFixedFormat", Dispatch.Method, obj2, new int[1]);
+            return outputFilePath;
+        } catch (Exception e) {
+            log.error("EXCEL转换PDF失败", e);
+            return null;
+        } finally {
+            if (excel != null) {
+                Dispatch.call(excel, "Close", new Variant(false));
+            }
+            if (ax != null) {
+                ax.invoke("Quit", new Variant[]{});
+                ax = null;
+            }
+            ComThread.Release();
+        }
+    }
+
+    public static void setPrintParam2Worksheet(Dispatch worksheet, PrintParam printParam){
+        Dispatch page = Dispatch.get(worksheet, "PageSetup").toDispatch();
+
+        //int[] excelSize = getExcelWidthAndHeight(worksheet);
+        PaperSize paperSize =PaperSize.resultPaperSize2Value(printParam.getWidth(),printParam.getHeight());
+        //int excelWidth = excelSize[0];
+        //int excelHeight = excelSize[1];
+//        int printWidth = paperSize.getWidth() - printParam.getMarginLeft() -printParam.getMarginRight();
+//        int printHeight = paperSize.getHeight() - printParam.getMarginTop() - printParam.getMarginBottom();
+
+        // 纵向缩放比例
+        //float zScale = getMinScale(printWidth, printHeight, excelWidth, excelHeight);
+        // 横向缩放比例
+        //float hScale = getMinScale(printHeight, printWidth, excelWidth, excelHeight);
+        //缩放比例
+        float scale = printParam.getScale();
+        //打印方向 0 自动 1 横向 2 纵向
+        int orientation = printParam.getOrientation();
+        // 打印缩放 1 无打印缩放 2 将所有列打印在一页 3 将所有行打印在一页 4 自定义缩放
+        int fitToPages = printParam.getFitToPages();
+
+//        if(orientation == 0){
+//            //自动方向
+//            if(zScale < hScale){
+//                // 横向需要缩小比例小
+//                // 打印方向 0 自动 1 横向 2 纵向
+//                orientation = 1;
+//            }else{
+//                // 纵向需要缩小比例小
+//                //打印方向 0 自动 1 横向 2 纵向
+//                orientation = 2;
+//            }
+//            printParam.setOrientation(orientation);
+//
+//        }
+
+//        if(fitToPages == 4 && scale == 0f){
+//            //自动缩放
+//            if(orientation == 1){
+//                //横向
+//                scale = hScale;
+//            }else if(orientation == 2){
+//                //纵向
+//                scale = zScale;
+//            }
+//            printParam.setScale(scale);
+//        }
+
+        //页面大小  A3是8,A4是9,A5是11等等
+        Dispatch.put(page, "PaperSize", new Integer(paperSize.getValue()));
+
+        //左
+        Dispatch.put(page, "LeftMargin", new Variant(printParam.getMarginLeft()));
+        //上
+        Dispatch.put(page, "TopMargin", new Variant(printParam.getMarginTop()));
+        //右
+        Dispatch.put(page, "RightMargin", new Variant(printParam.getMarginRight()));
+        //下
+        Dispatch.put(page, "BottomMargin", new Variant(printParam.getMarginBottom()));
+        //是否设置区域打印
+        //Dispatch.put(page, "PrintArea", true);
+        //打印方向 0 自动 1 横向 2 纵向
+        if(orientation == 1){
+            //设置横向打印2还是纵向打印1
+            Dispatch.put(page, "Orientation", 2);
+        }else if(orientation == 2){
+            //设置横向打印2还是纵向打印1
+            Dispatch.put(page, "Orientation", 1);
+        }
+        // 打印缩放 1 无打印缩放 2 将所有列打印在一页 3 将所有行打印在一页 4 自定义缩放
+        if(fitToPages == 1){
+            //所有行为一页
+            Dispatch.put(page, "FitToPagesTall", false);
+            //所有列为一页(1或false)
+            Dispatch.put(page, "FitToPagesWide", false);
+        }else if(fitToPages == 2){
+            //所有行为一页
+            Dispatch.put(page, "FitToPagesTall", false);
+            //所有列为一页(1或false)
+            Dispatch.put(page, "FitToPagesWide", 1);
+        }else if(fitToPages == 3){
+            //所有行为一页
+            Dispatch.put(page, "FitToPagesTall", 1);
+            //所有列为一页(1或false)
+            Dispatch.put(page, "FitToPagesWide", false);
+        }else if(fitToPages == 4){
+            //设置缩放,值为100或false
+            Dispatch.put(page, "Zoom", scale);
+        }
+        log.info("sheet页设置成功");
+
+    }
+
+
+
+    /*public static float getMinScale(int printWidth, int printHeight, int imageWidth, int imageHeight){
+        float scale;
+        float wScale = 1f;
+        if(printWidth < imageWidth){
+
+            wScale = BigDecimal.valueOf(printWidth)
+                    .divide(BigDecimal.valueOf(imageWidth),4, BigDecimal.ROUND_DOWN).floatValue();
+        }
+        float hScale = 1f;
+        if(printHeight < imageHeight){
+            hScale = BigDecimal.valueOf(printHeight)
+                    .divide(BigDecimal.valueOf(imageHeight), 4, BigDecimal.ROUND_DOWN).floatValue();
+        }
+        if(wScale < hScale){
+            scale = wScale;
+        }else{
+            scale = hScale;
+        }
+        return scale;
+    }*/
+
+    /**
+     * 获取excel的宽和高
+     * @param
+     * @return int[] {excelWidth,excelHeight}
+     */
+    /*public static int[] getExcelWidthAndHeight(Dispatch worksheet){
+        // 获取工作表的列数和行数
+        Variant d = Dispatch.get(worksheet, "Columns").changeType(Variant.VariantInt);
+        Object a = d.getString();
+
+
+        int columns = Dispatch.get(worksheet, "Columns").changeType(Variant.VariantInt).getInt();
+        int rows = Dispatch.get(worksheet, "Rows").changeType(Variant.VariantInt).getInt();
+
+        // 计算总宽度和总高度
+        int excelWidth = 0;
+        int excelHeight = 0;
+        for (int i = 1; i <= columns; i++) {
+            Dispatch column = Dispatch.call(worksheet, "Column", i).toDispatch();
+            excelWidth += Dispatch.get(column, "Width").changeType(Variant.VariantInt).getInt();
+        }
+        for (int i = 1; i <= rows; i++) {
+            Dispatch column = Dispatch.call(worksheet, "Row", i).toDispatch();
+            excelHeight += Dispatch.get(column, "Height").changeType(Variant.VariantInt).getInt();
+        }
+        return new int[] {excelWidth,excelHeight};
+    }*/
+
+    public enum PaperSize{
+        // value请查询https://learn.microsoft.com/zh-cn/office/vba/api/excel.xlpapersize
+        xlPaperA3(1,8,"A3:297mm X 420mm",297,420),
+        xlPaperA4(2,9,"A4:210mm X 297mm",210,297),
+        xlPaperA5(3,11,"A5:148mm X 210mm",148,210),
+        xlPaperB5(4,13,"B5:182mm X 257mm",182,257),
+        xlPaperDC5(5,28,"Devolop C5:162mm X 229mm",162,229),
+        xlPaperDDL(6,27,"Devolop DL:110mm X 220mm",110,220),
+        xlPaperDB5(7,34,"Devolop B5:176mm X 250mm",176,250),
+        xlPaperDM(8,37,"Devolop Monarch:3.875inch X 7.5inch",(int)(3.875  / Constants.INCHESPER_MILLIMETER),(int)(7.5 /  Constants.INCHESPER_MILLIMETER)),
+        xlPaperD9(9,19,"Devolop 9:3.875inch X 8.875inch",(int)(3.875  / Constants.INCHESPER_MILLIMETER),(int)(8.875 /  Constants.INCHESPER_MILLIMETER)),
+        xlPaperD10(10,20,"Devolop 10:4.125inch X 9.5inch",(int)(4.125  / Constants.INCHESPER_MILLIMETER),(int)(9.5 /  Constants.INCHESPER_MILLIMETER)),
+        xlPaperLT(11,1,"Letter:8.5inch X 11inch",(int)(8.5  / Constants.INCHESPER_MILLIMETER),(int)(11 /  Constants.INCHESPER_MILLIMETER)),
+        xlPaperLG(12,5,"Legal:8.5inch X 14inch",(int)(8.5  / Constants.INCHESPER_MILLIMETER),(int)(14 /  Constants.INCHESPER_MILLIMETER));
+        private int key;
+        private int value;
+        private String name;
+        private int width;
+        private int height;
+
+        private PaperSize(int key, int value, String name, int width, int height){
+            this.key = key;
+            this.value = value;
+            this.name = name;
+            this.width = width;
+            this.height = height;
+        }
+
+        public int getValue(){
+            return this.value;
+        }
+        public int getWidth(){
+            return this.width;
+        }
+        public int getHeight(){
+            return this.height;
+        }
+
+
+        public static PaperSize resultKey2Value(int key){
+            if(PaperSize.xlPaperA3.compareKey(key)){
+                return PaperSize.xlPaperA3;
+            }
+            if(PaperSize.xlPaperA4.compareKey(key)){
+                return PaperSize.xlPaperA4;
+            }
+            if(PaperSize.xlPaperA5.compareKey(key)){
+                return PaperSize.xlPaperA5;
+            }
+            if(PaperSize.xlPaperB5.compareKey(key)){
+                return PaperSize.xlPaperB5;
+            }
+            if(PaperSize.xlPaperDC5.compareKey(key)){
+                return PaperSize.xlPaperDC5;
+            }
+            if(PaperSize.xlPaperDDL.compareKey(key)){
+                return PaperSize.xlPaperDDL;
+            }
+            if(PaperSize.xlPaperDB5.compareKey(key)){
+                return PaperSize.xlPaperDB5;
+            }
+            if(PaperSize.xlPaperDM.compareKey(key)){
+                return PaperSize.xlPaperDM;
+            }
+            if(PaperSize.xlPaperD9.compareKey(key)){
+                return PaperSize.xlPaperD9;
+            }
+            if(PaperSize.xlPaperD10.compareKey(key)){
+                return PaperSize.xlPaperD10;
+            }
+            if(PaperSize.xlPaperLG.compareKey(key)){
+                return PaperSize.xlPaperLG;
+            }
+            if(PaperSize.xlPaperLT.compareKey(key)){
+                return PaperSize.xlPaperLT;
+            }
+            return PaperSize.xlPaperA3;
+        }
+
+        public static PaperSize resultPaperSize2Value(int width, int height){
+            if(PaperSize.xlPaperA3.comparePageSize(width,height)){
+                return PaperSize.xlPaperA3;
+            }
+            if(PaperSize.xlPaperA4.comparePageSize(width,height)){
+                return PaperSize.xlPaperA4;
+            }
+            if(PaperSize.xlPaperA5.comparePageSize(width,height)){
+                return PaperSize.xlPaperA5;
+            }
+            if(PaperSize.xlPaperB5.comparePageSize(width,height)){
+                return PaperSize.xlPaperB5;
+            }
+            if(PaperSize.xlPaperDC5.comparePageSize(width,height)){
+                return PaperSize.xlPaperDC5;
+            }
+            if(PaperSize.xlPaperDDL.comparePageSize(width,height)){
+                return PaperSize.xlPaperDDL;
+            }
+            if(PaperSize.xlPaperDB5.comparePageSize(width,height)){
+                return PaperSize.xlPaperDB5;
+            }
+            if(PaperSize.xlPaperDM.comparePageSize(width,height)){
+                return PaperSize.xlPaperDM;
+            }
+            if(PaperSize.xlPaperD9.comparePageSize(width,height)){
+                return PaperSize.xlPaperD9;
+            }
+            if(PaperSize.xlPaperD10.comparePageSize(width,height)){
+                return PaperSize.xlPaperD10;
+            }
+            if(PaperSize.xlPaperLG.comparePageSize(width,height)){
+                return PaperSize.xlPaperLG;
+            }
+            if(PaperSize.xlPaperLT.comparePageSize(width,height)){
+                return PaperSize.xlPaperLT;
+            }
+            return PaperSize.xlPaperA3;
+        }
+
+        private boolean compareKey(int key){
+            if(this.width == key){
+                return true;
+            }
+            return false;
+        }
+
+        private boolean comparePageSize(int width, int height){
+            if(this.width == width && this.height == height){
+                return true;
+            }
+            return false;
+        }
+    }
+}

+ 0 - 151
PrintServer/src/main/java/com/jd/printserver/utils/JxbrowserUtils.java

@@ -1,151 +0,0 @@
-package com.jd.printserver.utils;
-
-import com.jd.printserver.common.constants.Constants;
-import com.teamdev.jxbrowser.browser.Browser;
-import com.teamdev.jxbrowser.browser.event.ConsoleMessageReceived;
-import com.teamdev.jxbrowser.engine.Engine;
-import com.teamdev.jxbrowser.engine.EngineOptions;
-import com.teamdev.jxbrowser.engine.ProprietaryFeature;
-import com.teamdev.jxbrowser.engine.RenderingMode;
-import com.teamdev.jxbrowser.js.ConsoleMessage;
-import com.teamdev.jxbrowser.view.javafx.BrowserView;
-import javafx.application.Platform;
-import javafx.scene.Scene;
-import javafx.scene.layout.BorderPane;
-import javafx.stage.Stage;
-import org.apache.commons.lang3.time.StopWatch;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public class JxbrowserUtils {
-
-
-    public static final Logger log = LoggerFactory.getLogger(JxbrowserUtils.class);
-
-    public static String resultData = null;
-    public static Engine engine = null;
-    public static Browser browser = null;
-    public static Stage stage = null;
-
-    /**
-     * 获取网页返回数据最大等待时间。 30秒
-     */
-    private static Long maxWaitTime = Constants.JXBROWSER_CONSOLE_BASE64_WAIT_TIME;
-
-    static {
-        System.setProperty("jxbrowser.license.key", Constants.JXBROWSER_LICENSE_KEY);
-
-    }
-
-    public static String getResultData(final String url){
-        return getResultData(url,null, maxWaitTime);
-    }
-
-    public static String getResultData(final String url, final Long maxWaitTime){
-        return getResultData(url,null, maxWaitTime);
-    }
-
-
-    public static void getResultData(final String url,final Url2DataInterface url2DataInterface){
-        getResultData(url, url2DataInterface, null);
-    }
-
-    private synchronized static String getResultData(final String url, final Url2DataInterface url2DataInterface, final Long maxWaitTime){
-        resultData = null;
-        Platform.runLater(new Runnable() {
-            @Override
-            public void run() {
-                log.info("初始化隐藏浏览器");
-                if(stage == null || browser == null || browser.isClosed()){
-                    engine = Engine.newInstance(
-                            EngineOptions.newBuilder(RenderingMode.OFF_SCREEN)
-                                    .enableProprietaryFeature(ProprietaryFeature.AAC)
-                                    .enableProprietaryFeature(ProprietaryFeature.H_264)
-                                    .build());
-                    browser = engine.newBrowser();
-                    stage = new Stage();
-                    BrowserView view = BrowserView.newInstance(browser);
-                    Scene scene = new Scene(new BorderPane(view), 0, 0);
-                    stage.setScene(scene);
-                    //stage.show();
-                    //js打印监听
-                    browser.on(ConsoleMessageReceived.class, event -> {
-                        ConsoleMessage consoleMessage = event.consoleMessage();
-                        String message = consoleMessage.message();
-                        if(StringUtils.isNotEmpty(message)){
-                            String key = Constants.JXBROWSER_CONSOLE_BASE64_PREFIX;
-                            if(message.indexOf(key) == 0){
-                                if(message.length() > key.length()){
-                                    log.info("浏览器console.info(message)输出结果:{}", message);
-                                    message = message.substring(key.length());
-                                    if(url2DataInterface != null){
-                                        url2DataInterface.getData(message);
-                                    }else{
-                                        resultData = message;
-                                    }
-                                }
-                            }
-                        }
-                    });
-                }
-                browser.navigation().loadUrl(url);
-            }
-        });
-        if(maxWaitTime != null){
-            StopWatch stopWatch = new StopWatch();
-            stopWatch.start();
-            while (resultData == null){
-                try {
-                    Thread.sleep(100);
-                } catch (InterruptedException e) {
-                }
-                stopWatch.split();
-                if(stopWatch.getTime() >= maxWaitTime){
-                    break;
-                }
-            }
-            stopWatch.stop();
-            if(resultData != null){
-                log.info("浏览器{}毫秒返回结果", stopWatch.getTime());
-            }else{
-                log.info("浏览器{}毫秒后未返回结果,强制结束", stopWatch.getTime());
-            }
-        }
-        return resultData;
-    }
-
-    private static  void closeAll(){
-        if(engine != null && !engine.isClosed()){
-            try {
-                engine.close();
-                engine = null;
-            }catch (Exception e){
-                log.warn("关闭浏览器引擎失败", e);
-            }
-        }
-        if(browser != null && !browser.isClosed()){
-            try {
-                browser.close();
-                browser = null;
-            }catch (Exception e){
-                log.warn("关闭浏览器失败", e);
-            }
-        }
-        if(stage != null){
-            try {
-                Platform.runLater(new Runnable() {
-                    @Override
-                    public void run() {
-
-                        stage.close();
-                    }
-                });
-                stage = null;
-            }catch (Exception e){
-                log.warn("关闭窗口失败", e);
-            }
-        }
-
-    }
-}

+ 106 - 83
PrintServer/src/main/java/com/jd/printserver/utils/PrintUtils.java

@@ -24,20 +24,27 @@ public class PrintUtils {
     public static final Logger log = LoggerFactory.getLogger(PrintUtils.class);
 
     public static void main(String[] args) throws PrinterException {
+        String excelFilePath = "C:\\Users\\Administrator\\Desktop\\a.xlsx";
+
         PrintParam printParam = new PrintParam();
-        printParam.setMarginTop(5);
-        printParam.setMarginLeft(5);
-        printParam.setMarginRight(5);
-        printParam.setMarginBottom(5);
+        printParam.setMarginTop(0);
+        printParam.setMarginLeft(0);
+        printParam.setMarginRight(0);
+        printParam.setMarginBottom(0);
         printParam.setOrientation(0);
         printParam.setScale(0f);
-        PDFprint("G:\\WorkSoft\\STS\\workspace\\PrintServer\\target\\classes\\profile\\printUrl\\20230714\\175210_1679790882943012864_h.png", printParam);
+        JacobUtils.excelToPDF(excelFilePath, printParam);
+        String outputFilePath = JacobUtils.getPdfFilePath(excelFilePath);
+        PDFprint(outputFilePath, printParam);
+
+
+
     }
 
 
     public static Boolean PDFprint(String inputImgPath, PrintParam printParam){
-
-        try (PDDocument document = new PDDocument()) {
+//加载文档模板
+        try (PDDocument document = PDDocument.load(new File(inputImgPath))) {
             //单位:像素
             // 10mm边距, 对应 28px
             // 28px = 10mm * 72 / 25.4
@@ -49,82 +56,82 @@ public class PrintUtils {
             int paperHeight = printParam.mm2px(printParam.getHeight());
             int printWidth = paperWidth - marginLeft -marginRight;
             int printHeight = paperHeight - marginTop - marginBottom;
-            int pdfPaperWidth = 0;
-            int pdfPaperHeight = 0;
-            int pdfWidth = 0;
-            int pdfHeight = 0;
-
-            PDImageXObject pdImage = PDImageXObject.createFromFile(inputImgPath, document);
-            log.info("pdImage.getWidth():" + pdImage.getWidth());
-            log.info("pdImage.getHeight():" + pdImage.getHeight());
-
-            if(printParam.getOrientation() == 0){
-                // 纵向缩放比例
-                float zScale = getMinScale(printWidth, printHeight, pdImage.getWidth(), pdImage.getHeight());
-                // 横向缩放比例
-                float hScale = getMinScale(printHeight, printWidth, pdImage.getWidth(), pdImage.getHeight());
-
-                if(zScale < hScale){
-                    // 横向需要缩小比例小
-                    printParam.setOrientation(1);
-                }else{
-                    // 纵向需要缩小比例小
-                    printParam.setOrientation(2);
-                }
-
-            }
-            if (printParam.getOrientation() == 1) {
-                // 横向(宽高互反)
-                pdfPaperWidth = paperHeight;
-                pdfPaperHeight = paperWidth;
-                pdfWidth = printHeight;
-                pdfHeight = printWidth;
-            } else {
-                //纵向
-                pdfPaperWidth = paperWidth;
-                pdfPaperHeight = paperHeight;
-                pdfWidth = printWidth;
-                pdfHeight = printHeight;
-            }
-            float scale = printParam.getScale();
-            if(scale == 0f){
-                //缩小
-                scale = getMinScale(pdfWidth, pdfHeight, pdImage.getWidth(), pdImage.getHeight());
-            }
-
-
-//             PDPage page = new PDPage(PDRectangle.A4);
-            PDPage page = new PDPage(new PDRectangle(pdfPaperWidth, pdfPaperHeight));
-            document.addPage(page);
-
-            int imageWidth = BigDecimal.valueOf(pdImage.getWidth())
-                    //乘以
-                    .multiply(BigDecimal.valueOf(scale))
-                    // 丢弃小数部分,加一
-                    .setScale(0,BigDecimal.ROUND_DOWN)
-                    .intValue();
-            int imageHeight = BigDecimal.valueOf(pdImage.getHeight())
-                    //乘以
-                    .multiply(BigDecimal.valueOf(scale))
-                    // 丢弃小数部分,加一
-                    .setScale(0,BigDecimal.ROUND_DOWN)
-                    .intValue();
-
-
-            try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) {
-                contentStream.drawImage(
-                        pdImage,
-                        marginLeft + 1,
-                        pdfPaperHeight - imageHeight - marginBottom + 1,
-                        imageWidth - 2,
-                        imageHeight - 2);
-            } catch (IOException e) {
-                log.error("写入PDF失败", e);
-                return false;
-            }
-
-
-            document.save(inputImgPath.substring(0,inputImgPath.lastIndexOf(".")) + ".pdf");
+//            int pdfPaperWidth = 0;
+//            int pdfPaperHeight = 0;
+//            int pdfWidth = 0;
+//            int pdfHeight = 0;
+//
+//            PDImageXObject pdImage = PDImageXObject.createFromFile(inputImgPath, document);
+//            log.info("pdImage.getWidth():" + pdImage.getWidth());
+//            log.info("pdImage.getHeight():" + pdImage.getHeight());
+//
+//            if(printParam.getOrientation() == 0){
+//                // 纵向缩放比例
+//                float zScale = getMinScale(printWidth, printHeight, pdImage.getWidth(), pdImage.getHeight());
+//                // 横向缩放比例
+//                float hScale = getMinScale(printHeight, printWidth, pdImage.getWidth(), pdImage.getHeight());
+//
+//                if(zScale < hScale){
+//                    // 横向需要缩小比例小
+//                    printParam.setOrientation(1);
+//                }else{
+//                    // 纵向需要缩小比例小
+//                    printParam.setOrientation(2);
+//                }
+//
+//            }
+//            if (printParam.getOrientation() == 1) {
+//                // 横向(宽高互反)
+//                pdfPaperWidth = paperHeight;
+//                pdfPaperHeight = paperWidth;
+//                pdfWidth = printHeight;
+//                pdfHeight = printWidth;
+//            } else {
+//                //纵向
+//                pdfPaperWidth = paperWidth;
+//                pdfPaperHeight = paperHeight;
+//                pdfWidth = printWidth;
+//                pdfHeight = printHeight;
+//            }
+//            float scale = printParam.getScale();
+//            if(scale == 0f){
+//                //缩小
+//                scale = getMinScale(pdfWidth, pdfHeight, pdImage.getWidth(), pdImage.getHeight());
+//            }
+//
+//
+////             PDPage page = new PDPage(PDRectangle.A4);
+//            PDPage page = new PDPage(new PDRectangle(pdfPaperWidth, pdfPaperHeight));
+//            document.addPage(page);
+//
+//            int imageWidth = BigDecimal.valueOf(pdImage.getWidth())
+//                    //乘以
+//                    .multiply(BigDecimal.valueOf(scale))
+//                    // 丢弃小数部分,加一
+//                    .setScale(0,BigDecimal.ROUND_DOWN)
+//                    .intValue();
+//            int imageHeight = BigDecimal.valueOf(pdImage.getHeight())
+//                    //乘以
+//                    .multiply(BigDecimal.valueOf(scale))
+//                    // 丢弃小数部分,加一
+//                    .setScale(0,BigDecimal.ROUND_DOWN)
+//                    .intValue();
+//
+//
+//            try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) {
+//                contentStream.drawImage(
+//                        pdImage,
+//                        marginLeft + 1,
+//                        pdfPaperHeight - imageHeight - marginBottom + 1,
+//                        imageWidth - 2,
+//                        imageHeight - 2);
+//            } catch (IOException e) {
+//                log.error("写入PDF失败", e);
+//                return false;
+//            }
+//
+//
+//            document.save(inputImgPath.substring(0,inputImgPath.lastIndexOf(".")) + ".pdf");
 
             PrinterJob printJob = PrinterJob.getPrinterJob();
             printJob.setJobName(printParam.getJobName());
@@ -202,6 +209,22 @@ public class PrintUtils {
                 default:
                     pars.add(Sides.ONE_SIDED);
             }
+
+
+            //页码范围类型 1 全部 2 部分页码
+            int pageRange = printParam.getPageRange();
+            if(pageRange == 2){
+                //打印页数
+                //打印第1~2页
+                if(printParam.getPageRangeEnd() > printParam.getPageRangeStart()){
+                    //打印开始到结束页
+                    pars.add(new PageRanges(printParam.getPageRangeStart(),printParam.getPageRangeEnd()));
+                }else{
+                    //打印一页
+                    pars.add(new PageRanges(printParam.getPageRangeStart()));
+                }
+            }
+
             try {
                 printJob.print(pars);
             } catch (PrinterException e) {

+ 265 - 0
PrintServer/src/main/java/com/jd/printserver/utils/SeleniumUtils.java

@@ -0,0 +1,265 @@
+package com.jd.printserver.utils;
+
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
+import com.jd.printserver.common.constants.Constants;
+import org.apache.commons.lang3.time.StopWatch;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.chrome.ChromeOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+/**
+ * selenium内置浏览器
+ */
+public class SeleniumUtils {
+
+    public static final Logger log = LoggerFactory.getLogger(SeleniumUtils.class);
+
+    public static List<Map<String, String>> resultDatas = new ArrayList<>();
+
+    /**
+     * 获取网页返回数据最大等待时间。 30秒
+     */
+    private static Long maxWaitTime = Constants.JXBROWSER_CONSOLE_BASE64_WAIT_TIME;
+
+    public synchronized static Map<String, String> getResultDataByUrl(final String url,final String key,final String value){
+
+        Map<String, String> resultData = getResultData(key,value);
+        WebDriver driver = null;
+        try {
+            log.info("初始化隐藏浏览器");
+
+            String zipFilePath = "selenium/Chrome.zip";
+            File zipFile = initChromeZipFile(zipFilePath);
+
+            log.info("Chrome.zip地址:" + zipFile.getCanonicalPath());
+
+            String outputFolder = zipFile.getParentFile().getCanonicalPath();
+            String driverPath = outputFolder +  "/Chrome/Application/chromedriver.exe";
+            File driverFile = new File(driverPath);
+            if(driverFile == null || !driverFile.exists()){
+                unzipChromeZipFile(zipFile);
+            }
+            log.info("chromedriver.exe地址:" + driverPath);
+            // 设置 Chrome 驱动的路径
+            System.setProperty("webdriver.chrome.driver", driverPath);
+            // 创建 ChromeOptions 对象,用于设置浏览器选项
+            ChromeOptions options = new ChromeOptions();
+            String chromePath = outputFolder +  "/Chrome/Application/chrome.exe";
+            log.info("chrome.exe地址:" + chromePath);
+            options.setBinary(chromePath);
+            //设置 chrome 的无头模式
+
+            options.addArguments("--headless");
+
+            options.addArguments("--disable-gpu");
+
+            options.addArguments("--no-sandbox");
+
+            options.addArguments("--disable-dev-shm-usage");
+
+            options.addArguments("--start-maximized");
+            // 创建 ChromeDriver 对象,并传入 ChromeOptions 对象
+            driver = new ChromeDriver(options);
+
+            // 最大化窗口
+            driver.manage().window().maximize();
+            // 访问网页
+            driver.get(url);
+            if(maxWaitTime != null){
+                StopWatch stopWatch = new StopWatch();
+                stopWatch.start();
+                while (resultData == null){
+                    try {
+                        Thread.sleep(100);
+                    } catch (InterruptedException e) {
+                    }
+                    stopWatch.split();
+                    if(stopWatch.getTime() >= maxWaitTime){
+                        break;
+                    }
+                    resultData = getResultData(key,value);
+                }
+                stopWatch.stop();
+                if(resultData != null){
+                    log.info("浏览器{}毫秒返回结果", stopWatch.getTime());
+                }else{
+                    log.info("浏览器{}毫秒后未返回结果,强制结束", stopWatch.getTime());
+                }
+            }
+
+        }catch (Exception e){
+            log.error("内置浏览器获取网页失败", e);
+        }finally {
+            if(driver != null){
+                try {
+                    // 关闭浏览器
+                    driver.quit();
+                }catch (Exception e){
+                    log.error("内置浏览器关闭失败", e);
+                }
+            }
+        }
+
+
+        return resultData;
+    }
+
+    public static Map<String, String> getURLParameters(String urlString) {
+        Map<String, String> params = new HashMap<>();
+
+        try {
+            URL url = new URL(urlString);
+            String query = url.getQuery();
+            if (query != null) {
+                String[] pairs = query.split("&");
+                for (String pair : pairs) {
+                    int idx = pair.indexOf("=");
+                    String key = URLDecoder.decode(pair.substring(0, idx), "UTF-8");
+                    String value = URLDecoder.decode(pair.substring(idx + 1), "UTF-8");
+                    params.put(key, value);
+                }
+            }
+        } catch (Exception e) {
+            log.error("请求地址错误", e);
+        }
+
+        return params;
+    }
+
+    public static String buildUrl(String baseUrl, Map<String, String> params){
+
+        StringBuilder urlBuilder = new StringBuilder(baseUrl);
+        try {
+            if (params != null && !params.isEmpty()) {
+                urlBuilder.append("?");
+                for (Map.Entry<String, String> entry : params.entrySet()) {
+                    String key = URLEncoder.encode(entry.getKey(), "UTF-8");
+                    String value = URLEncoder.encode(entry.getValue(), "UTF-8");
+                    urlBuilder.append(key).append("=").append(value).append("&");
+                }
+                urlBuilder.deleteCharAt(urlBuilder.length() - 1);  // 移除最后一个&
+            }
+        } catch (Exception e) {
+            log.error("请求地址拼接参数错误", e);
+        }
+        return urlBuilder.toString();
+    }
+
+    private static File initChromeZipFile(String zipFilePath){
+        File zipFile = new File(zipFilePath);
+        if(zipFile == null || !zipFile.exists()){
+            InputStream inputStream = SeleniumUtils.class.getClassLoader().getResourceAsStream(zipFilePath);
+            FileUtil.writeFromStream(inputStream,zipFile);
+        }
+        return zipFile;
+    }
+    private static String unzipChromeZipFile(File zipFile){
+        String outputFolder = zipFile.getParentFile().getPath();
+        try {
+            // 创建ZipInputStream对象
+            ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipFile.getAbsolutePath()));
+            // 读取zip文件中的条目
+            ZipEntry entry;
+            while ((entry = zipInputStream.getNextEntry()) != null) {
+                String entryPath = outputFolder + File.separator + entry.getName();
+
+                // 如果条目是一个文件夹,则创建对应的文件夹路径
+                if (entry.isDirectory()) {
+                    File dir = new File(entryPath);
+                    dir.mkdirs();
+                } else {
+                    // 如果条目是一个文件,则输出文件到指定路径
+                    FileOutputStream outputStream = new FileOutputStream(entryPath);
+
+                    byte[] buffer = new byte[1024];
+                    int length;
+                    while ((length = zipInputStream.read(buffer)) > 0) {
+                        outputStream.write(buffer, 0, length);
+                    }
+
+                    outputStream.close();
+                }
+
+                zipInputStream.closeEntry();
+            }
+
+            zipInputStream.close();
+            log.info("解压成功!");
+        } catch (IOException e) {
+            e.printStackTrace();
+            log.error("zip解压失败", e);
+        }
+
+        return outputFolder;
+    }
+
+
+    public static void addResultData(Map<String, String> map){
+        resultDatas.add(map);
+    }
+
+    public static void updateResultData(Map<String, String> map,String key){
+        for (int i = 0; i < resultDatas.size(); i++) {
+            Map<String, String> resultMap = resultDatas.get(i);
+            String resultKey = resultMap.get(key);
+            String inKey = map.get(key);
+            if(StrUtil.isNotEmpty(resultKey) && resultKey.equals(inKey)){
+                for (Map.Entry<String, String> entry : map.entrySet()) {
+                    resultMap.put(entry.getKey(), entry.getValue());
+                }
+                return;
+            }
+        }
+    }
+
+
+    public static void removeResultData(Map<String, String> map,String key){
+        for (int i = 0; i < resultDatas.size(); i++) {
+            String resultKey = resultDatas.get(i).get(key);
+            String inKey = map.get(key);
+            if(StrUtil.isNotEmpty(resultKey) && resultKey.equals(inKey)){
+                resultDatas.remove(i);
+                return;
+            }
+        }
+    }
+
+
+    public static void removeResultData(String key,String value){
+        Map<String, String> map = new HashMap<>();
+        map.put(key, value);
+        removeResultData(map, key);
+    }
+
+    public static Map<String, String> getResultData(Map<String, String> map,String key){
+        for (int i = 0; i < resultDatas.size(); i++) {
+            String resultKey = resultDatas.get(i).get(key);
+            String inKey = map.get(key);
+            if(StrUtil.isNotEmpty(resultKey) && resultKey.equals(inKey)){
+                return resultDatas.get(i);
+            }
+        }
+        return null;
+    }
+
+
+    public static Map<String, String> getResultData(String key,String value){
+        Map<String, String> map = new HashMap<>();
+        map.put(key, value);
+        return getResultData(map, key);
+    }
+}

+ 13 - 3
PrintServer/src/main/resources/application.yml

@@ -8,14 +8,24 @@
 #      max-request-size: 200MB
 server:
   port: 8084
+#log配置
 logging:
+  file:
+    name: printServer
+    path: ./logs
+  config: classpath:logback-spring.xml
   level:
     root: info
-  file:
-    name: logs/printServer.log
+  logback:
+    rollingpolicy:
+      max-history: 30
+      max-file-size: 10MB
 data:
   app:
+    # 程序应用版本
+    # @变量名@ 读取pom.xml中的值
+    version: @project.version@
     lable:
-      title: "川仪打印服务"
+      title: "EI Auto Print"
       exit: "退出"
       setting: "配置"

+ 105 - 0
PrintServer/src/main/resources/logback-spring.xml

@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 日志级别从低到高分为TRACE < DEBUG < INFO < WARN < ERROR < FATAL,如果设置为WARN,则低于WARN的信息都不会输出 -->
+<!-- scan:当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true -->
+<!-- scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 -->
+<!-- debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 -->
+<configuration  scan="true" scanPeriod="10 seconds">
+
+    <!--<include resource="org/springframework/boot/logging/logback/base.xml" />-->
+    <contextName>logback</contextName>
+    <!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 -->
+
+    <springProperty scope="context" name="logging.file.path" source="logging.file.path"/>
+    <springProperty scope="context" name="logging.file.name" source="logging.file.name"/>
+    <springProperty scope="context" name="logging.file.level" source="logging.level.root"/>
+    <springProperty scope="context" name="maxHistory" source="logging.logback.rollingpolicy.max-history"/>
+    <springProperty scope="context" name="maxFileSize" source="logging.logback.rollingpolicy.max-file-size"/>
+
+    <!-- 彩色日志(IDE下载插件才可以生效) -->
+    <!-- 彩色日志依赖的渲染类 -->
+    <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
+    <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
+    <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
+    <!-- 彩色日志格式 -->
+    <property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
+
+
+    <!--输出到控制台-->
+    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+        <!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
+        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+            <level>debug</level>
+        </filter>
+        <encoder>
+            <Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
+            <!-- 设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+    </appender>
+
+
+    <!-- 时间滚动输出 level为 INFO 日志 -->
+    <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 正在记录的日志文件的路径及文件名 -->
+        <!--        <file>${logging.file.path}/log_info.log</file>-->
+        <!--日志文件输出格式-->
+        <encoder>
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
+            <charset>UTF-8</charset>
+        </encoder>
+        <!-- 日志记录器的滚动策略,按日期,按大小记录 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 每天日志归档路径以及格式 -->
+            <fileNamePattern>${logging.file.path}/${logging.file.name}-log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
+            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
+                <maxFileSize>${maxFileSize}</maxFileSize>
+            </timeBasedFileNamingAndTriggeringPolicy>
+            <!--日志文件保留天数-->
+            <maxHistory>${maxHistory}</maxHistory>
+        </rollingPolicy>
+        <!-- 此日志文件只记录info级别的 -->
+        <!--        <filter class="ch.qos.logback.classic.filter.LevelFilter">-->
+        <!--            <level>info</level>-->
+        <!--            <onMatch>ACCEPT</onMatch>-->
+        <!--            <onMismatch>DENY</onMismatch>-->
+        <!--        </filter>-->
+    </appender>
+
+    <!--
+        <logger>用来设置某一个包或者具体的某一个类的日志打印级别、
+        以及指定<appender>。<logger>仅有一个name属性,
+        一个可选的level和一个可选的addtivity属性。
+        name:用来指定受此logger约束的某一个包或者具体的某一个类。
+        level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,
+              还有一个特俗值INHERITED或者同义词NULL,代表强制执行上级的级别。
+              如果未设置此属性,那么当前logger将会继承上级的级别。
+        addtivity:是否向上级logger传递打印信息。默认是true。
+    -->
+    <!--<logger name="org.springframework.web" level="info"/>-->
+    <!--<logger name="org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor" level="INFO"/>-->
+    <!--
+        使用mybatis的时候,sql语句是debug下才会打印,而这里我们只配置了info,所以想要查看sql语句的话,有以下两种操作:
+        第一种把<root level="info">改成<root level="DEBUG">这样就会打印sql,不过这样日志那边会出现很多其他消息
+        第二种就是单独给dao下目录配置debug模式,代码如下,这样配置sql语句会打印,其他还是正常info级别:
+     -->
+    <!--    <logger name="com.hgfr.gfs.esgenterprise.mapper" level="DEBUG"></logger>-->
+
+    <!--
+        root节点是必选节点,用来指定最基础的日志输出级别,只有一个level属性
+        level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,
+        不能设置为INHERITED或者同义词NULL。默认是DEBUG
+        可以包含零个或多个元素,标识这个appender将会添加到这个logger。
+    -->
+
+    <!--开发环境:打印控制台-->
+    <!--    <springProfile name="dev">-->
+    <!--        <logger name="com.*.mapper" level="debug"/>-->
+    <!--    </springProfile>-->
+
+    <root level="${logging.file.level}">
+        <appender-ref ref="CONSOLE" />
+        <appender-ref ref="INFO_FILE" />
+    </root>
+
+
+</configuration>

BIN
PrintServer/lib/jxbrowser-win64-7.21.jar → PrintServer/src/main/resources/selenium/Chrome.zip


Някои файлове не бяха показани, защото твърде много файлове са промени