first commit

main
ChenZichaoczc 2 weeks ago
commit c48739e9b3

@ -0,0 +1,168 @@
<job id="SubsMacros-MSExcel">
<script language="VBScript">
Option Explicit
On Error Resume Next
Dim digitDict
digitDict = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim docFileName, txtFileName
If WScript.Arguments.Count < 2 Then
MsgBox "Usage: SubsMacros-MSWord <doc file> <data file>"
WScript.Quit
End If
docFileName = WScript.Arguments(0)
txtFileName = WScript.Arguments(1)
'docFileName = "C:\Users\cloong\Desktop\新建文件夹\验证计划DVP&R-WFQ-R-19-008A.xlsm"
'txtFileName = "C:\Users\cloong\Desktop\新建文件夹\变更通知单.docm.txt"
Dim fs, txtFile, line, data
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(docFileName) = False Then
'WScript.Echo "File " & docFileName & " doesn't exist!"
WScript.Quit
End If
If Not Right(docFileName, 5) = ".xlsm" Then
'MsgBox "数据集引用文件 " & docFileName & " 扩展名不是.xlsm, 可能出现不正确结果. 建议将扩展名改为.xlsm"
End If
If fs.FileExists(txtFileName) = False Then
'WScript.Echo "File " & txtFileName & " doesn't exist!"
WScript.Quit
End If
Dim metaDic,nvpair,nv
Set txtFile = fs.OpenTextFile(txtFileName)
Set metaDic = CreateObject("Scripting.Dictionary") '将dataFile第一行的数据转换为metaDic
line = txtFile.ReadLine
data = Split(line, "|")
For Each nvpair In data
nv = Split(nvpair, "=")
If UBound(nv) > 0 Then
If Not metaDic.Exists(nv(0)) Then
metaDic.Add nv(0), nv(1)
End If
End If
Next
Dim excelApp, workbook, workSheet
Set excelApp = CreateObject("Excel.Application")
'excelApp.Visible = True
Set workbook = excelApp.Workbooks.Open(docFileName)
'For n=1 to workbook.Sheets.Count
'Set workSheet = workbook.Sheets(n)
'With workSheet
'WScript.Echo workbook.Names.Count
Dim NameItem,n,item,subvalue,attrName,ReferTo, Pos,subPos,col,row,range,sheetStr,pic
For Each NameItem In workbook.Names
'For Each NameItem in workbook.Names
'Set NameItem = workbook.Names.item(n)
'WScript.Echo NameItem.Name
For Each item In data
If item <> "" then
subvalue = Split(item,"=")
'WScript.Echo subvalue(0)
If (Left(NameItem.Name, 3) = Left(subvalue(0), 3)) Then
'attrName = Right(subvalue(1), Len(subvalue(1))-1)
'WScript.Echo subvalue(0)
Pos = NameItem.Value
subPos = Split(Pos,"$")
'WScript.Echo Pos
'WScript.Echo subPos(2)
range = subPos(1) & subPos(2)
sheetStr = Mid(subPos(0),2 ,Len(subPos(0))-2)
if Right(subvalue(1), 4) = ".jpg" Or Right(subvalue(1), 4) = ".png" Or Right(subvalue(1), 5) = ".jpg," Or Right(subvalue(1), 5) = ".png,"Then
Dim t,l,w,h,strs,str,Fso,i
'WScript.Echo "插入图片"
'Set Fso = CreateObject("Scripting.FileSystemObject")
'WScript.Echo sheetStr
workbook.Sheets(sheetStr).Select
workbook.Sheets(sheetStr).Range(range).Select
strs = Split(subvalue(1), ",")
i=0
On Error Resume Next
For Each str In strs
if(Right(str, 1) ="g") Then
Set Fso=workbook.Sheets(sheetStr).Shapes.AddPicture(str, False, True,workbook.Sheets(sheetStr).Range(range).Left+i, workbook.Sheets(sheetStr).Range(range).Top+5, 60, 65)
Fso.Name="jkexcel"
'Fso.ShapeRange.IncrementTop 5
'Fso.ShapeRange.IncrementLeft i
i=i+40
End If
Next
excelApp.ActiveSheet.PageSetup.CenterHorizontally = 2/0.035
excelApp.ActiveSheet.PageSetup.CenterVertically = 2/0.035
Else
'WScript.Echo subvalue(1)
col= workbook.Sheets(sheetStr).Range(range).Column
workbook.Sheets(sheetStr).cells(Int(subPos(2)),Int(col)).Value = subvalue(1)
End if
End if
End if
Next
Next
'End With
'Next
' With workSheet
' Dim curRow, curCol, colCount,rowCount, cellValue, attrName, item, cellName, subvalue, NameItem
' colCount = .UsedRange.Columns.count
' rowCount = .UsedRange.Rows.count
' Dim n
' WScript.Echo .Names.count
' For n= 1 To workSheet.Names.count
' Set NameItem = workSheet.Names.item(n)
' WScript.Echo NameItem.Name
' WScript.Echo NameItem.Value
' Next
' For curRow = 1 To (rowCount+.UsedRange.Row) '遍历题头至题尾的每一行,将该行的每一个&attrName替换为metaDic.Item(attrName)
' For curCol = 1 To (colCount+.UsedRange.Column)
' For Each NameItem In workbook.Names
' If .cells(curRow,curCol).Value <> "" Then
' For Each item In data
' subvalue = Split(item,"=")
' If subvalue(0) = NameItem.Name Then
' attrName = Right(subvalue(1), Len(subvalue(1))-1)
' .cells(curRow,curCol)= attrName
' End if
' Next
' End If
' Next
' Next
' Next
' End With
If Err.Number > 0 Then
WScript.Echo "脚本执行过程中发生了错误 '" & Err.Description & "', 很可能导致了不正确的结果, 请检查相应数据."
End If
workbook.Save
workbook.Close
excelApp.Quit
'WScript.Echo "end"
WScript.Quit
Function digitValue(hexStr)
digitValue = InStr(digitDict, hexStr) - 1
'WScript.Echo "Decode hex char " & hexStr & " to " & digitValue
End Function
</script>
</job>

@ -0,0 +1,221 @@
<job id="SubsMacros-MSWord">
<reference guid="{00020905-0000-0000-C000-000000000046}"/>
<script language="VBScript">
Option Explicit
On Error Resume Next
Dim digitDict
digitDict = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim fs, WshShell
Set fs = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim docFileName, txtFileName
If WScript.Arguments.Count < 2 Then
MsgBox "Usage: SubsMacros-MSWord <doc file> <data file>"
WScript.Quit
End If
docFileName = WScript.Arguments(0)
txtFileName = WScript.Arguments(1)
'docFileName = "C:\Users\cloong\Desktop\新建文件夹\新品立项报告书-WFQ-R-19-002A.docm"
'txtFileName = "C:\Users\cloong\Desktop\新建文件夹\变更通知单.docm.txt"
Dim wordApp
'Do
' Set wordApp = Nothing
' Set wordApp = GetObject(, "Word.Application")
' wordApp.Quit
'Loop Until wordApp Is Nothing
'Err.Clear
'On Error Resume Next
Dim docFilePath, pathLen
For pathLen = Len(docFileName) To 1 Step -1
If Mid(docFileName, pathLen, 1) = "\" Then
docFilePath = Left(docFileName, pathLen)
Exit For
End If
Next
'WshShell.Run "cmd.exe /c del /f /ah " & docFilePath & "~*.doc"
Dim txtFile, line, data
If fs.FileExists(docFileName) = False Then
'WScript.Echo "File " & docFileName & " doesn't exist!"
WScript.Quit
End If
If Not Right(docFileName, 4) = ".doc" Then
If Not Right(docFileName, 5) = ".docm" Then
'MsgBox "数据集引用文件 " & docFileName & " 扩展名不是.docm或doc, 可能出现不正确结果. 建议将扩展名改为.doc.docm"
End If
End If
If fs.FileExists(txtFileName) = False Then
'WScript.Echo "File " & txtFileName & " doesn't exist!"
WScript.Quit
End If
Set txtFile = fs.OpenTextFile(txtFileName)
line = txtFile.ReadLine()
txtFile.Close
Set data = ReadObject(line)
Dim doc
Dim docVar, varIndex
Dim pages
'Dim word, name, value, startPos, endPos,preword
Set wordApp = CreateObject("Word.Application")
'wordApp.Visible = True
Set doc = wordApp.Documents.Open( docFileName )
pages = doc.Windows(1).Panes(1).Pages.Count
'WScript.Echo pages
'检查所有的客户化属性,赋初值
Dim intProp, cusProp
For intProp = 1 To doc.CustomDocumentProperties.Count
If doc.CustomDocumentProperties(intProp).Value = "" Then
doc.CustomDocumentProperties(intProp).Value = " "
End If
Next
'更新属性值
Dim oShape
Dim t, dataName, dataVal ,pic,str,pim,i,pageName
Dim ObjSelection,wordRange
On Error Resume Next
For Each t In data
On Error Resume Next
dataName = t
If Right(data(dataName), 4) =".jpg" Or Right(data(dataName), 4) =".png" Or Right(data(dataName), 5) =".jpg," Or Right(data(dataName), 5) =".png," Then
'WScript.Echo "插入图片"
'WScript.Echo data(dataName)
str = data(dataName)
'WScript.Echo dataName
Set wordRange =wordApp.selection.Goto( , , ,dataName)
Set ObjSelection=wordApp.selection
if err.number=0 Then
On Error Resume Next
if(Right(str, 1) ="g") Then
Set pim = ObjSelection.InlineShapes.AddPicture(str)
pim.Title="wfword"
Set oShape = pim.ConvertToShape
'oShape.WrapFormat.Type = WdWrapType.wdWrapTopButtom
oShape.WrapFormat.Type = 3
oShape.ZOrder 4
oShape.WrapFormat.AllowOverlap = False
End If
End if
'If (pages > 1) Then
'For i = 1 to pages-1
'pageName = dataName & i
'WScript.Echo pageName
'Set wordRange =wordApp.selection.Goto( , , ,pageName)
'Set ObjSelection=wordApp.selection
'if err.number=0 Then
'On Error Resume Next
'if(Right(str, 1) ="g") Then
'Set pim =ObjSelection.InlineShapes.AddPicture(str)
'pim.Title="wfword"
'End If
'End if
'Next
'End If
err.Clear
End If
Next
Dim aStory, aField
For Each aStory In doc.StoryRanges
For Each aField In aStory.Fields
aField.Update
Next
Next
Dim sh
dim l1
dim n1
dim n2
On Error Resume Next
For Each sh in doc.Shapes
startPos = -1 : endPos = -1
name=trim(sh.TextFrame.TextRange.text)
If left(name, 2) = "&[" and mid(name,len(name)-1,1) = "]" then
l1=len(name)
n1=right(name,l1-2)
n2=left(n1,l1-4)
name=n2
If data.Exists(name) Then
value = data(name)
sh.TextFrame.TextRange.Text=value
wordApp.Selection.Find.Execute wdReplaceAll
'WScript.Echo "wordApp.Selection.Find.Execute wdReplaceAll"
Else
value = "(?)"
'WScript.Echo "(?)"
'doc.Range(startPos-2, endPos+1).Text = value
End If
' WScript.Echo "Substituting " & doc.Range(startPos, endPos).Text & " to " & value
startPos = -1 : endPos = -1
End If
Next
'On Error Goto 0
'Err.Clear
doc.Save
'WScript.Echo "插入图片成功"
doc.Close
wordApp.Quit
'WshShell.Run "cmd.exe /c del /f /ah " & docFilePath & "~*.doc"
'WScript.Echo "end"
If Err.Number > 0 Then
' WScript.Echo "脚本执行过程中发生了错误 '" & Err.Description & "', 很可能导致了不正确的结果, 请检查相应数据."
End If
Function ReadObject(dataline)
Dim data, nvpair, nv
Set ReadObject = CreateObject("Scripting.Dictionary")
data = Split(dataline, "|")
For Each nvpair In data
nv = Split(nvpair, "=")
If UBound(nv) >= 1 Then
If Not ReadObject.Exists(nv(0)) Then
ReadObject.Add nv(0), SubstEscSeq(nv(1))
End If
End If
Next
End Function
Function digitValue(hexStr)
digitValue = InStr(digitDict, hexStr) - 1
'WScript.Echo "Decode hex char " & hexStr & " to " & digitValue
End Function
Function SubstEscSeq(str)
Dim startPos, tokenPos, strLen
SubstEscSeq = ""
strLen = Len(str)
startPos = 1
Do While startPos < strLen
tokenPos = InStr(startPos, str, "%")
If tokenPos < 1 Then
Exit Do
End If
SubstEscSeq = SubstEscSeq + Mid(str, startPos, tokenPos - startPos)
'WScript.Echo "Hex token " & Mid(str, tokenPos, 3) & " decoded to asc value: " & digitValue(Mid(str, tokenPos+1, 1)) * 16 + digitValue(Mid(str, tokenPos+2, 1))
SubstEscSeq = SubstEscSeq + Chr(digitValue(Mid(str, tokenPos+1, 1)) * 16 + digitValue(Mid(str, tokenPos+2, 1)))
startPos = tokenPos + 3
Loop
SubstEscSeq = SubstEscSeq + Mid(str, startPos, strLen - startPos + 1)
'WScript.Echo "Decoded string from " & str & " to " & SubstEscSeq
End Function
</script>
</job>

Binary file not shown.

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/core-renderer.jar"/>
<classpathentry exported="true" kind="lib" path="lib/iTextAsian.jar"/>
<classpathentry exported="true" kind="lib" path="lib/iTextAsianCmaps.jar"/>
<classpathentry exported="true" kind="lib" path="lib/itextpdf-5.0.6.jar"/>
<classpathentry exported="true" kind="lib" path="lib/ojdbc7.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cn.net.connor.designtopart</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/cn/net/connor/plm/util/ExcelWriteTable1.java=UTF-8
encoding//src/cn/net/connor/plm/util/ExcelWriteTable2.java=UTF-8
encoding//src/cn/net/connor/plm/util/ExcelWriteTable3.java=UTF-8

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

@ -0,0 +1,73 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Designtopart
Bundle-SymbolicName: cn.net.connor.designtopart;singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: cn.net.connor.designtopart.Activator
Eclipse-RegisterBuddy: k.util
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
com.teamcenter.rac.aifrcp;bundle-version="12000.3.0",
com.teamcenter.rac.common;bundle-version="12000.3.0",
com.teamcenter.rac.external;bundle-version="12000.3.0",
com.teamcenter.rac.kernel;bundle-version="12000.3.0",
com.teamcenter.rac.tcapps;bundle-version="12000.3.0",
com.teamcenter.rac.ui;bundle-version="12000.3.0",
com.teamcenter.rac.ui.commands;bundle-version="12000.3.0",
com.teamcenter.rac.util;bundle-version="12000.3.0",
k.util;bundle-version="1.0.0",
TcSoaCoreLoose;bundle-version="12000.3.0",
TcSoaCoreRac;bundle-version="12000.3.0",
TcSoaCoreTypes;bundle-version="12000.3.0",
org.apache.poi.315;bundle-version="3.15.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: cn.net.connor.designtopart
Bundle-ActivationPolicy: lazy
Export-Package: cn.net.connor.designtopart,
cn.net.connor.designtopart.commands,
cn.net.connor.designtopart.designtopart,
com.connor.dfl.plm.util,
oracle.core.lmx,
oracle.core.lvf,
oracle.jdbc,
oracle.jdbc.aq,
oracle.jdbc.babelfish,
oracle.jdbc.connector,
oracle.jdbc.dcn,
oracle.jdbc.diagnostics,
oracle.jdbc.driver,
oracle.jdbc.internal,
oracle.jdbc.oci,
oracle.jdbc.oracore,
oracle.jdbc.pool,
oracle.jdbc.pooling,
oracle.jdbc.proxy,
oracle.jdbc.proxy.annotation,
oracle.jdbc.replay,
oracle.jdbc.replay.driver,
oracle.jdbc.replay.internal,
oracle.jdbc.rowset,
oracle.jdbc.util,
oracle.jdbc.xa,
oracle.jdbc.xa.client,
oracle.jpub.runtime,
oracle.net.ano,
oracle.net.aso,
oracle.net.jdbc.TNSAddress,
oracle.net.jdbc.nl,
oracle.net.jdbc.nl.mesg,
oracle.net.jndi,
oracle.net.ns,
oracle.net.nt,
oracle.net.resolver,
oracle.security.o3logon,
oracle.security.o5logon,
oracle.sql,
oracle.sql.converter
Bundle-ClassPath: .,
lib/ojdbc7.jar,
lib/core-renderer.jar,
lib/iTextAsian.jar,
lib/iTextAsianCmaps.jar,
lib/itextpdf-5.0.6.jar
Import-Package: com.teamcenter.rac.ui.common

@ -0,0 +1,17 @@
## 图纸转物料
> 配置首选项Connor_Design_To_Part
```text
需要转换Design对象类型=[-]关系名称=转换后对象类型+“|”分隔后边为属性继承对应关系R为版本上属性RM为版本表单属性I为对象上的属性+“*”标识属性为必填+“!”为可编辑;
Design版本=Part版本|R.Design属性值=R.Part属性值*RM. Design属性值=RM.Part属性值;
关系名称前加“-”表示将需要转换的对象版本添加到转换后的对象版本的关系下
```
示例
```text
ItemRevision=-IMAN_reference=Part Revision|R.object_desc=R.object_desc;RM.object_desc=RM.object_desc*!
Ac5_ProductInfoRevision=IMAN_reference=Ac5_ProductInfoRevision|R.object_string=R.object_desc;R.object_name=R.object_name;RM.ac5_BearingResearchDepart=RM.ac5_BearingResearchDepart!*;RM.ac5_ByTheHost=RM.ac5_ByTheHost;RM.ac5_CAE=rm.ac5_CAE;rm.ac5_ChiefDesigner=rm.ac5_ChiefDesigner;rm.ac5_ContractSigningTime=rm.ac5_ContractSigningTime;rm.ac5_CustomerIndustry=rm.ac5_CustomerIndustry;rm.ac5_Laboratory=rm.ac5_Laboratory;rm.ac5_MainEnginePlants=rm.ac5_MainEnginePlants;rm.ac5_NumberOfUnitsInstalled=rm.ac5_NumberOfUnitsInstalled
```

@ -0,0 +1,11 @@
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
icons/,\
.,\
lib/ojdbc7.jar,\
lib/core-renderer.jar,\
lib/iTextAsian.jar,\
lib/iTextAsianCmaps.jar,\
lib/itextpdf-5.0.6.jar
source.. = src/

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.ui.commands">
<command name="图纸创建物料" id="cn.net.connor.designtopart.commands.DesignToPartCommand"/>
<command name="数据发放" id="cn.net.connor.designtopart.commands.DataAllocationCommand"></command>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler commandId="cn.net.connor.designtopart.commands.DesignToPartCommand" class="k.KHandler"/>
<handler class="cn.net.connor.plm.handlers.DataAllocationHandler" commandId="cn.net.connor.designtopart.commands.DataAllocationCommand"></handler>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="menu:custWJ?after=projectCust">
<command commandId="cn.net.connor.designtopart.commands.DesignToPartCommand" id="cn.net.connor.designtopart.menu.designtopart"/>
</menuContribution>
<menuContribution locationURI="popup:org.eclipse.ui.popup.any?before=additions">
<command commandId="cn.net.connor.designtopart.commands.DataAllocationCommand" mnemonic="S" icon="icons/refresh_16.png" id="com.LINIX.sap.commands.batchDownload">
<visibleWhen>
<and>
<or>
<reference definitionId="com.teamcenter.rac.ui.inMainPerspective"/>
<reference definitionId="com.teamcenter.rac.cme.mpp.inMainView"/>
</or>
<iterate ifEmpty="false">
<adapt type="com.teamcenter.rac.kernel.TCComponent">
<!-- A8_ProductRevision==> 指定版本类型-->
<test property="com.teamcenter.rac.kernel.TCComponent.type" value="DocumentRevision" />
</adapt>
</iterate>
<with variable="rac_command_suppression">
<not>
<iterate operator="or"><equals value="com.nancal.XXXHandler" /> </iterate>
</not>
</with>
</and>
</visibleWhen>
</command>
</menuContribution>
</extension>
</plugin>

@ -0,0 +1,44 @@
package cn.net.connor.designtopart;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "cn.net.connor.designtopart"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}

@ -0,0 +1,22 @@
package cn.net.connor.designtopart;
import com.teamcenter.rac.util.Registry;
public class DesigntopartLocale {
public static final Registry reg = Registry.getRegistry(DesigntopartLocale.class);
public static String getString(String title) {
if (isEmpty(title)) {
return "";
} else {
String res = reg.getString(title);
return isEmpty(res) ? title : res;
}
}
private static boolean isEmpty(String title) {
return title == null || "".equals(title.trim());
}
}

@ -0,0 +1,16 @@
package cn.net.connor.designtopart.commands;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import cn.net.connor.designtopart.designtopart.DesignToPartDialog;
import cn.net.connor.designtopart.designtopart.DesignToPartDialogController;
import k.KCommand;
public class DesignToPartCommand extends KCommand {
public DesignToPartCommand(AbstractAIFApplication app, String commandId, String actionInfo) {
super(app, commandId, actionInfo);
this.setRunnable(new DesignToPartDialog(new DesignToPartDialogController(app)));
}
}

@ -0,0 +1,35 @@
package cn.net.connor.designtopart.designtopart;
import java.awt.BorderLayout;
import java.awt.Dimension;
import cn.net.connor.designtopart.DesigntopartLocale;
import javafx.embed.swing.JFXPanel;
import k.KDialog;
import k.KDialogController;
@SuppressWarnings("serial")
public class DesignToPartDialog extends KDialog {
protected DesignToPartDialogController controller;
public DesignToPartDialog(KDialogController controller) {
super(controller);
this.controller = (DesignToPartDialogController) controller;
}
@Override
protected void addListeners() {
}
@Override
protected void initUI() {
this.setTitle(DesigntopartLocale.getString("designtopart"));
this.setPreferredSize(new Dimension(800, 600));
this.setMinimumSize(new Dimension(800, 600));
JFXPanel panel = new JFXPanel();
panel.setScene(new DesignToPartPanel(this).getScene());
this.add(BorderLayout.CENTER, panel);
}
}

@ -0,0 +1,72 @@
package cn.net.connor.designtopart.designtopart;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import cn.net.connor.designtopart.DesigntopartLocale;
import k.KDialogController;
import k.util.KUtil;
public class DesignToPartDialogController extends KDialogController {
public static final String PREF_TRANSFER = DesigntopartLocale.getString("DESIGNTOPART.PREF");
protected List<TableBuilder> tableBuilders = new ArrayList<TableBuilder>();
public DesignToPartDialogController(AbstractAIFApplication app) {
super(app);
}
@Override
public boolean init() throws Exception {
InterfaceAIFComponent[] targets = app.getTargetComponents();
Map<String, List<TCComponentItemRevision>> selectedRevMap = new HashMap<>(64);
int targetCnt = KUtil.getLen(targets);
for (int i = 0; i < targetCnt; i++) {
InterfaceAIFComponent target = targets[i];
if (!(target instanceof TCComponentItemRevision)) {
continue;
}
TCComponentItemRevision rev = (TCComponentItemRevision) target;
String type = rev.getType();
List<TCComponentItemRevision> list;
if (selectedRevMap.containsKey(type)) {
list = selectedRevMap.get(type);
} else {
list = new ArrayList<TCComponentItemRevision>();
selectedRevMap.put(type, list);
}
if (!list.contains(rev)) {
list.add(rev);
}
}
selectedRevMap.forEach((k, v) -> System.out.println("ÀàÐÍ = " + k + ", " + v));
if (selectedRevMap.size() == 0) {
throw new TCException(DesigntopartLocale.getString("selectrev.INFO"));
}
// Connor_Design_To_Part
String[] prefVals = KUtil.getPrefVals(session, PREF_TRANSFER);
int len = KUtil.getLen(prefVals);
int counter = 0;
for (int i = 0; i < len; i++) {
String prefVal = prefVals[i];
TableBuilder builder = new TableBuilder(session, prefVal, selectedRevMap);
tableBuilders.add(builder);
counter += (builder.fromRevList == null ? 0 : builder.fromRevList.size());
}
if (tableBuilders.size() == 0) {
throw new TCException(String.format(DesigntopartLocale.getString("pref.ERROR1"), PREF_TRANSFER));
}
if (counter == 0) {
throw new TCException(DesigntopartLocale.getString("notransferdata.INFO"));
}
return true;
}
}

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0"
xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="cn.net.connor.designtopart.designtopart.DesignToPartPanelController">
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0">
<center>
<ScrollPane fx:id="scrollPane" fitToHeight="true" fitToWidth="true" prefViewportHeight="400.0" prefViewportWidth="600.0" styleClass="edge-to-edge" BorderPane.alignment="CENTER">
<content>
<VBox fx:id="vBox" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="150.0" spacing="12.0">
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" />
</padding>
</VBox>
</content>
</ScrollPane>
</center>
<bottom>
<GridPane alignment="CENTER" hgap="50.0" BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" minWidth="10.0" />
<ColumnConstraints hgrow="NEVER" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button mnemonicParsing="false" onAction="#createBtnClick" text=" 创建 " />
<Button mnemonicParsing="false" onAction="#closeBtnClick" text=" 取消 " GridPane.columnIndex="1" />
</children>
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" />
</padding>
</GridPane>
</bottom>
</BorderPane>
<AnchorPane fx:id="cover" prefHeight="600.0" prefWidth="800.0" visible="false">
<children>
<ProgressIndicator prefHeight="30.0" prefWidth="30.0" AnchorPane.bottomAnchor="15.0" AnchorPane.leftAnchor="15.0" />
</children>
</AnchorPane>
</children>
</StackPane>

@ -0,0 +1,14 @@
package cn.net.connor.designtopart.designtopart;
import java.awt.Window;
import k.ui.KFXPanel;
public class DesignToPartPanel extends KFXPanel{
public DesignToPartPanel(Window dialog) {
super(dialog, DesignToPartPanel.class, "style.css");
initData();
}
}

@ -0,0 +1,186 @@
package cn.net.connor.designtopart.designtopart;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.util.MessageBox;
import cn.net.connor.designtopart.DesigntopartLocale;
import cn.net.connor.designtopart.designtopart.TableBuilder.RowData;
import javafx.application.Platform;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TableView;
import javafx.scene.control.TitledPane;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import k.KOperation;
import k.KOperation2;
import k.ui.KFXPanel;
import k.ui.KFXPanelController;
import k.util.KUtil;
public class DesignToPartPanelController extends KFXPanelController {
@FXML
private AnchorPane cover;
@FXML
private VBox vBox;
@FXML
private ScrollPane scrollPane;
private DesignToPartDialog dialog;
private List<TableBuilder> tableBuilders;
protected boolean flag = false;
protected double scrollVal;
@Override
public void initData(KFXPanel panel) throws Exception {
this.dialog = (DesignToPartDialog) ((DesignToPartPanel) panel).getParentDialog();
this.tableBuilders = dialog.controller.tableBuilders;
setProgressVisible(true);
new KOperation(AIFUtility.getCurrentApplication(), DesigntopartLocale.getString("readdata.STATUS")) {
@Override
public boolean init() throws Exception {
return true;
}
@Override
public void execute() throws Exception {
int tableBuilderCnt = tableBuilders.size();
for (int i = 0; i < tableBuilderCnt; i++) {
TableBuilder tableBuilder = tableBuilders.get(i);
TableView<RowData> table = tableBuilder.build();
if (table == null) {
continue;
}
table.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
flag = true;
scrollVal = scrollPane.getVvalue();
scrollPane.setVvalue(scrollVal);
System.out.println("---MOUSE_CLICKED---");
}
});
Platform.runLater(() -> {
TitledPane pane = new TitledPane(tableBuilder.title, table);
int height = (100 + 35 * tableBuilder.fromRevList.size()) > 205
? (100 + 35 * tableBuilder.fromRevList.size())
: 205;
pane.setMinHeight(170);
pane.setMaxHeight(height);
pane.expandedProperty().addListener((observable, wasExpanded, isExpanded) -> {
pane.setMaxHeight(isExpanded ? height : 0);
pane.setMinHeight(isExpanded ? 230 : Region.USE_PREF_SIZE);
});
pane.setAnimated(false);
VBox.setVgrow(pane, Priority.ALWAYS);
vBox.getChildren().add(pane);
});
}
setProgressVisible(false);
}
}.executeModeless();
scrollPane.vvalueProperty()
.addListener((ObservableValue<? extends Number> ov, Number old_val, Number new_val) -> {
if (flag) {
scrollPane.setVvalue(scrollVal);
flag = false;
}
});
}
public void closeBtnClick() {
dialog.disposeDialog();
}
public void createBtnClick() {
setProgressVisible(true);
new KOperation2(AIFUtility.getCurrentApplication(), DesigntopartLocale.getString("create.STATUS")) {
@Override
public boolean init() throws Exception {
try {
checkCanCreate();
return true;
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(dialog, e);
}
return false;
}
@Override
public void execute() {
try {
doCreate();
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(dialog, e);
}
}
@Override
public void clearCache() throws Exception {
setProgressVisible(false);
}
}.executeModeless();
}
public void checkCanCreate() throws Exception {
for (int i = 0; i < tableBuilders.size(); i++) {
tableBuilders.get(i).checkCanCreate();
}
}
public void doCreate() throws Exception {
StringBuilder err = new StringBuilder();
for (int i = 0; i < tableBuilders.size(); i++) {
TableBuilder tableBuilder = tableBuilders.get(i);
String status = tableBuilder.title + ": " + DesigntopartLocale.getString("create.STATUS");
try {
tableBuilder.doCreate(status);
} catch (Exception e) {
e.printStackTrace();
err.append("[" + tableBuilder.title + "]" + e.getMessage() + "\r\n");
}
}
if (err.length() > 0) {
String errTitle = DesigntopartLocale.getString("createerror.TITLE");
String exportFileName = errTitle + KUtil.getDateStr(new Date(), "_yyyyMMdd_HHmmss") + ".txt";
KUtil.showScrollDialogWithExport(dialog, err.toString(), errTitle, exportFileName);
} else {
KUtil.info(dialog, DesigntopartLocale.getString("create.SUCCESS"));
}
}
public void setProgressVisible(boolean visible) {
if (cover != null) {
if (Platform.isFxApplicationThread()) {
cover.setVisible(visible);
} else {
Platform.runLater(() -> {
cover.setVisible(visible);
});
}
try {
TimeUnit.MILLISECONDS.sleep(20);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

@ -0,0 +1,817 @@
package cn.net.connor.designtopart.designtopart;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.connor.dfl.plm.util.DataBaseControl;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemRevisionType;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCComponentListOfValues;
import com.teamcenter.rac.kernel.TCComponentType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCPropertyDescriptor;
import com.teamcenter.rac.kernel.TCSession;
import cn.net.connor.designtopart.DesigntopartLocale;
import javafx.application.Platform;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.ComboBoxTableCell;
import javafx.util.Callback;
import k.ui.KFXEditableStringTableCell;
import k.ui.KFXUtil;
import k.util.KUtil;
@SuppressWarnings("all")
public class TableBuilder {
public static final String PROPLOC_ITEM = "I";
public static final String PROPLOC_REV = "R";
public static final String PROPLOC_REVMASTER = "RM";
public static final String CSS_REDCELL = "redcell";
public static final String DEFAULTNAME = DesigntopartLocale.getString("designtopart");
protected TCSession session;
protected TCComponentItemRevisionType fromRevType;
protected TCComponentItemRevisionType toRevType;
protected TCComponentType fromRevMasterType;
protected TCComponentType toRevMasterType;
protected List<ColConfig> colConfigs = new ArrayList<TableBuilder.ColConfig>();
protected List<TCComponentItemRevision> fromRevList;
protected TableView<RowData> table;
protected String title;
private String relation;
protected TCComponentItemType toItemType;
protected ColConfig colConfig_Name;
private boolean reverseRelation;
protected String drm01;
protected String drm22;
protected String drm03;
protected String[] connor_laoShiBao;
protected String[] connor_xinShiBao;
protected String[] drawingtypes;
protected String[] dbStrings;
protected boolean laoShiBao;
protected boolean xinShiBao;
protected long parseLong;
protected DataBaseControl dataBaseControl = null;
private TCComponentItem newItem;
private Map<String, String[]> xinMap = new HashMap<>();
private Map<String, String> laoMap = new HashMap<>();
private String[] xinValues = null, laoValues = null;
protected List<String> list = Arrays.asList(new String[] { "SB6_AutocadDLRevision", "SB6_AutocadSDLRevision",
"SB6_AutocadAssDLRevision", "SB6_CatiaAssDLRevision", "SB6_CatiaSDLRevision", "SB6_CatiaDesignLRevision",
"SB6_AutocadDXRevision", "SB6_AutocadSDXRevision", "SB6_AutocadAssDXRevision", "SB6_CatiaAssDXRevision",
"SB6_CatiaSDXRevision", "SB6_CatiaDesignXRevision" });
protected List<String> list2 = Arrays
.asList(new String[] { "SB6_CatiaAssDLRevision", "SB6_CatiaSDLRevision", "SB6_CatiaDesignLRevision" });
protected List<String> list3 = Arrays.asList(new String[] { "SB6_CatiaDesignLRevision", "SB6_CatiaAssDLRevision",
"SB6_CatiaSDLRevision", "SB6_AutocadAssDLRevision", "SB6_AutocadDLRevision", "SB6_AutocadSDLRevision" });
protected Map<String, Object> uomMap = new HashMap<>();
protected ObservableList<String> uomList = FXCollections.observableArrayList();
protected Map<String, String> khflMap = new HashMap<>();
protected Map<String, String[]> tzMap = new HashMap<>();
protected ObservableList<String> khflList = FXCollections.observableArrayList();
protected ObservableList<String> tzList = FXCollections.observableArrayList();
protected Map<String, String> khfl2Map = new HashMap<>();
protected Map<String, String> tz2Map = new HashMap<>();
protected ObservableList<String> khfl2List = FXCollections.observableArrayList();
protected ObservableList<String> tz2List = FXCollections.observableArrayList();
protected Map<String, String> khfl3Map = new HashMap<>();
protected Map<String, String> cgqlxMap = new HashMap<>();
protected Map<String, String> tz3Map = new HashMap<>();
protected ObservableList<String> khfl3List = FXCollections.observableArrayList();
protected ObservableList<String> cgqlxList = FXCollections.observableArrayList();
protected ObservableList<String> tz3List = FXCollections.observableArrayList();
protected String formName = "";
protected boolean isHave = false;
protected String sb6_PartRM14 = "";
public TableBuilder(TCSession session, String config, Map<String, List<TCComponentItemRevision>> selectedRevMap)
throws Exception {
this.session = session;
initData();
parseConfig(config, selectedRevMap);
}
protected void parseConfig(String config, Map<String, List<TCComponentItemRevision>> selectedRevMap)
throws Exception {
if (KUtil.isEmpty(config)) {
throw new TCException(DesigntopartLocale.getString("prefconfig.EMPTY"));
}
int ind = config.indexOf('|');
if (ind <= 0) {
throw new TCException(String.format(DesigntopartLocale.getString("prefvalue.ERROR1"), config));
}
String[] typeSplit = config.substring(0, ind).split("=");
String[] propConfigSplit = config.substring(ind + 1).split(";");
if (KUtil.getLen(typeSplit) == 3) {
String fromTypeName = typeSplit[0].trim();
this.relation = typeSplit[1].trim();
this.reverseRelation = this.relation.startsWith("-");
if (this.reverseRelation) {
this.relation = this.relation.substring(1);
}
String toTypeName = typeSplit[2].trim();
try {
if (!KUtil.isEmpty(fromTypeName)) {
this.fromRevType = (TCComponentItemRevisionType) session.getTypeComponent(fromTypeName);
this.fromRevMasterType = session.getTypeComponent(fromTypeName + "Master");
if (this.fromRevMasterType == null) {
this.fromRevMasterType = session.getTypeComponent(fromTypeName + " Master");
}
}
if (!KUtil.isEmpty(toTypeName)) {
this.toRevType = (TCComponentItemRevisionType) session.getTypeComponent(toTypeName);
this.toRevMasterType = session.getTypeComponent(toTypeName + "Master");
if (this.toRevMasterType == null) {
this.toRevMasterType = session.getTypeComponent(toTypeName + " Master");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (KUtil.isEmpty(this.relation) || this.fromRevType == null || this.toRevType == null
|| this.fromRevMasterType == null || this.toRevMasterType == null) {
throw new TCException(String.format(DesigntopartLocale.getString("prefvalue.ERROR1"), config));
}
this.toItemType = this.toRevType.getItemType();
String fromRevTypeName = fromRevType.getTypeName();
if (list.contains(fromRevTypeName)) {
ColConfig colConfig = new ColConfig(true, false, false, "对象ID", "I", "item_id", "I", "item_id");
ColConfig colConfig2 = new ColConfig(false, true, false, "单位", "I", "uom_tag", "I", "uom_tag");
this.colConfigs.add(colConfig);
this.colConfigs.add(colConfig2);
if (list2.contains(fromRevTypeName)) {
ColConfig colConfig3 = new ColConfig(true, true, false, "客户分类", "I", "khfl", "I", "khfl");
ColConfig colConfig4 = new ColConfig(true, true, false, "特征", "I", "tz", "I", "tz");
this.colConfigs.add(colConfig3);
if(fromRevTypeName.equals("SB6_CatiaSDLRevision")) {
ColConfig colConfig5 = new ColConfig(true, true, false, "传感器类型", "I", "cgqlx", "I", "cgqlx");
this.colConfigs.add(colConfig5);
}
this.colConfigs.add(colConfig4);
}
}
int len = KUtil.getLen(propConfigSplit);
for (int i = 0; i < len; i++) {
String[] split = propConfigSplit[i].trim().split("=");
if (KUtil.getLen(split) != 2) {
continue;
}
String[] fromConfig = split[0].trim().split("\\.");
String[] toConfig = split[1].trim().split("\\.");
if (KUtil.getLen(fromConfig) != 2 || KUtil.getLen(toConfig) != 2) {
continue;
}
String fromPropLoc = fromConfig[0].trim().toUpperCase();
String fromPropName = fromConfig[1].trim();
String toPropLoc = toConfig[0].trim().toUpperCase();
String toPropName = toConfig[1].trim().replace("*", "").replace("!", "");
if (KUtil.isEmpty(fromPropLoc) || KUtil.isEmpty(fromPropName) || KUtil.isEmpty(toPropLoc)
|| KUtil.isEmpty(toPropName)) {
continue;
}
TCComponentType type = null;
switch (toPropLoc) {
case PROPLOC_ITEM:
type = toItemType;
break;
case PROPLOC_REV:
type = toRevType;
break;
case PROPLOC_REVMASTER:
type = toRevMasterType;
break;
default:
break;
}
if (type == null) {
continue;
}
TCPropertyDescriptor prop = type.getPropDesc(toPropName);
if (prop == null) {
throw new TCException(String.format(DesigntopartLocale.getString("propnotdefinedintype.ERROR2"),
toPropName, type.getDisplayTypeName()));
}
boolean require = toConfig[1].contains("*");
boolean editable = toConfig[1].contains("!");
String colName = prop.getDisplayName();
ColConfig colConfig = new ColConfig(require, editable, prop.getType2() == TCProperty.PROP_reference,
colName, fromPropLoc, fromPropName, toPropLoc, toPropName);
this.colConfigs.add(colConfig);
if (PROPLOC_REV.equals(toPropLoc) && "object_name".equals(toPropName)) {
this.colConfig_Name = colConfig;
}
}
if (this.colConfigs.size() == 0) {
throw new TCException(String.format(DesigntopartLocale.getString("prefvalue.ERROR1"), config));
}
this.fromRevList = selectedRevMap.get(fromRevTypeName);
this.title = fromRevType.getDisplayTypeName();
}
public static class ColConfig {
public boolean require;
public boolean editable;
public boolean isRefType;
public String colName;
public String fromPropLoc;
public String fromPropName;
public String toPropLoc;
public String toPropName;
public ColConfig(boolean require, boolean editable, boolean isRefType, String colName, String fromPropLoc,
String fromPropName, String toPropLoc, String toPropName) {
super();
this.require = require;
this.editable = editable;
this.isRefType = isRefType;
this.colName = colName;
this.fromPropLoc = fromPropLoc;
this.fromPropName = fromPropName;
this.toPropLoc = toPropLoc;
this.toPropName = toPropName;
}
}
public static class RowData {
public Map<ColConfig, SimpleStringProperty> dataMap = new HashMap<>();
public Map<ColConfig, SimpleObjectProperty<TCComponent>> refDataMap = new HashMap<>();
public TCComponentItemRevision fromRev;
public RowData(TCComponentItemRevision rev, List<ColConfig> colConfigs) throws Exception {
this.fromRev = rev;
rev.refresh();
TCComponent form = rev.getRelatedComponent("IMAN_master_form_rev");
form.refresh();
TCComponentItem item = rev.getItem();
item.refresh();
for (ColConfig colConfig : colConfigs) {
if (PROPLOC_REV.equals(colConfig.fromPropLoc)) {
addData(rev, colConfig);
} else if (PROPLOC_REVMASTER.equals(colConfig.fromPropLoc)) {
addData(form, colConfig);
} else if (PROPLOC_ITEM.equals(colConfig.fromPropLoc)) {
addData(item, colConfig);
}
}
}
public void addData(TCComponent comp, ColConfig colConfig) throws Exception {
if (colConfig.isRefType) {
TCComponent value = comp.getTCProperty(colConfig.fromPropName).getReferenceValue();
System.out.println(colConfig.fromPropName + " = " + value);
refDataMap.put(colConfig, new SimpleObjectProperty<TCComponent>(value));
} else {
String value = comp.getProperty(colConfig.fromPropName);
dataMap.put(colConfig, new SimpleStringProperty(value));
}
}
}
public void checkCanCreate() throws Exception {
if (table == null) {
return;
}
ObservableList<RowData> items = table.getItems();
int rowCounter = 0;
for (RowData rowData : items) {
rowCounter++;
for (ColConfig colConfig : rowData.dataMap.keySet()) {
if (colConfig.require) {
if (KUtil.isEmpty(rowData.dataMap.get(colConfig).getValueSafe())) {
Platform.runLater(() -> {
table.scrollTo(rowData);
});
throw new TCException(String.format(DesigntopartLocale.getString("tablerowdataempty.ERROR2"),
title, rowCounter));
}
}
}
}
}
public void doCreate(String status) throws Exception {
if (table == null) {
return;
}
ObservableList<RowData> items = table.getItems();
int rowCounter = 0;
int rowCount = items.size();
StringBuilder err = new StringBuilder();
for (RowData rowData : items) {
rowCounter++;
session.setStatus(String.format("%s ( %d / %d )", status, rowCounter, rowCount));
try {
createItem(rowData);
} catch (Exception e) {
e.printStackTrace();
err.append("\r\n" + rowData.fromRev + ": " + e.getMessage());
}
}
if (err.length() > 0) {
throw new Exception(err.toString());
}
}
protected void createItem(RowData rowData) throws Exception {
if (rowData == null || rowData.fromRev == null) {
return;
}
dbStrings = session.getPreferenceService().getStringValues("connor_xinshibao_db");
String strDriver = "oracle.jdbc.driver.OracleDriver";
String strUrl = "jdbc:oracle:thin:@" + dbStrings[0];
String strUserName = dbStrings[1];
String strPassword = dbStrings[2];
dataBaseControl = new DataBaseControl(strDriver, strUrl, strUserName, strPassword);
String id = "";
String lshMin = "";
String lshMax = "";
String prefix = "";
String newCode = "";
String khfl = "";
String cgqlx = "";
String tz = "";
String sb6_DRM03 = "";
String uom_tag_display = "";
Object uom_tag_real = null;
Map<ColConfig, SimpleStringProperty> dataMap = rowData.dataMap;
for (ColConfig colConfig : dataMap.keySet()) {
if ("item_id".equals(colConfig.fromPropName)) {
id = dataMap.get(colConfig).getValue();
}
if ("khfl".equals(colConfig.fromPropName)) {
khfl = dataMap.get(colConfig).getValue();
}
if ("cgqlx".equals(colConfig.fromPropName)) {
cgqlx = dataMap.get(colConfig).getValue();
}
if ("tz".equals(colConfig.fromPropName)) {
tz = dataMap.get(colConfig).getValue();
}
if ("sb6_DRM03".equals(colConfig.fromPropName)) {
sb6_DRM03 = dataMap.get(colConfig).getValue();
}
if ("uom_tag".equals(colConfig.fromPropName)) {
uom_tag_display = dataMap.get(colConfig).getValue();
uom_tag_real = uomMap.get(uom_tag_display);
}
}
String type = rowData.fromRev.getType();
switch (type) {
case "SB6_CatiaDesignLRevision":
String khflStr = khflMap.get(khfl);
String[] tzStr = tzMap.get(tz);
id = id.length() > 8 ? id.substring(0, 8) : id;
prefix = id + khflStr;
lshMin = tzStr[0];
lshMax = tzStr[1];
newCode = dataBaseControl.getNewCode(prefix, lshMin, lshMax);
id = prefix + newCode;
break;
case "SB6_CatiaAssDLRevision":
String khfl2Str = khfl2Map.get(khfl);
String tz2Str = tz2Map.get(tz);
id = id.length() > 8 ? id.substring(0, 8) : id;
prefix = id + khfl2Str + tz2Str;
lshMin = "001";
lshMax = "999";
newCode = dataBaseControl.getNewCode(prefix, lshMin, lshMax);
if ("".equals(newCode)) {
throw new TCException("对象" + prefix + "流水号已用完");
}
id = prefix + newCode;
break;
case "SB6_CatiaSDLRevision":
String khfl3Str = khfl3Map.get(khfl);
String cgqlxStr = cgqlxMap.get(cgqlx);
String tz3Str = tz3Map.get(tz);
id = id.length() > 8 ? id.substring(0, 8) : id;
prefix = id + khfl3Str + tz3Str + cgqlxStr;
lshMin = "01";
lshMax = "99";
newCode = dataBaseControl.getNewCode(prefix, lshMin, lshMax);
if ("".equals(newCode)) {
throw new TCException("对象" + prefix + "流水号已用完");
}
id = prefix + newCode;
break;
case "SB6_AutocadAssDLRevision":
prefix = id + "M";
lshMin = "01";
lshMax = "99";
newCode = dataBaseControl.getNewCode(prefix, lshMin, lshMax);
if ("".equals(newCode)) {
throw new TCException("对象" + prefix + "流水号已用完");
}
id = prefix + newCode;
break;
case "SB6_AutocadDLRevision":
prefix = id + "M";
lshMin = "01";
lshMax = "99";
newCode = dataBaseControl.getNewCode(prefix, lshMin, lshMax);
if ("".equals(newCode)) {
throw new TCException("对象" + prefix + "流水号已用完");
}
id = prefix + newCode;
break;
case "SB6_AutocadSDLRevision":
prefix = id + "M";
lshMin = "01";
lshMax = "99";
newCode = dataBaseControl.getNewCode(prefix, lshMin, lshMax);
if ("".equals(newCode)) {
throw new TCException("对象" + prefix + "流水号已用完");
}
id = prefix + newCode;
break;
default:
break;
}
// 新老世宝对象类型
connor_xinShiBao = session.getPreferenceService().getStringValues("connor_xinshibao");
xinShiBao = Arrays.asList(connor_xinShiBao).contains(fromRevType.getTypeName());
xinValues = session.getPreferenceService().getStringValues("Conno_Design_to_Part_CHDLX");
for (int i = 0; i < xinValues.length; i++) {
String[] split = xinValues[i].split("=");
xinMap.put(split[0], split[1].split(":"));
}
if (xinShiBao) {
if (!list3.contains(type)) {
if ("".equals(sb6_DRM03)) {
throw new TCException("图纸类型为空,无法创建物料");
}
if (!xinMap.containsKey(sb6_DRM03)) {
throw new TCException("Conno_Design_to_Part_CHDLX不包含该图纸类型" + sb6_DRM03);
}
prefix = xinMap.get(sb6_DRM03)[0];
lshMin = xinMap.get(sb6_DRM03)[1];
int length = 11 - prefix.length() - lshMin.length();
while (length > 0) {
lshMin = "0" + lshMin;
length--;
}
length = 11 - prefix.length();
while (length > 0) {
lshMax = "9" + lshMax;
length--;
}
// lshMax = prefix + lshMax;
newCode = dataBaseControl.getNewCode(prefix, lshMin, lshMax);
id = prefix + newCode;
// id = id.substring(prefix.length());
TCComponentItem find = toItemType.find(id);
while (find != null) {
newCode = dataBaseControl.getNewCode(prefix, lshMin, lshMax);
id = prefix + newCode;
// id = id.substring(prefix.length());
find = toItemType.find(id);
}
}
sb6_PartRM14 = id;
}
connor_laoShiBao = session.getPreferenceService().getStringValues("connor_laoshibao");
laoShiBao = Arrays.asList(connor_laoShiBao).contains(fromRevType.getTypeName());
drawingtypes = session.getPreferenceService().getStringValues("connor_laoshibao_sb6_DRM03");
laoValues = session.getPreferenceService().getStringValues("Conno_Design_to_Part_CHDL");
for (int i = 0; i < laoValues.length; i++) {
String[] split = laoValues[i].split("=");
laoMap.put(split[0], split[1]);
}
if (laoShiBao) {
TCComponent component = rowData.fromRev.getRelatedComponent("IMAN_master_form_rev");
drm03 = component.getProperty("sb6_DRM03");// 图纸类型
drm01 = component.getProperty("sb6_DRM01");// 图号
drm22 = component.getProperty("sb6_DRM22");// 图纸代号
if (Arrays.asList(drawingtypes).contains(drm03)) {
return;
}
if (!list3.contains(type)) {
id = component.getProperty("sb6_DRM22");
}
sb6_PartRM14 = laoMap.get(drm03);
}
System.out.println("khfl = " + khfl);
System.out.println("tz = " + tz);
System.out.println("uom_tag_display = " + uom_tag_display + ", uom_tag_real = " + uom_tag_real);
System.out.println("lshMin = " + lshMin);
System.out.println("newCode = " + newCode);
System.out.println("lshMax = " + lshMax);
TCComponentItem newItem = null;
TCComponent[] findItem = session.search("零组件 ID", new String[] { "零组件 ID" }, new String[] { id + "*" });
for (TCComponent item : findItem) {
if (item.getProperty("item_id").equals(id)) {
newItem = (TCComponentItem) item;
isHave = true;
}
}
if (newItem == null) {
String revId = toItemType.getNewRev(null);
String name = this.colConfig_Name == null ? null : dataMap.get(colConfig_Name).getValueSafe();
if (KUtil.isEmpty(name)) {
name = DEFAULTNAME;
}
newItem = toItemType.create(id, revId, toItemType.getTypeName(), name, "", null);
}
this.newItem = newItem;
Map<String, String> itemProps = new HashMap<>();
Map<String, String> revProps = new HashMap<>();
Map<String, String> revMasterProps = new HashMap<>();
Map<String, TCComponent> itemRefProps = new HashMap<>();
Map<String, TCComponent> revRefProps = new HashMap<>();
Map<String, TCComponent> revMasterRefProps = new HashMap<>();
for (ColConfig colConfig : dataMap.keySet()) {
String value = dataMap.get(colConfig).getValueSafe();
if (PROPLOC_REV.equals(colConfig.toPropLoc)) {
revProps.put(colConfig.toPropName, value);
} else if (PROPLOC_REVMASTER.equals(colConfig.toPropLoc)) {
revMasterProps.put(colConfig.toPropName, value);
} else if (PROPLOC_ITEM.equals(colConfig.toPropLoc)) {
itemProps.put(colConfig.toPropName, value);
}
}
for (ColConfig colConfig : rowData.refDataMap.keySet()) {
TCComponent value = rowData.refDataMap.get(colConfig).getValue();
if (PROPLOC_REV.equals(colConfig.toPropLoc)) {
revRefProps.put(colConfig.toPropName, value);
} else if (PROPLOC_REVMASTER.equals(colConfig.toPropLoc)) {
revMasterRefProps.put(colConfig.toPropName, value);
} else if (PROPLOC_ITEM.equals(colConfig.toPropLoc)) {
itemRefProps.put(colConfig.toPropName, value);
}
}
TCComponentItemRevision rev = newItem.getLatestItemRevision();
if (!isHave) {
if (reverseRelation) {
rev.add(relation, rowData.fromRev);
rev.refresh();
} else {
rowData.fromRev.add(relation, rev);
rowData.fromRev.refresh();
}
}
TCComponent form = rev.getRelatedComponent("IMAN_master_form_rev");
this.formName = rev.getProperty("object_string").split(";")[0];
setProperties(newItem, itemProps);
setProperties(rev, revProps);
setProperties(form, revMasterProps);
setRefProperties(newItem, itemRefProps);
setRefProperties(rev, revRefProps);
setRefProperties(form, revMasterRefProps);
if (uom_tag_real != null) {
newItem.setReferenceProperty("uom_tag", (TCComponent) uom_tag_real);
}
newItem.refresh();
rev.refresh();
form.refresh();
}
private void setProperties(TCComponent comp, Map<String, String> props) throws Exception {
if (comp == null || props == null || props.size() == 0) {
return;
}
comp.lock();
try {
props.remove("item_id");
props.remove("khfl");
props.remove("cgqlx");
props.remove("tz");
props.remove("uom_tog");
comp.setProperties(props);
if (laoShiBao && comp instanceof TCComponentForm) {
comp.setStringProperty("sb6_PartRM14", sb6_PartRM14);
if (!isHave) {
comp.setStringProperty("object_name", formName);
}
}
if (xinShiBao && comp instanceof TCComponentForm) {
comp.setStringProperty("sb6_PartRM14", sb6_PartRM14);
comp.setStringProperty("object_name", formName);
}
comp.save();
} finally {
comp.unlock();
}
comp.refresh();
}
private void setRefProperties(TCComponent comp, Map<String, TCComponent> props) throws Exception {
if (comp == null || props == null || props.size() == 0) {
return;
}
comp.lock();
try {
for (String propName : props.keySet()) {
comp.setReferenceProperty(propName, props.get(propName));
}
comp.save();
} finally {
comp.unlock();
}
comp.refresh();
}
public TableView<RowData> build() throws Exception {
if (fromRevList == null || fromRevList.size() == 0) {
return null;
}
this.table = new TableView<TableBuilder.RowData>();
this.table.setEditable(true);
int colCnt = this.colConfigs.size();
for (int i = 0; i < colCnt; i++) {
ColConfig colConfig = colConfigs.get(i);
if (colConfig.isRefType) {
TableColumn<RowData, TCComponent> col = new TableColumn<TableBuilder.RowData, TCComponent>(
colConfig.colName);
col.setCellValueFactory(p -> p.getValue().refDataMap.get(colConfig));
this.table.getColumns().add(col);
continue;
}
TableColumn<RowData, String> col = new TableColumn<>(colConfig.colName);
col.setPrefWidth(110);
col.setCellValueFactory(p -> p.getValue().dataMap.get(colConfig));
this.table.getColumns().add(col);
if (colConfig.editable) {
col.setCellFactory(new Callback<TableColumn<RowData, String>, TableCell<RowData, String>>() {
@Override
public TableCell<RowData, String> call(TableColumn<RowData, String> param) {
return new KFXEditableStringTableCell<RowData, String>() {
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (colConfig.require) {
this.getStyleClass().remove(CSS_REDCELL);
if (KUtil.isEmpty(getString())) {
this.getStyleClass().add(CSS_REDCELL);
}
}
};
};
}
});
} else {
col.setCellFactory(new Callback<TableColumn<RowData, String>, TableCell<RowData, String>>() {
@Override
public TableCell<RowData, String> call(TableColumn<RowData, String> param) {
return new TableCell<RowData, String>() {
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
} else {
setText(item);
}
if (colConfig.require) {
this.getStyleClass().remove(CSS_REDCELL);
if (KUtil.isEmpty(item)) {
this.getStyleClass().add(CSS_REDCELL);
}
}
};
};
}
});
}
String fromRevTypeName = fromRevType.getTypeName();
if (list.contains(fromRevTypeName)) {
if ("uom_tag".equals(colConfig.fromPropName)) {
col.setCellFactory(ComboBoxTableCell.forTableColumn(uomList));
}
if ("SB6_CatiaDesignLRevision".equals(fromRevTypeName)) {
if ("khfl".equals(colConfig.fromPropName)) {
col.setCellFactory(ComboBoxTableCell.forTableColumn(khflList));
}
if ("tz".equals(colConfig.fromPropName)) {
col.setCellFactory(ComboBoxTableCell.forTableColumn(tzList));
}
}
if ("SB6_CatiaAssDLRevision".equals(fromRevTypeName)) {
if ("khfl".equals(colConfig.fromPropName)) {
col.setCellFactory(ComboBoxTableCell.forTableColumn(khfl2List));
}
if ("tz".equals(colConfig.fromPropName)) {
col.setCellFactory(ComboBoxTableCell.forTableColumn(tz2List));
}
}
if ("SB6_CatiaSDLRevision".equals(fromRevTypeName)) {
if ("khfl".equals(colConfig.fromPropName)) {
col.setCellFactory(ComboBoxTableCell.forTableColumn(khfl3List));
}
if ("cgqlx".equals(colConfig.fromPropName)) {
col.setCellFactory(ComboBoxTableCell.forTableColumn(cgqlxList));
}
if ("tz".equals(colConfig.fromPropName)) {
col.setCellFactory(ComboBoxTableCell.forTableColumn(tz3List));
}
}
}
}
// read data
int rowCnt = fromRevList == null ? 0 : fromRevList.size();
for (int i = 0; i < rowCnt; i++) {
TCComponentItemRevision rev = fromRevList.get(i);
RowData row = new RowData(rev, colConfigs);
this.table.getItems().add(row);
}
KFXUtil.autoResizeColumn(this.table);
return this.table;
}
public void initData() {
getLovValue("Design", "uom_tag", uomMap);
getKHFL("SB6_YYXHQ_CUSTOME", khflMap);
getKHFL("SB6_DYXHQ_CUSTOME", khfl2Map);
getKHFL("SB6_DDXHQ_CUSTOME", khfl3Map);
getKHFL("SB6_DDXHQ_CGQ", cgqlxMap);
getTZ("SB6_YYXHQ_TZ", tzMap);
getTZ2("SB6_DYXHQ_TZ", tz2Map);
getTZ2("SB6_DDXHQ_TZ", tz3Map);
uomMap.forEach((k, v) -> uomList.add(k));
khflMap.forEach((k, v) -> khflList.add(k));
khfl2Map.forEach((k, v) -> khfl2List.add(k));
khfl3Map.forEach((k, v) -> khfl3List.add(k));
cgqlxMap.forEach((k, v) -> cgqlxList.add(k));
tzMap.forEach((k, v) -> tzList.add(k));
tz2Map.forEach((k, v) -> tz2List.add(k));
tz3Map.forEach((k, v) -> tz3List.add(k));
}
public void getLovValue(String type, String property, Map<String, Object> map) {
try {
TCComponentItemType itemType = (TCComponentItemType) session.getTypeComponent(type);
TCPropertyDescriptor descriptor = itemType.getPropertyDescriptor(property);
TCComponentListOfValues lov = descriptor.getLOV();
Object[] listOfValues = lov.getListOfValues().getListOfValues();
for (int i = 0; i < listOfValues.length; ++i) {
String displayVal = lov.getListOfValues().getDisplayableValue(listOfValues[i]);
map.put(displayVal, listOfValues[i]);
}
} catch (TCException e) {
e.printStackTrace();
}
}
public void getKHFL(String str, Map<String, String> map) {
String[] values = session.getPreferenceService().getStringValues(str);
for (String val : values) {
String[] split = val.split("-");
map.put(val, split[1]);
}
}
public void getTZ(String str, Map<String, String[]> map) {
String[] values = session.getPreferenceService().getStringValues(str);
for (String val : values) {
String[] split = val.split(":");
map.put(val, split[1].split("-"));
}
}
public void getTZ2(String str, Map<String, String> map) {
String[] values = session.getPreferenceService().getStringValues(str);
for (String val : values) {
String[] split = val.split("-");
map.put(val, split[1]);
}
}
}

@ -0,0 +1,18 @@
.table-view {
-fx-faint-focus-color: transparent;
-fx-focus-color: rgba(0, 0, 0, 0.2);
-fx-background-insets: 0;
}
.redcell:filled {
-fx-background-color: #f5696c;
-fx-background-insets: 0.5;
}
.table-view:row-selection .table-row-cell:selected .redcell {
-fx-background-color: null;
}
.table-view:cell-selection .redcell:selected {
-fx-background-color: -fx-table-cell-border-color, -fx-background;
}

@ -0,0 +1,15 @@
#
#Wed Dec 23 10:14:08 CST 2020
designtopart=Design To Part
DESIGNTOPART.PREF=Connor_Design_To_Part
notransferdata.INFO=\u6CA1\u6709\u627E\u5230\u53EF\u4EE5\u8F6C\u6362\u7684\u7C7B\u578B
propnotdefinedintype.ERROR2=\u5C5E\u6027"%s"\u672A\u5728\u7C7B\u578B"%s"\u4E2D\u5B9A\u4E49
create.SUCCESS=\u56FE\u7EB8\u8F6C\u7269\u6599\u5B8C\u6210
selectrev.INFO=\u672A\u9009\u62E9\u7248\u672C\u7C7B\u578B
prefvalue.ERROR1=\u65E0\u6CD5\u89E3\u6790\u9996\u9009\u9879\u914D\u7F6E "%s"
create.STATUS=\u56FE\u7EB8\u8F6C\u7269\u6599
prefconfig.EMPTY=\u914D\u7F6E\u4E0D\u53EF\u4E3A\u7A7A
readdata.STATUS=\u52A0\u8F7D\u6570\u636E
createerror.TITLE=\u56FE\u7EB8\u8F6C\u7269\u6599\u9519\u8BEF
tablerowdataempty.ERROR2="%s"\u8868\u7B2C%d\u884C\u5FC5\u586B\u5C5E\u6027\u5B58\u5728\u7A7A\u503C\uFF0C\u8BF7\u5B8C\u5584\u540E\u518D\u6267\u884C\u521B\u5EFA
pref.ERROR1=\u9996\u9009\u9879"%s"\u914D\u7F6E\u9519\u8BEF

@ -0,0 +1,15 @@
#
#Wed Dec 23 10:14:08 CST 2020
designtopart=\u56FE\u7EB8\u8F6C\u7269\u6599
DESIGNTOPART.PREF=Connor_Design_To_Part
notransferdata.INFO=\u6CA1\u6709\u627E\u5230\u53EF\u4EE5\u8F6C\u6362\u7684\u7C7B\u578B
propnotdefinedintype.ERROR2=\u5C5E\u6027"%s"\u672A\u5728\u7C7B\u578B"%s"\u4E2D\u5B9A\u4E49
create.SUCCESS=\u56FE\u7EB8\u8F6C\u7269\u6599\u5B8C\u6210
selectrev.INFO=\u672A\u9009\u62E9\u7248\u672C\u7C7B\u578B
prefvalue.ERROR1=\u65E0\u6CD5\u89E3\u6790\u9996\u9009\u9879\u914D\u7F6E "%s"
create.STATUS=\u56FE\u7EB8\u8F6C\u7269\u6599
prefconfig.EMPTY=\u914D\u7F6E\u4E0D\u53EF\u4E3A\u7A7A
readdata.STATUS=\u52A0\u8F7D\u6570\u636E
createerror.TITLE=\u56FE\u7EB8\u8F6C\u7269\u6599\u9519\u8BEF
tablerowdataempty.ERROR2="%s"\u8868\u7B2C%d\u884C\u5FC5\u586B\u5C5E\u6027\u5B58\u5728\u7A7A\u503C\uFF0C\u8BF7\u5B8C\u5584\u540E\u518D\u6267\u884C\u521B\u5EFA
pref.ERROR1=\u9996\u9009\u9879"%s"\u914D\u7F6E\u9519\u8BEF

@ -0,0 +1,288 @@
package cn.net.connor.plm.dialogs;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import cn.net.connor.plm.entity.Prop;
import cn.net.connor.plm.util.ExcelWriteTable1;
import cn.net.connor.plm.util.ExcelWriteTable2;
import cn.net.connor.plm.util.ExcelWriteTable3;
import cn.net.connor.plm.util.SignPDF;
import java.awt.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class DataAllocationHandlerDialog extends JFrame implements Runnable{
private JLabel selectUploadLabel;
private JComponent uploadInput;
private JButton importButton;
private JButton okButton;
private JButton celButton;
private AbstractAIFUIApplication app;
private List<Prop> propList1;
private List<Prop> propList2;
private List<Prop> propList3;
private List<TCComponentItemRevision> relationRevs;
public DataAllocationHandlerDialog(AbstractAIFUIApplication app, List<Prop> propList1, List<Prop> propList2,
List<Prop> propList3, List<TCComponentItemRevision> relationRevs) {
// TODO Auto-generated constructor stub
this.app = app;
this.propList1 = propList1;
this.propList2 = propList2;
this.propList3 = propList3;
this.relationRevs = relationRevs;
}
public void initializationComponent() {
selectUploadLabel = new JLabel("请选择下载位置");
uploadInput = new JTextField(14);
importButton = new JButton("浏览");
okButton = new JButton("确定");
celButton = new JButton("取消");
SwingUtilities.getWindowAncestor(importButton);
}
/**
*
*/
public void initUi() {
initializationComponent();
JDialog dialog = new JDialog((JFrame) SwingUtilities.getWindowAncestor(importButton), "请选择下载路径", true);
dialog.setLayout(null);
// 创建标签
selectUploadLabel.setBounds(35, 40, 110, 25);
dialog.add(selectUploadLabel);
// 创建输入框
uploadInput.setBounds(140, 40, 150, 25);
dialog.add(uploadInput);
// 创建选择按钮
importButton.setBounds(305, 40, 90, 25);
importButton.addActionListener(e -> {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
// fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
// fileChooser.setMultiSelectionEnabled(false);
fileChooser.setAcceptAllFileFilterUsed(false); // 不显示 "所有文件" 选项
// FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel Files", "xlsx", "xls");
// fileChooser.setFileFilter(filter);
// 设置默认打开的文件夹为桌面
File desktopDir = new File(System.getProperty("user.home"), "Desktop");
fileChooser.setCurrentDirectory(desktopDir);
int result = fileChooser.showOpenDialog(dialog);
if (result == JFileChooser.APPROVE_OPTION) {
((JTextField) uploadInput).setText(fileChooser.getSelectedFile().getAbsolutePath());
}
});
dialog.add(importButton, BorderLayout.EAST);
okButton.addActionListener(e -> {
String path = ((JTextField) uploadInput).getText();
if (path.isEmpty()) {
JOptionPane.showMessageDialog(dialog, "请选择文件下载位置");
} else {
// 检查文件是否为目录
File file = new File(path);
if (file.exists()) {
// 处理上传逻辑
doTask(file);
dialog.dispose();
}
}
});
celButton.addActionListener(e -> {
dialog.dispose();
});
// 创建确定和取消按钮
okButton.setBounds(90, 90, 100, 25);
celButton.setBounds(210, 90, 100, 25);
dialog.add(okButton);
dialog.add(celButton);
// 设置对话框大小和位置
dialog.pack();
dialog.setSize(440, 190);
// 获取 importButton 的祖先窗口
Window ancestor = SwingUtilities.getWindowAncestor(importButton);
if (ancestor instanceof JFrame) {
dialog.setLocationRelativeTo((JFrame) ancestor);
} else {
// 如果祖先不是 JFrame可以选择居中显示在屏幕中央
dialog.setLocationRelativeTo(null);
}
dialog.setVisible(true);
}
public void doTask(File file) {
System.out.println("fileName : " + file.getName());
String absolutePath = file.getAbsolutePath();
System.out.println(propList1);
System.out.println(propList2);
System.out.println(propList3);
try {
if (propList1 != null) {
ExcelWriteTable1.generateFromTemplateStructure(absolutePath + "\\技术工艺【图纸】发放回收记录表.xlsx",
propList1);
}
if (propList2 != null) {
ExcelWriteTable2.generateFromTemplateStructure(absolutePath + "\\技术工艺【变更】发放回收记录表.xlsx",
propList2);
}
if (propList3 != null) {
ExcelWriteTable3.generateFromTemplateStructure(absolutePath + "\\【试制工作联系单】发放回收记录.xlsx",
propList3);
}
List<String> filePaths = new ArrayList<String>();
for (TCComponentItemRevision rev : relationRevs) {
String itemId = rev.getStringProperty("item_id");
String itemRevId = rev.getStringProperty("item_revision_id");
String name = rev.getStringProperty("object_name");
TCComponent[] components = rev.getRelatedComponents("IMAN_specification");
for (TCComponent tcComponent : components) {
if(tcComponent instanceof TCComponentDataset) {
String type = tcComponent.getType();
System.out.println("type : "+type);
if(type.toLowerCase().equals("pdf")) {
String downLoadExcel = downLoadExcel((TCComponentDataset)tcComponent,absolutePath);
StringBuffer newFileName = new StringBuffer("");
newFileName.append(itemId);
newFileName.append("_");
newFileName.append(itemRevId);
newFileName.append("_");
newFileName.append(name);
newFileName.append("_");
newFileName.append(downLoadExcel.substring(downLoadExcel.lastIndexOf("\\")+1));
File renameFile = renameFile(downLoadExcel,newFileName.toString());
downLoadExcel = renameFile.getAbsolutePath();
System.out.println("download path : " + downLoadExcel);
filePaths.add(downLoadExcel);
}
}
}
}
for (String path : filePaths) {
SignPDF.sign(path, addSignSuffix(path));
// deleteFileIfExists(path);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
/**
*
*
* @param oldFilePath "D:/test/123.pdf"
* @param newFileName "123_sign.pdf"
* @return null
*/
public static File renameFile(String oldFilePath, String newFileName) {
File oldFile = new File(oldFilePath);
if (!oldFile.exists()) {
System.out.println("原文件不存在: " + oldFilePath);
return null;
}
// 获取父目录路径
String parentDir = oldFile.getParent();
// 构建新文件对象
File newFile = new File(parentDir, newFileName);
// 如果目标文件已存在,则删除
if (newFile.exists()) {
if (newFile.delete()) {
System.out.println("已删除旧的目标文件: " + newFile.getAbsolutePath());
} else {
System.out.println("无法删除旧的目标文件: " + newFile.getAbsolutePath());
return null;
}
}
// 重命名文件
if (oldFile.renameTo(newFile)) {
System.out.println("文件重命名为: " + newFile.getAbsolutePath());
return newFile;
} else {
System.out.println("文件重命名失败: " + oldFile.getAbsolutePath());
return null;
}
}
public static void deleteFileIfExists(String filePath) {
File file = new File(filePath);
if (file.exists()) {
if (file.delete()) {
System.out.println("文件已成功删除: " + filePath);
} else {
System.out.println("无法删除文件: " + filePath);
}
} else {
System.out.println("文件不存在,无需处理: " + filePath);
}
}
public static String addSignSuffix(String fileName) {
if (fileName == null || fileName.isEmpty()) {
return fileName;
}
int dotIndex = fileName.lastIndexOf(".");
if (dotIndex == -1 || dotIndex == 0 || dotIndex == fileName.length() - 1) {
// 没有有效扩展名,直接追加 _sign
return fileName + "_sign";
}
String namePart = fileName.substring(0, dotIndex);
String extensionPart = fileName.substring(dotIndex);
return namePart + "_sign" + extensionPart;
}
public String downLoadExcel(TCComponentDataset dataset,String path) {
try {
String refs = dataset.getProperty("ref_names");
String[] ref = refs.split(",");
File file = dataset.getFiles(ref[0], path)[0];
String templateFilePath = file.getAbsolutePath();
// 获取到本地文件的绝对路径templateFilePath
System.out.println("filePath: " + templateFilePath);
return templateFilePath;
} catch (TCException e) {
e.printStackTrace();
}
return "";
}
@Override
public void run() {
// TODO Auto-generated method stub
initUi();
}
}

@ -0,0 +1,127 @@
package cn.net.connor.plm.entity;
/**
* @ClassName Prop
* @Description TODO
* @Author chenzc
* @Date 2025/5/9 11:58
**/
public class Prop {
//从1开始自动增加步长为1
private String sNo;
// B
private String fileName;
// C
private String productName;
// D
private String productDrawingNum;
// E
private String drawingStatus;
// F
private String drawingRevision;
// G
private String compiler;
// O
private String drawingDate;
// P
private String relationFileNo;
public Prop(String sNo, String fileName, String productName, String productDrawingNum, String drawingStatus, String drawingRevision, String compiler, String drawingDate, String relationFileNo) {
this.sNo = sNo;
this.fileName = fileName;
this.productName = productName;
this.productDrawingNum = productDrawingNum;
this.drawingStatus = drawingStatus;
this.drawingRevision = drawingRevision;
this.compiler = compiler;
this.drawingDate = drawingDate;
this.relationFileNo = relationFileNo;
}
public String getsNo() {
return sNo;
}
public void setsNo(String sNo) {
this.sNo = sNo;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductDrawingNum() {
return productDrawingNum;
}
public void setProductDrawingNum(String productDrawingNum) {
this.productDrawingNum = productDrawingNum;
}
public String getDrawingStatus() {
return drawingStatus;
}
public void setDrawingStatus(String drawingStatus) {
this.drawingStatus = drawingStatus;
}
public String getDrawingRevision() {
return drawingRevision;
}
public void setDrawingRevision(String drawingRevision) {
this.drawingRevision = drawingRevision;
}
public String getCompiler() {
return compiler;
}
public void setCompiler(String compiler) {
this.compiler = compiler;
}
public String getDrawingDate() {
return drawingDate;
}
public void setDrawingDate(String drawingDate) {
this.drawingDate = drawingDate;
}
public String getRelationFileNo() {
return relationFileNo;
}
public void setRelationFileNo(String relationFileNo) {
this.relationFileNo = relationFileNo;
}
@Override
public String toString() {
return "Prop{" +
"sNo='" + sNo + '\'' +
", fileName='" + fileName + '\'' +
", productName='" + productName + '\'' +
", productDrawingNum='" + productDrawingNum + '\'' +
", drawingStatus='" + drawingStatus + '\'' +
", drawingRevision='" + drawingRevision + '\'' +
", compiler='" + compiler + '\'' +
", drawingDate='" + drawingDate + '\'' +
", relationFileNo='" + relationFileNo + '\'' +
'}';
}
}

@ -0,0 +1,173 @@
package cn.net.connor.plm.handlers;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import cn.net.connor.plm.dialogs.DataAllocationHandlerDialog;
import cn.net.connor.plm.entity.Prop;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.util.MessageBox;
public class DataAllocationHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
// TODO Auto-generated method stub
AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
TCComponent rev = (TCComponent) app.getTargetComponent();
try {
TCComponent[] components = rev.getRelatedComponents("SB6_XGWJ");
String[] type1 = { "SB6_CatiaDesignXRevision", "SB6_AutocadDXRevision", "SB6_CatiaAssDXRevision",
"SB6_CatiaSDXRevision", "SB6_AutocadAssDXRevision", "SB6_AutocadSDXRevision",
"SB6_CatiaDesignLRevision", "SB6_AutocadDLRevision", "SB6_CatiaAssDLRevision",
"SB6_CatiaSDLRevision", "SB6_AutocadAssDLRevision", "SB6_AutocadSDLRevision" };
String type3 = "SB6_SZLXDRevisionMaster";
String[] prop1 = { "object_name", "item_id", "item_revision_id" };
String[] prop3 = { "sb6_SZRM01", "sb6_SZRM02", "sb6_SZRM03", "sb6_SZRM04"};
// 获取当前本地日期和时间
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd");
String localTime = now.format(formatter);
System.out.println("localTime : "+ localTime);
List<Prop> propList1 = new ArrayList<>();
List<Prop> propList2 = new ArrayList<>();
List<Prop> propList3 = new ArrayList<>();
List<TCComponentItemRevision> relationRevs = new ArrayList<TCComponentItemRevision>();
for (int i = 0; i < components.length; i++) {
if (components[i] instanceof TCComponentItemRevision) {
TCComponentItemRevision tcComponent = (TCComponentItemRevision) components[i];
TCComponent[] components1 = tcComponent.getRelatedComponents("release_status_list");
if (components1 == null || components1.length == 0) {
MessageBox.post("存在未发布版本对象", "Error", MessageBox.ERROR);
return null;
}
String type = tcComponent.getType();
System.out.println("type : "+ type);
boolean flag1 = false;
for (String tempType : type1) {
if (type.equals(tempType)) {
flag1 = true;
break;
}
}
TCComponent form = tcComponent.getRelatedComponent("IMAN_master_form_rev");
String itemId = tcComponent.getStringProperty("item_id");
TCComponent owningUeserRelation = tcComponent.getRelatedComponent("owning_user");
String ownerUser = owningUeserRelation.getStringProperty("user_name");
if (ownerUser.contains("(")) {
ownerUser = ownerUser.substring(0, ownerUser.indexOf("("));
}
int cnt = 0;
if (flag1) {
relationRevs.add(tcComponent);
String[] properties = tcComponent.getProperties(prop1);
String property1 = form.getStringProperty("sb6_ifls");
if(property1 != null) {
if (property1.equals("是")) {
property1 = "临时";
} else if (property1.equals("否")) {
property1 = "正式";
} else {
System.out.println("null");
}
}else {
System.out.println("sb6_ifls属性为空");
}
String property2 = form.getStringProperty("sb6_relatedfileno");
propList1.add(new Prop("", "图纸", properties[cnt++], properties[cnt++], property1,
properties[cnt++], ownerUser, localTime, property2));
continue;
}
if (type.equals("ChangeNoticeRevision")) {
relationRevs.add(tcComponent);
String[] properties = form.getProperties(new String[] { "sb6_CNRM05", "sb6_CNRM05" });
TCComponent[] tempGx = tcComponent.getRelatedComponents("CMSolutionItems");
String itemIds = getItemId(tempGx);
String status = getDrawingStatu(tempGx);
propList2.add(new Prop("", "技术文件更改通知单", properties[cnt++], properties[cnt++], itemIds, status,
ownerUser, localTime, itemId));
} else if (type.equals("SB6_JSWTLSCLTZDRevision")) {
relationRevs.add(tcComponent);
String[] properties = form.getProperties(new String[] { "sb6_LSRM05", "sb6_LSRM05" });
TCComponent[] tempGx = tcComponent.getRelatedComponents("SB6_LSSJRelation");
String itemIds = getItemId(tempGx);
String status = getDrawingStatu(tempGx);
propList2.add(new Prop("", "临时问题处理通知单", properties[cnt++], properties[cnt++], itemIds, status,
ownerUser, localTime, itemId));
}
if (type3.equals(type)) {
relationRevs.add(tcComponent);
String[] properties = form.getProperties(prop3);
propList3.add(new Prop("", "样件试制/试生产联系单", properties[cnt++], properties[cnt++], properties[cnt++],properties[cnt++],
ownerUser, localTime, itemId));
}
}
}
DataAllocationHandlerDialog cmbd = new DataAllocationHandlerDialog(app,propList1,propList2,propList3,relationRevs);
new Thread(cmbd).start();
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public String getItemId(TCComponent[] tempGx) throws TCException {
StringBuffer str = new StringBuffer();
for (int i = 0; i < tempGx.length; i++) {
TCComponent tcComponent = tempGx[i];
str.append(tcComponent.getStringProperty("item_id"));
if (i != tempGx.length - 1) {
str.append("\n");
}
}
return str.toString();
}
public String getDrawingStatu(TCComponent[] tempGx) throws TCException {
StringBuffer str = new StringBuffer();
for (int i = 0; i < tempGx.length; i++) {
TCComponent tcComponent = tempGx[i];
TCComponent form = tcComponent.getRelatedComponent("IMAN_master_form_rev");
String ifls = form.getStringProperty("sb6_ifls");
if (ifls.equals("是")) {
ifls = "临时" + tcComponent.getStringProperty("item_revision_id");
} else if (ifls.equals("否")) {
ifls = "正式" + tcComponent.getStringProperty("item_revision_id");
} else {
System.out.println("getDrawingStatu null");
}
System.out.println("ifls : " + ifls);
str.append(ifls);
if (i != tempGx.length - 1 || !ifls.isEmpty()) {
str.append("\n");
}
}
return str.toString();
}
}

@ -0,0 +1,284 @@
package cn.net.connor.plm.util;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import cn.net.connor.plm.entity.Prop;
public class ExcelWriteTable1 {
public static void main(String[] args) throws Exception {
List<Prop> props = new ArrayList<>();
props.add(new Prop("图纸", "减速箱壳体", "123",
"正式", "A", "test1", "2024.4.18", "TCN_1", "TCN_2"));
props.add(new Prop("图纸", "减速箱壳体", "123",
"正式", "A", "test1", "2024.4.18", "TCN_1", "TCN_2"));
props.add(new Prop("1", "2", "3", "4", "5", "6", "7", "8", "9"));
ExcelWriteTable1.generateFromTemplateStructure(
"C:\\Users\\Administrator\\Desktop\\test\\generated_file.xlsx",
props
);
}
public static void generateFromTemplateStructure(String outputPath, List<Prop> props) throws Exception {
try (Workbook workbook = new HSSFWorkbook()) {
Sheet sheet = workbook.createSheet("sheet1");
// ====================== 创建固定表头 ======================
createHeader(workbook, sheet);
// ====================== 创建数据区域 ======================
int rowNum = 2; // 数据起始行(第三行)
for (int i = 0; i < props.size(); i++) {
Prop prop = props.get(i);
// 创建四行数据(合并行)
Row row1 = sheet.createRow(rowNum++);
Row row2 = sheet.createRow(rowNum++);
Row row3 = sheet.createRow(rowNum++);
Row row4 = sheet.createRow(rowNum++);
// 设置行高为 16.8 磅336 单位)
row1.setHeight((short) 336);
row2.setHeight((short) 336);
row3.setHeight((short) 336);
row4.setHeight((short) 336);
// 设置行高为 16.8 磅336 单位)
row1.setHeight((short) 336);
row2.setHeight((short) 336);
// ====================== 填充动态数据 ======================
fillDynamicData(workbook, row1, prop, i + 1);
setRow2Style(workbook, row2);
setRow2Style(workbook, row3);
setRow2Style(workbook, row4);
// ====================== 创建固定模板内容 ======================
createFixedContent(workbook, row1, row2, row3, row4);
// ====================== 设置合并区域 ======================
addMergedRegions(sheet, row1, row2, row3, row4);
}
// ====================== 自动调整列宽 ======================
autoSizeColumns(sheet);
// 保存文件
try (FileOutputStream fos = new FileOutputStream(outputPath)) {
workbook.write(fos);
}
}
}
private static void setRow2Style(Workbook workbook, Row row2) {
CellStyle dataStyle = createDataStyle(workbook);
for (int i = 0; i < 8; i++) {
Cell cell = row2.createCell(i);
cell.setCellStyle(dataStyle);
}
for (int i = 14; i < 18; i++) {
Cell cell = row2.createCell(i);
cell.setCellStyle(dataStyle);
}
}
private static void createHeader(Workbook workbook, Sheet sheet) {
// 第一行标题
Row titleRow = sheet.createRow(0);
titleRow.setHeight((short) 436);
Cell titleCell = titleRow.createCell(0);
titleCell.setCellValue("\u6280\u672F/\u5DE5\u827A\u3010\u56FE\u7EB8\u3011\u53D1\u653E\u3001\u56DE\u6536\u8BB0\u5F55\u8868");
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 17));
// 创建带实线边框的标题样式
CellStyle headerStyle = workbook.createCellStyle();
Font titleFont = workbook.createFont();
titleFont.setBold(true);
titleFont.setFontHeightInPoints((short) 14);
headerStyle.setFont(titleFont);
headerStyle.setAlignment(HorizontalAlignment.CENTER);
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
// 设置实线边框
headerStyle.setBorderTop(BorderStyle.THIN);
headerStyle.setBorderBottom(BorderStyle.THIN);
headerStyle.setBorderLeft(BorderStyle.THIN);
headerStyle.setBorderRight(BorderStyle.THIN);
// 应用样式到合并后的标题单元格
titleCell.setCellStyle(headerStyle);
// 单独创建第二行表头的样式
CellStyle secondHeaderStyle = workbook.createCellStyle();
Font secondHeaderFont = workbook.createFont();
secondHeaderFont.setBold(true);
secondHeaderFont.setFontHeightInPoints((short) 10);
secondHeaderStyle.setFont(secondHeaderFont);
secondHeaderStyle.setAlignment(HorizontalAlignment.CENTER);
secondHeaderStyle.setVerticalAlignment(VerticalAlignment.CENTER);
secondHeaderStyle.setWrapText(true); // 允许换行
// 设置实线边框
secondHeaderStyle.setBorderTop(BorderStyle.THIN);
secondHeaderStyle.setBorderBottom(BorderStyle.THIN);
secondHeaderStyle.setBorderLeft(BorderStyle.THIN);
secondHeaderStyle.setBorderRight(BorderStyle.THIN);
// 第二行表头
Row headerRow = sheet.createRow(1);
headerRow.setHeight((short) 556);
String[] headers = {"\u5E8F\u53F7", "\u6587\u4EF6\u540D\u79F0", "\u4EA7\u54C1/\u96F6\u90E8\u4EF6\u540D\u79F0", "\u4EA7\u54C1/\u96F6\u90E8\u4EF6\u56FE\u53F7",
"\u56FE\u7EB8\u72B6\u6001", "\u56FE\u7EB8\u7248\u672C", "\u7F16\u5236\u4EBA", "\u9875\u6570", "\u2714 \u7B7E\u6536\u90E8\u95E8",
"", "", "", "", "", "\u7B7E\u6536\u65E5\u671F", "\u76F8\u5173\u6587\u4EF6\u7F16\u53F7", "\u5907\u6CE8", ""};
for (int i = 0; i < headers.length; i++) {
Cell cell = headerRow.createCell(i);
cell.setCellValue(headers[i]);
cell.setCellStyle(secondHeaderStyle);
}
sheet.addMergedRegion(new CellRangeAddress(1, 1, 8, 13));
sheet.addMergedRegion(new CellRangeAddress(1, 1, 16, 17));
}
private static void fillDynamicData(Workbook workbook, Row row, Prop prop, int serialNumber) {
CellStyle dataStyle = createDataStyle(workbook);
// 序号A列
createStyledCell(row, 0, String.valueOf(serialNumber), dataStyle);
// 动态字段
createStyledCell(row, 1, prop.getFileName(), dataStyle);
createStyledCell(row, 2, prop.getProductName(), dataStyle);
createStyledCell(row, 3, prop.getProductDrawingNum(), dataStyle);
createStyledCell(row, 4, prop.getDrawingStatus(), dataStyle);
createStyledCell(row, 5, prop.getDrawingRevision(), dataStyle);
createStyledCell(row, 6, prop.getCompiler(), dataStyle);
createStyledCell(row, 14, prop.getDrawingDate(), dataStyle); // O列
createStyledCell(row, 15, prop.getRelationFileNo(), dataStyle); // P列
}
private static void createFixedContent(Workbook workbook, Row row1, Row row2, Row row3, Row row4) {
CellStyle fixedStyle = createFixedStyle(workbook);
CellStyle dataStyle = createDataStyle(workbook);
// H列固定内容合并单元格
createStyledCell(row1, 7, "1", dataStyle);
// I-N列固定模板
// I-N列固定模板按行分配
String[][] fixedRows = {
{"", "\u91C7\u8D2D\u90E8:", "", "PMC\u90E8:", "", "\u751F\u4EA7\u90E8:"},
{"", "\u5DE5\u827A\u90E8:", "", "\u8D28\u4FDD\u90E8\uFF1A", "", "SQE:"},
{"", "\u56FD\u96451\u90E8:", "", "\u56FD\u96452\u90E8:", "", "\u9500\u552E:"},
{"", "\u96F6\u552E:", "", "\u8BD5\u9A8C\u5BA4:", "", "\u7EFC\u7BA1:"}
};
int colIndex = 8; // I列开始
for (int i = 0; i < fixedRows.length; i++) {
Row currentRow = null;
switch (i) {
case 0:
currentRow = row1;
break;
case 1:
currentRow = row2;
break;
case 2:
currentRow = row3;
break;
case 3:
currentRow = row4;
break;
}
if (currentRow != null) {
for (int j = 0; j < fixedRows[i].length; j++) {
createStyledCell(currentRow, colIndex + j, fixedRows[i][j], fixedStyle);
}
}
}
// Q-R列固定内容
createStyledCell(row1, 16, "\u56DE\u65362023.4.26\uFF0CS6\u7248", dataStyle);
createStyledCell(row1, 17, "\u25A1", dataStyle);
}
private static void addMergedRegions(Sheet sheet, Row row1, Row row2, Row row3, Row row4) {
int startRow = row1.getRowNum();
int endRow = row4.getRowNum();
// 合并 A-H 列(索引 0-7
for (int i = 0; i < 8; i++) {
sheet.addMergedRegion(new CellRangeAddress(
startRow,
endRow,
i,
i
));
}
// 合并 O-R 列(索引 14-17
for (int i = 14; i < 18; i++) {
sheet.addMergedRegion(new CellRangeAddress(
startRow,
endRow,
i,
i
));
}
}
private static CellStyle createFixedStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
return style;
}
private static CellStyle createDataStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
Font dataFont = workbook.createFont();
dataFont.setFontHeightInPoints((short) 10);
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFont(dataFont);
return style;
}
private static void createStyledCell(Row row, int column, String value, CellStyle style) {
Cell cell = row.createCell(column);
cell.setCellValue(value);
cell.setCellStyle(style);
}
private static void autoSizeColumns(Sheet sheet) {
for (int i = 0; i < 18; i++) {
if (i == 8 || i == 10 || i == 12) {
sheet.setColumnWidth(i, 5 * 256);
} else if(i == 16 ){
sheet.setColumnWidth(i, 20 * 256);
} else {
sheet.setColumnWidth(i, 12 * 256);
}
}
}
}

@ -0,0 +1,259 @@
package cn.net.connor.plm.util;
import java.io.FileOutputStream;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import cn.net.connor.plm.entity.Prop;
public class ExcelWriteTable2 {
public static void generateFromTemplateStructure(String outputPath, List<Prop> props) throws Exception {
try (Workbook workbook = new HSSFWorkbook()) {
Sheet sheet = workbook.createSheet("sheet1");
// ====================== 创建固定表头 ======================
createHeader(workbook, sheet);
// ====================== 创建数据区域 ======================
int rowNum = 2; // 数据起始行(第三行)
for (int i = 0; i < props.size(); i++) {
Prop prop = props.get(i);
// 创建四行数据(合并行)
Row row1 = sheet.createRow(rowNum++);
Row row2 = sheet.createRow(rowNum++);
Row row3 = sheet.createRow(rowNum++);
Row row4 = sheet.createRow(rowNum++);
// 设置行高为 16.8 磅336 单位)
row1.setHeight((short) 336);
row2.setHeight((short) 336);
row3.setHeight((short) 336);
row4.setHeight((short) 336);
// 设置行高为 16.8 磅336 单位)
row1.setHeight((short) 336);
row2.setHeight((short) 336);
// ====================== 填充动态数据 ======================
fillDynamicData(workbook, row1, prop, i + 1);
setRow2Style(workbook, row2);
setRow2Style(workbook, row3);
setRow2Style(workbook, row4);
// ====================== 创建固定模板内容 ======================
createFixedContent(workbook, row1, row2, row3, row4);
// ====================== 设置合并区域 ======================
addMergedRegions(sheet, row1, row2, row3, row4);
}
// ====================== 自动调整列宽 ======================
autoSizeColumns(sheet);
// 保存文件
try (FileOutputStream fos = new FileOutputStream(outputPath)) {
workbook.write(fos);
}
}
}
private static void setRow2Style(Workbook workbook, Row row2) {
CellStyle dataStyle = createDataStyle(workbook);
for (int i = 0; i < 8; i++) {
Cell cell = row2.createCell(i);
cell.setCellStyle(dataStyle);
}
for (int i = 14; i < 18; i++) {
Cell cell = row2.createCell(i);
cell.setCellStyle(dataStyle);
}
}
private static void createHeader(Workbook workbook, Sheet sheet) {
// 第一行标题
Row titleRow = sheet.createRow(0);
titleRow.setHeight((short) 436);
Cell titleCell = titleRow.createCell(0);
titleCell.setCellValue(
"\u6280\u672F/\u5DE5\u827A\u3010\u53D8\u66F4\u3011\u53D1\u653E\u3001\u56DE\u6536\u8BB0\u5F55\u8868");
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 17));
// 创建带实线边框的标题样式
CellStyle headerStyle = workbook.createCellStyle();
Font titleFont = workbook.createFont();
titleFont.setBold(true);
titleFont.setFontHeightInPoints((short) 14);
headerStyle.setFont(titleFont);
headerStyle.setAlignment(HorizontalAlignment.CENTER);
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
// 设置实线边框
headerStyle.setBorderTop(BorderStyle.THIN);
headerStyle.setBorderBottom(BorderStyle.THIN);
headerStyle.setBorderLeft(BorderStyle.THIN);
headerStyle.setBorderRight(BorderStyle.THIN);
// 应用样式到合并后的标题单元格
titleCell.setCellStyle(headerStyle);
// 单独创建第二行表头的样式
CellStyle secondHeaderStyle = workbook.createCellStyle();
Font secondHeaderFont = workbook.createFont();
secondHeaderFont.setBold(true);
secondHeaderFont.setFontHeightInPoints((short) 10);
secondHeaderStyle.setFont(secondHeaderFont);
secondHeaderStyle.setAlignment(HorizontalAlignment.CENTER);
secondHeaderStyle.setVerticalAlignment(VerticalAlignment.CENTER);
secondHeaderStyle.setWrapText(true); // 允许换行
// 设置实线边框
secondHeaderStyle.setBorderTop(BorderStyle.THIN);
secondHeaderStyle.setBorderBottom(BorderStyle.THIN);
secondHeaderStyle.setBorderLeft(BorderStyle.THIN);
secondHeaderStyle.setBorderRight(BorderStyle.THIN);
// 第二行表头
Row headerRow = sheet.createRow(1);
headerRow.setHeight((short) 556);
String[] headers = { "\u5E8F\u53F7", "\u6587\u4EF6\u540D\u79F0", "\u4EA7\u54C1/\u96F6\u90E8\u4EF6\u540D\u79F0",
"\u4EA7\u54C1/\u96F6\u90E8\u4EF6\u56FE\u53F7", "\u540C\u65F6\u4E0B\u53D1\u56FE\u7EB8",
"\u56FE\u7EB8\u72B6\u6001/\u7248\u672C", "\u7F16\u5236\u4EBA", "\u9875\u6570",
"\u2714 \u7B7E\u6536\u90E8\u95E8", "", "", "", "", "", "\u7B7E\u6536\u65E5\u671F",
"\u6587\u4EF6\u7F16\u53F7", "\u5907\u6CE8", "" };
for (int i = 0; i < headers.length; i++) {
Cell cell = headerRow.createCell(i);
cell.setCellValue(headers[i]);
cell.setCellStyle(secondHeaderStyle);
}
sheet.addMergedRegion(new CellRangeAddress(1, 1, 8, 13));
sheet.addMergedRegion(new CellRangeAddress(1, 1, 16, 17));
}
private static void fillDynamicData(Workbook workbook, Row row, Prop prop, int serialNumber) {
CellStyle dataStyle = createDataStyle(workbook);
// 序号A列
createStyledCell(row, 0, String.valueOf(serialNumber), dataStyle);
// 动态字段
createStyledCell(row, 1, prop.getFileName(), dataStyle);
createStyledCell(row, 2, prop.getProductName(), dataStyle);
createStyledCell(row, 3, prop.getProductDrawingNum(), dataStyle);
createStyledCell(row, 4, prop.getDrawingStatus(), dataStyle);
createStyledCell(row, 5, prop.getDrawingRevision(), dataStyle);
createStyledCell(row, 6, prop.getCompiler(), dataStyle);
createStyledCell(row, 14, prop.getDrawingDate(), dataStyle); // O列
createStyledCell(row, 15, prop.getRelationFileNo(), dataStyle); // P列
}
private static void createFixedContent(Workbook workbook, Row row1, Row row2, Row row3, Row row4) {
CellStyle fixedStyle = createFixedStyle(workbook);
CellStyle dataStyle = createDataStyle(workbook);
// H列固定内容合并单元格
createStyledCell(row1, 7, "1", dataStyle);
// I-N列固定模板
// I-N列固定模板按行分配
String[][] fixedRows = { { "", "\u91C7\u8D2D\u90E8:", "", "PMC\u90E8:", "", "\u751F\u4EA7\u90E8:" },
{ "", "\u5DE5\u827A\u90E8:", "", "\u8D28\u4FDD\u90E8\uFF1A", "", "SQE:" },
{ "", "\u56FD\u96451\u90E8:", "", "\u56FD\u96452\u90E8:", "", "\u9500\u552E:" },
{ "", "\u96F6\u552E:", "", "\u8BD5\u9A8C\u5BA4:", "", "\u7EFC\u7BA1:" } };
int colIndex = 8; // I列开始
for (int i = 0; i < fixedRows.length; i++) {
Row currentRow = null;
switch (i) {
case 0:
currentRow = row1;
break;
case 1:
currentRow = row2;
break;
case 2:
currentRow = row3;
break;
case 3:
currentRow = row4;
break;
}
if (currentRow != null) {
for (int j = 0; j < fixedRows[i].length; j++) {
createStyledCell(currentRow, colIndex + j, fixedRows[i][j], fixedStyle);
}
}
}
// Q-R列固定内容
createStyledCell(row1, 16, "", dataStyle);
createStyledCell(row1, 17, "", dataStyle);
}
private static void addMergedRegions(Sheet sheet, Row row1, Row row2, Row row3, Row row4) {
int startRow = row1.getRowNum();
int endRow = row4.getRowNum();
// 合并 A-H 列(索引 0-7
for (int i = 0; i < 8; i++) {
sheet.addMergedRegion(new CellRangeAddress(startRow, endRow, i, i));
}
// 合并 O-R 列(索引 14-15
for (int i = 14; i < 16; i++) {
sheet.addMergedRegion(new CellRangeAddress(startRow, endRow, i, i));
}
sheet.addMergedRegion(new CellRangeAddress(startRow, endRow, 16, 17));
}
private static CellStyle createFixedStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
return style;
}
private static CellStyle createDataStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
Font dataFont = workbook.createFont();
dataFont.setFontHeightInPoints((short) 10);
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFont(dataFont);
return style;
}
private static void createStyledCell(Row row, int column, String value, CellStyle style) {
Cell cell = row.createCell(column);
cell.setCellValue(value);
cell.setCellStyle(style);
}
private static void autoSizeColumns(Sheet sheet) {
for (int i = 0; i < 18; i++) {
if (i == 8 || i == 10 || i == 12) {
sheet.setColumnWidth(i, 5 * 256);
} else {
sheet.setColumnWidth(i, 10 * 256);
}
}
}
}

@ -0,0 +1,277 @@
package cn.net.connor.plm.util;
import java.io.FileOutputStream;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import cn.net.connor.plm.entity.Prop;
public class ExcelWriteTable3 {
public static void generateFromTemplateStructure(String outputPath, List<Prop> props) throws Exception {
try (Workbook workbook = new HSSFWorkbook()) {
Sheet sheet = workbook.createSheet("sheet1");
// ====================== 创建固定表头 ======================
createHeader(workbook, sheet);
// ====================== 创建数据区域 ======================
int rowNum = 2; // 数据起始行(第三行)
for (int i = 0; i < props.size(); i++) {
Prop prop = props.get(i);
// 创建四行数据(合并行)
Row row1 = sheet.createRow(rowNum++);
Row row2 = sheet.createRow(rowNum++);
Row row3 = sheet.createRow(rowNum++);
Row row4 = sheet.createRow(rowNum++);
// 设置行高为 16.8 磅336 单位)
row1.setHeight((short) 336);
row2.setHeight((short) 336);
row3.setHeight((short) 336);
row4.setHeight((short) 336);
// 设置行高为 16.8 磅336 单位)
row1.setHeight((short) 336);
row2.setHeight((short) 336);
// ====================== 填充动态数据 ======================
fillDynamicData(workbook, row1, prop, i + 1);
setRow2Style(workbook, row2);
setRow2Style(workbook, row3);
setRow2Style(workbook, row4);
// ====================== 创建固定模板内容 ======================
createFixedContent(workbook, row1, row2, row3, row4);
// ====================== 设置合并区域 ======================
addMergedRegions(sheet, row1, row2, row3, row4);
}
// ====================== 自动调整列宽 ======================
autoSizeColumns(sheet);
// 保存文件
try (FileOutputStream fos = new FileOutputStream(outputPath)) {
workbook.write(fos);
}
}
}
private static void setRow2Style(Workbook workbook,Row row2) {
CellStyle dataStyle = createDataStyle(workbook);
for (int i = 0; i < 8; i++) {
Cell cell = row2.createCell(i);
cell.setCellStyle(dataStyle);
}
for (int i = 14; i < 18; i++) {
Cell cell = row2.createCell(i);
cell.setCellStyle(dataStyle);
}
}
private static void createHeader(Workbook workbook, Sheet sheet) {
// 第一行标题
Row titleRow = sheet.createRow(0);
titleRow.setHeight((short) 436);
Cell titleCell = titleRow.createCell(0);
titleCell.setCellValue("\u3010\u8BD5\u5236/\u5DE5\u4F5C\u8054\u7CFB\u5355\u3011\u53D1\u653E\u3001\u56DE\u6536\u8BB0\u5F55");
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 17));
// 创建带实线边框的标题样式
CellStyle headerStyle = workbook.createCellStyle();
Font titleFont = workbook.createFont();
titleFont.setBold(true);
titleFont.setFontHeightInPoints((short) 14);
headerStyle.setFont(titleFont);
headerStyle.setAlignment(HorizontalAlignment.CENTER);
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
// 设置实线边框
headerStyle.setBorderTop(BorderStyle.THIN);
headerStyle.setBorderBottom(BorderStyle.THIN);
headerStyle.setBorderLeft(BorderStyle.THIN);
headerStyle.setBorderRight(BorderStyle.THIN);
// 应用样式到合并后的标题单元格
titleCell.setCellStyle(headerStyle);
// 单独创建第二行表头的样式
CellStyle secondHeaderStyle = workbook.createCellStyle();
Font secondHeaderFont = workbook.createFont();
secondHeaderFont.setBold(true);
secondHeaderFont.setFontHeightInPoints((short) 10);
secondHeaderStyle.setFont(secondHeaderFont);
secondHeaderStyle.setAlignment(HorizontalAlignment.CENTER);
secondHeaderStyle.setVerticalAlignment(VerticalAlignment.CENTER);
secondHeaderStyle.setWrapText(true); // 允许换行
// 设置实线边框
secondHeaderStyle.setBorderTop(BorderStyle.THIN);
secondHeaderStyle.setBorderBottom(BorderStyle.THIN);
secondHeaderStyle.setBorderLeft(BorderStyle.THIN);
secondHeaderStyle.setBorderRight(BorderStyle.THIN);
// 第二行表头
Row headerRow = sheet.createRow(1);
headerRow.setHeight((short) 556);
String[] headers = {"\u5E8F\u53F7", "\u6587\u4EF6\u540D\u79F0", "\u4EA7\u54C1/\u96F6\u90E8\u4EF6\u540D\u79F0", "\u4EA7\u54C1/\u96F6\u90E8\u4EF6\u56FE\u53F7",
"\u5B8C\u6210\u65F6\u95F4", "\u8BD5\u5236\u6570\u91CF", "\u7F16\u5236\u4EBA", "\u9875\u6570", "\u2714 \u7B7E\u6536\u4EBA\uFF08\u4EFD\u6570\uFF09",
"", "", "", "", "", "\u7B7E\u6536\u65E5\u671F", "\u6587\u4EF6\u7F16\u53F7", "\u5907\u6CE8", ""};
for (int i = 0; i < headers.length; i++) {
Cell cell = headerRow.createCell(i);
cell.setCellValue(headers[i]);
cell.setCellStyle(secondHeaderStyle);
}
sheet.addMergedRegion(new CellRangeAddress(1, 1, 8, 13));
sheet.addMergedRegion(new CellRangeAddress(1, 1, 16, 17));
}
private static void fillDynamicData(Workbook workbook, Row row, Prop prop, int serialNumber) {
CellStyle dataStyle = createDataStyle(workbook);
// 序号A列
createStyledCell(row, 0, String.valueOf(serialNumber), dataStyle);
// 动态字段
createStyledCell(row, 1, prop.getFileName(), dataStyle);
createStyledCell(row, 2, prop.getProductName(), dataStyle);
createStyledCell(row, 3, prop.getProductDrawingNum(), dataStyle);
createStyledCell(row, 4, prop.getDrawingStatus(), dataStyle);
createStyledCell(row, 5, prop.getDrawingRevision(), dataStyle);
createStyledCell(row, 6, prop.getCompiler(), dataStyle);
createStyledCell(row, 14, prop.getDrawingDate(), dataStyle); // O列
createStyledCell(row, 15, prop.getRelationFileNo(), dataStyle); // P列
}
private static void createFixedContent(Workbook workbook, Row row1, Row row2, Row row3, Row row4) {
CellStyle fixedStyle = createFixedStyle(workbook);
CellStyle dataStyle = createDataStyle(workbook);
// H列固定内容合并单元格
createStyledCell(row1, 7, "1", dataStyle);
// I-N列固定模板
// I-N列固定模板按行分配
String[][] fixedRows = {
{"", "\u91C7\u8D2D\u90E8:", "", "PMC\u90E8:", "", "\u751F\u4EA7\u90E8:"},
{"", "\u5DE5\u827A\u90E8:", "", "\u8D28\u4FDD\u90E8\uFF1A", "", "SQE:"},
{"", "\u56FD\u96451\u90E8:", "", "\u56FD\u96452\u90E8:", "", "\u9500\u552E:"},
{"", "\u96F6\u552E:", "", "\u8BD5\u9A8C\u5BA4:", "", "\u7EFC\u7BA1:"}
};
int colIndex = 8; // I列开始
for (int i = 0; i < fixedRows.length; i++) {
Row currentRow = null;
switch (i) {
case 0:
currentRow = row1;
break;
case 1:
currentRow = row2;
break;
case 2:
currentRow = row3;
break;
case 3:
currentRow = row4;
break;
}
if (currentRow != null) {
for (int j = 0; j < fixedRows[i].length; j++) {
createStyledCell(currentRow, colIndex + j, fixedRows[i][j], fixedStyle);
}
}
}
// Q-R列固定内容
createStyledCell(row1, 16, "", dataStyle);
createStyledCell(row1, 17, "", dataStyle);
}
private static void addMergedRegions(Sheet sheet, Row row1, Row row2, Row row3, Row row4) {
int startRow = row1.getRowNum();
int endRow = row4.getRowNum();
// 合并 A-H 列(索引 0-7
for (int i = 0; i < 8; i++) {
sheet.addMergedRegion(new CellRangeAddress(
startRow,
endRow,
i,
i
));
}
// 合并 O-R 列(索引 14-15
for (int i = 14; i < 16; i++) {
sheet.addMergedRegion(new CellRangeAddress(
startRow,
endRow,
i,
i
));
}
sheet.addMergedRegion(new CellRangeAddress(
startRow,
endRow,
16,
17
));
}
private static CellStyle createFixedStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
return style;
}
private static CellStyle createDataStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
Font dataFont = workbook.createFont();
dataFont.setFontHeightInPoints((short) 10);
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFont(dataFont);
return style;
}
private static void createStyledCell(Row row, int column, String value, CellStyle style) {
Cell cell = row.createCell(column);
cell.setCellValue(value);
cell.setCellStyle(style);
}
private static void autoSizeColumns(Sheet sheet) {
for (int i = 0; i < 18; i++) {
if(i ==8 || i ==10 || i==12){
sheet.setColumnWidth(i,5 * 256);
}else{
sheet.setColumnWidth(i, 10 * 256);
}
}
}
}

@ -0,0 +1,277 @@
package cn.net.connor.plm.util;
import java.io.File;
import java.io.FileOutputStream;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfGState;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
public class SignPDF {
public static void main(String[] args) {
String pdfUrl = "C:\\测试用例\\ECN2.pdf";
String newPdfUrl = "C:\\测试用例\\ECN_2.pdf";
String dateSign = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd"));
try {
PdfReader reader = new PdfReader(pdfUrl);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(newPdfUrl));
Rectangle rectangle = reader.getPageSize(1);
Float[] fposition = getSize(rectangle);
float x1 = 0.0F;
float y1 = 0.0F;
if (fposition[0] == 2384.0 && fposition[1] == 3370.0F) { // A0
System.out.println("A0");
x1 = 2718.42F;
y1 = 28.3F;
} else if (fposition[0] == 2384.0F && fposition[1] == 1684.0F) { // A1
System.out.println("A1");
x1 = 1731.9F;
y1 = 28.3F;
} else if (fposition[0] == 1684.0F && fposition[1] == 1191.0F) { // A2
System.out.println("A2");
x1 = 1031.8F;
y1 = 28.3F;
} else if (fposition[0] == 1191.0F && fposition[1] == 842.0F) { // A3
System.out.println("A3");
x1 = 552.7F;
y1 = 14.1F;
} else if (fposition[0] == 842.0F && fposition[1] == 595.0F) { // A4
System.out.println("A4");
x1 = 714.3F;
y1 = 467.7F;
} else if (fposition[0] == 3370.4F && fposition[1] == 2383.94F) { // CATIA A0
System.out.println("CATIA A0");
x1 = 2718.4F;
y1 = 28.3F;
} else if (fposition[0] == 2383.94F && fposition[1] == 1683.78F) { // CATIA A1
System.out.println("CATIA A1");
x1 = 1731.9F;
y1 = 28.3F;
} else if (fposition[0] == 1683.78F && fposition[1] == 1190.56F) { // CATIA A2
System.out.println("CATIA A2");
x1 = 1031.8F;
y1 = 28.3F;
} else if (fposition[0] == 1190.56F && fposition[1] == 841.89F) { // CATIA A3
System.out.println("CATIA A3");
x1 = 552.7F;
y1 = 14.1F;
} else if (fposition[0] == 595.28F && fposition[1] == 841.89F) { // CATIA A4
System.out.println("CATIA A4");
x1 = 467.7F;
y1 = 714.3F;
} else if (fposition[0] == 5054.18F && fposition[1] == 2383.94F) { // CATIA S0 A0
System.out.println("CATIA S0 A0");
x1 = 4402.2F;
y1 = 28.3F;
} else if (fposition[0] == 6740.79F && fposition[1] == 2383.94F) { // CATIA S0 A1
System.out.println("CATIA S0 A1");
x1 = 6088.8F;
y1 = 28.3F;
} else if (fposition[0] == 8424.57F && fposition[1] == 2383.94F) { // CATIA S0 A2
System.out.println("CATIA S0 A2");
x1 = 7772.6F;
y1 = 28.3F;
} else if (fposition[0] == 10111.19F && fposition[1] == 2383.94F) { // CATIA S0 A3
System.out.println("CATIA S0 A3");
x1 = 9459.2F;
y1 = 28.3F;
} else if (fposition[0] == 11794.97F && fposition[1] == 2383.94F) { // CATIA S0 A4
System.out.println("CATIA S0 A4");
x1 = 11143F;
y1 = 28.3F;
} else if (fposition[0] == 595.0F && fposition[1] == 842.0F) { // A4
System.out.println("-A4");
x1 = 467.7F;
y1 = 714.3F;
}
if (fposition[0] == 841.92F && fposition[1] == 595.32F) { // A4
System.out.println("技术文件变更通知单");
dateSign = "文档发放日期:" + dateSign;
System.out.println(dateSign);
x1 += 701;
y1 += 570;
}else if(fposition[0] == 595.32F && fposition[1] == 841.92F) { // A4
System.out.println("技术文件变更通知单");
dateSign = "文档发放日期:" + dateSign;
System.out.println(dateSign);
x1 += 454;
y1 += 821;
}else{
x1 += 33;
y1 += 15;
}
System.out.println("当前盖章x1坐标:" + x1);
System.out.println("当前盖章y1坐标:" + y1);
String getenv = System.getenv("TC_ROOT");
getenv += "\\simsun.ttf";
System.out.println(getenv);
PdfContentByte under = stamper.getOverContent(1);
PdfGState fontState = new PdfGState();
under.setGState(fontState);
under.saveState();
// 2. 插入时间字符串formattedTime2
// 定义字体Times New Roman常规小四红色
BaseFont baseFont = BaseFont.createFont(getenv, // Times New Roman 字体文件路径
BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
under.beginText();
under.setFontAndSize(baseFont, 10);
under.setColorFill(new BaseColor(225, 0, 0));
under.setTextMatrix(x1, y1);
under.showText(dateSign);
under.endText();
under.restoreState();
stamper.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void sign(String pdfUrl, String newPdfUrl) {
String dateSign = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd"));
try {
PdfReader reader = new PdfReader(pdfUrl);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(newPdfUrl));
Rectangle rectangle = reader.getPageSize(1);
Float[] fposition = getSize(rectangle);
float x1 = 0.0F;
float y1 = 0.0F;
if (fposition[0] == 2384.0 && fposition[1] == 3370.0F) { // A0
System.out.println("A0");
x1 = 2718.42F;
y1 = 28.3F;
} else if (fposition[0] == 2384.0F && fposition[1] == 1684.0F) { // A1
System.out.println("A1");
x1 = 1731.9F;
y1 = 28.3F;
} else if (fposition[0] == 1684.0F && fposition[1] == 1191.0F) { // A2
System.out.println("A2");
x1 = 1031.8F;
y1 = 28.3F;
} else if (fposition[0] == 1191.0F && fposition[1] == 842.0F) { // A3
System.out.println("A3");
x1 = 552.7F;
y1 = 14.1F;
} else if (fposition[0] == 842.0F && fposition[1] == 595.0F) { // A4
System.out.println("A4");
x1 = 714.3F;
y1 = 467.7F;
} else if (fposition[0] == 3370.4F && fposition[1] == 2383.94F) { // CATIA A0
System.out.println("CATIA A0");
x1 = 2718.4F;
y1 = 28.3F;
} else if (fposition[0] == 2383.94F && fposition[1] == 1683.78F) { // CATIA A1
System.out.println("CATIA A1");
x1 = 1731.9F;
y1 = 28.3F;
} else if (fposition[0] == 1683.78F && fposition[1] == 1190.56F) { // CATIA A2
System.out.println("CATIA A2");
x1 = 1031.8F;
y1 = 28.3F;
} else if (fposition[0] == 1190.56F && fposition[1] == 841.89F) { // CATIA A3
System.out.println("CATIA A3");
x1 = 552.7F;
y1 = 14.1F;
} else if (fposition[0] == 595.28F && fposition[1] == 841.89F) { // CATIA A4
System.out.println("CATIA A4");
x1 = 467.7F;
y1 = 714.3F;
} else if (fposition[0] == 5054.18F && fposition[1] == 2383.94F) { // CATIA S0 A0
System.out.println("CATIA S0 A0");
x1 = 4402.2F;
y1 = 28.3F;
} else if (fposition[0] == 6740.79F && fposition[1] == 2383.94F) { // CATIA S0 A1
System.out.println("CATIA S0 A1");
x1 = 6088.8F;
y1 = 28.3F;
} else if (fposition[0] == 8424.57F && fposition[1] == 2383.94F) { // CATIA S0 A2
System.out.println("CATIA S0 A2");
x1 = 7772.6F;
y1 = 28.3F;
} else if (fposition[0] == 10111.19F && fposition[1] == 2383.94F) { // CATIA S0 A3
System.out.println("CATIA S0 A3");
x1 = 9459.2F;
y1 = 28.3F;
} else if (fposition[0] == 11794.97F && fposition[1] == 2383.94F) { // CATIA S0 A4
System.out.println("CATIA S0 A4");
x1 = 11143F;
y1 = 28.3F;
} else if (fposition[0] == 595.0F && fposition[1] == 842.0F) { // A4
System.out.println("-A4");
x1 = 467.7F;
y1 = 714.3F;
}
if (fposition[0] == 841.92F && fposition[1] == 595.32F) { // A4
System.out.println("技术文件变更通知单");
dateSign = "文档发放日期:" + dateSign;
System.out.println(dateSign);
x1 += 701;
y1 += 570;
}else if(fposition[0] == 595.32F && fposition[1] == 841.92F) { // A4
System.out.println("技术文件变更通知单");
dateSign = "文档发放日期:" + dateSign;
System.out.println(dateSign);
x1 += 454;
y1 += 821;
}else{
x1 += 33;
y1 += 15;
}
System.out.println("当前盖章x1坐标:" + x1);
System.out.println("当前盖章y1坐标:" + y1);
String getenv = System.getenv("TC_ROOT");
getenv += "\\bin\\simsun.ttf";
System.out.println(getenv);
PdfContentByte under = stamper.getOverContent(1);
PdfGState fontState = new PdfGState();
under.setGState(fontState);
under.saveState();
// 2. 插入时间字符串formattedTime2
// 定义字体Times New Roman常规小四红色
BaseFont baseFont = BaseFont.createFont(getenv, // Times New Roman 字体文件路径
BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
under.beginText();
under.setFontAndSize(baseFont, 10);
under.setColorFill(new BaseColor(225, 0, 0));
under.setTextMatrix(x1, y1);
under.showText(dateSign);
under.endText();
under.restoreState();
stamper.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static Float[] getSize(Rectangle rectangle) {
Float[] sizef = new Float[2];
float toleft = rectangle.getLeft();
float tobottom = rectangle.getBottom();
float toright = rectangle.getRight();
float totop = rectangle.getTop();
sizef[0] = (Float.valueOf(toright - toleft));
sizef[1] = (Float.valueOf(totop - tobottom));
System.out.println("bean.getH------------>................." + sizef[0]);
System.out.println("bean.getW------------>................." + sizef[1]);
return sizef;
}
}

@ -0,0 +1,43 @@
package cn.net.connor.test;
public class Colconfig {
private String name;
private String age;
private String code;
public Colconfig(String name, String age, String code) {
super();
this.name = name;
this.age = age;
this.code = code;
}
public Colconfig() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}

@ -0,0 +1,45 @@
package cn.net.connor.test;
import javafx.beans.property.SimpleStringProperty;
public class Data {
private SimpleStringProperty name = new SimpleStringProperty();
private SimpleStringProperty age = new SimpleStringProperty();
private SimpleStringProperty code = new SimpleStringProperty();
public Data() {
super();
}
public Data(String name, String age, String code) {
super();
this.name.set(name);
this.age.set(age);
this.code.set(code);
}
public SimpleStringProperty getName() {
return name;
}
public void setName(SimpleStringProperty name) {
this.name = name;
}
public SimpleStringProperty getAge() {
return age;
}
public void setAge(SimpleStringProperty age) {
this.age = age;
}
public SimpleStringProperty getCode() {
return code;
}
public void setCode(SimpleStringProperty code) {
this.code = code;
}
}

@ -0,0 +1,79 @@
package cn.net.connor.test;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.ComboBoxTableCell;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.util.Callback;
@SuppressWarnings("all")
public class Main extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage stage) {
StackPane root = new StackPane();
ObservableList<String> list = FXCollections.observableArrayList();
list.add("One");
list.add("Two");
list.add("Three");
list.add("Four");
TableColumn name = new TableColumn("Name");
TableColumn age = new TableColumn("age");
TableColumn code = new TableColumn("code");
name.setCellValueFactory(new PropertyValueFactory<Colconfig, String>("name"));
name.setCellFactory(ComboBoxTableCell.forTableColumn(list));
age.setCellValueFactory(new PropertyValueFactory<Colconfig, String>("age"));
age.setCellFactory(TextFieldTableCell.forTableColumn());
code.setCellValueFactory(new PropertyValueFactory<Colconfig, String>("code"));
code.setCellFactory(TextFieldTableCell.forTableColumn());
name.setOnEditCommit(new EventHandler<Event>() {
@Override
public void handle(Event arg0) {
}
});
ObservableList<Colconfig> datas = FXCollections.observableArrayList();
datas.add(new Colconfig("A", "12", "1212"));
datas.add(new Colconfig("B", "13", "1313"));
datas.add(new Colconfig("C", "14", "1414"));
TableView table = new TableView(datas);
table.setEditable(true);
table.getColumns().addAll(name, age, code);
root.getChildren().add(table);
Scene scene = new Scene(root, 300, 250);
stage.setTitle("Test");
stage.setScene(scene);
stage.show();
}
}

@ -0,0 +1,75 @@
package cn.net.connor.test;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TitledPane;
import javafx.scene.control.cell.ComboBoxTableCell;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main2 extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage stage) {
VBox vBox = new VBox();
Scene scene = new Scene(vBox, 500, 250);
ObservableList<String> list = FXCollections.observableArrayList();
list.add("One");
list.add("Two");
list.add("Three");
list.add("Four");
for (int i = 0; i < 3; i++) {
ObservableList<Colconfig> datas = FXCollections.observableArrayList();
datas.add(new Colconfig("A", "12", "1212"));
datas.add(new Colconfig("B", "13", "1313"));
datas.add(new Colconfig("C", "14", "1414"));
TableColumn<Colconfig, String> name = new TableColumn<>("Name");
TableColumn<Colconfig, String> age = new TableColumn<>("Age");
TableColumn<Colconfig, String> code = new TableColumn<>("Code");
name.setCellValueFactory(new PropertyValueFactory<Colconfig, String>("name"));
name.setCellFactory(ComboBoxTableCell.forTableColumn(list));
age.setCellValueFactory(new PropertyValueFactory<Colconfig, String>("age"));
age.setCellFactory(TextFieldTableCell.forTableColumn());
code.setCellValueFactory(new PropertyValueFactory<Colconfig, String>("code"));
code.setCellFactory(TextFieldTableCell.forTableColumn());
TableView<Colconfig> table = new TableView<>(datas);
name.setEditable(false);
table.setEditable(true);
table.getColumns().addAll(name, age, code);
TitledPane titledPane = new TitledPane("AutocadSDX" + i, table);
titledPane.setMaxHeight(500);
titledPane.setMinHeight(230);
titledPane.expandedProperty().addListener((observable, wasExpanded, isExpanded) -> {
titledPane.setMaxHeight(isExpanded ? 500 : 0);
titledPane.setMinHeight(isExpanded ? 230 : Region.USE_PREF_SIZE);
});
titledPane.setAnimated(false);
VBox.setVgrow(titledPane, Priority.ALWAYS);
vBox.getChildren().add(titledPane);
}
stage.setScene(scene);
stage.show();
}
}

@ -0,0 +1,56 @@
package cn.net.connor.test;
public class PartBean {
private String id;
private String uom;
private String material;
private String weight;
public PartBean() {
super();
}
public PartBean(String id, String uom, String material, String weight) {
super();
this.id = id;
this.uom = uom;
this.material = material;
this.weight = weight;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUom() {
return uom;
}
public void setUom(String uom) {
this.uom = uom;
}
public String getMaterial() {
return material;
}
public void setMaterial(String material) {
this.material = material;
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
}
}

@ -0,0 +1,37 @@
package cn.net.connor.test;
import java.util.ArrayList;
import java.util.List;
public class Test {
public List<Inner> inners;
public Test() {
inners = new ArrayList<Test.Inner>();
Inner inner = new Inner(true, "A");
Inner inner2 = new Inner(true, "A");
;
inners.add(inner);
inners.add(inner2);
System.out.println(inner);
System.out.println(inner2);
System.out.println(inner == inner2);
}
public static class Inner {
public boolean flag;
public String name;
public Inner(boolean flag, String name) {
super();
this.flag = flag;
this.name = name;
}
}
public static void main(String[] args) {
new Test();
}
}

@ -0,0 +1,256 @@
package com.connor.dfl.plm.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import com.teamcenter.rac.util.MessageBox;
public class DataBaseControl {
/** ************************数据库类调用:声明部分*********************************** */
/**
* kelsen ....
*/
Connection conn;
ResultSet rs;
PreparedStatement pstmt;
Statement stmt;
String strSQLQuery;
public String str_Information = "";
private String strDriver = "oracle.jdbc.driver.OracleDriver";
private String strUrl = "jdbc:oracle:thin:@localhost:1521:tc12";
// private String strUrl = "jdbc:oracle:thin:@192.168.3.22:1521:tc12";
private String strUserName = "infodba";
private String strPassword = "infodba";
public DataBaseControl(String strDriver, String strUrl, String strUserName, String strPassword) {
this.strDriver = strDriver;
this.strUrl = strUrl;
this.strUserName = strUserName;
this.strPassword = strPassword;
try {
Class.forName(strDriver);
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
}
/**
* 2
*/
public ResultSet dbQuery2(String strSQLQuery, Object[] strs) {
ResultSet rs_result = null;
if (conn == null)
openDataBase();
try {
// stmt = conn.createStatement();
PreparedStatement ps = conn.prepareStatement(strSQLQuery);
for (int i = 0; i < strs.length; i++) {
ps.setObject(i + 1, strs[i]);
}
rs_result = ps.executeQuery();
} catch (SQLException sqle2) {
sqle2.printStackTrace();
}
return rs_result;
}
/**
* 2
*/
public void dbModify2(String strSQLQuery, Object[] strs) {
try {
PreparedStatement ps = conn.prepareStatement(strSQLQuery);
for (int i = 0; i < strs.length; i++) {
ps.setObject(i + 1, strs[i]);
}
ps.executeUpdate();
} catch (SQLException sqle2) {
sqle2.printStackTrace();
}
}
/**
*
*
*/
public void openDataBase() {
try {
if (conn == null || conn.isClosed()) {
conn = DriverManager.getConnection(this.strUrl, this.strUserName, this.strPassword);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
*
*/
public void closeDataBase() {
try {
if (rs != null) {
try {
rs.close();
} catch (SQLException sqlec) {
sqlec.printStackTrace();
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException sqlec) {
sqlec.printStackTrace();
}
}
if (conn != null && !conn.isClosed()) {
try {
conn.close();
} catch (SQLException sqlecon) {
sqlecon.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
*
*
* @param type
* @param prefix
* @param col 4"0000"
* @return
* @throws Exception
*/
public String getNewCode(String type, String col) throws Exception {
openDataBase();
String lshstr = "";
if (col != null && !"".equals(col)) {
lshstr = col;
} else {
lshstr = "00000000000";
}
openDataBase();
// 根据图纸类型查询 前缀 流水码
String query = "select TYPE,PREFIX,LSH from XINSHIBAO where TYPE= ?";
String query2 = "select LSH from XINSHIBAO where PREFIX = ? ";
String query3 = "select LSH from XINSHIBAO where PREFIX = ? and LSH is not null order by LSH DESC";
ResultSet rs = dbQuery2(query, new Object[] { type });
if (rs.next()) {
String t = rs.getString(1);
String pre = rs.getString(2);
String lsh = rs.getString(3);
if (pre == null || "".equals(pre) || "null".equals(pre)) {
return "该新世宝未分配前缀无法构建ERP编码";
}
ResultSet rs2 = dbQuery2(query2, new Object[] { pre });
boolean flag = rs2.next();
if (flag) {
lsh = rs2.getString(1);
if (lsh == null || "null".equals(lsh) || "".equals(lsh)) {
int temp = col.length() - pre.length();
lsh = pre;
while (temp > 0) {
lsh += "0";
temp--;
}
} else {
ResultSet rs3 = dbQuery2(query3, new Object[] { pre });
rs3.next();
lsh = rs3.getString(1);
}
}
long ls = Long.parseLong(lsh) + 1;// 新的流水码数
lshstr = ls + "";
String upin = "update XINSHIBAO set LSH = ? where TYPE = ? ";
dbModify2(upin, new Object[] { lshstr, t });
}
closeDataBase();
return lshstr;
}
public String getNewCode(String prefix, String min, String max) throws Exception {
openDataBase();
String lshstr = "";
String query = "SELECT LSH FROM SHIBAO_LSH WHERE PREFIX = ? AND LSHMIN = ?";
ResultSet rs = dbQuery2(query, new Object[] { prefix, min });
if (rs.next()) {
String lsh = rs.getString(1);
long parseLong = Long.parseLong(lsh) + 1;
if (parseLong > Long.parseLong(max)) {
return "";
}
lshstr = parseLong + "";
if (lshstr.length() < max.length()) {
int temp = max.length() - lshstr.length();
while (temp > 0) {
lshstr = "0" + lshstr;
temp--;
}
}
String update = "UPDATE SHIBAO_LSH SET LSH = ? WHERE PREFIX = ? AND LSHMIN = ?";
dbModify2(update, new Object[] { lshstr, prefix, min });
} else {
lshstr = min;
String update = "INSERT INTO SHIBAO_LSH(PREFIX,LSH,LSHMIN) VALUES(?,?,?)";
dbModify2(update, new Object[] { prefix, min, min });
}
closeDataBase();
return lshstr;
}
public static void main(String args[]) {
try {
// String strDriver = "oracle.jdbc.driver.OracleDriver";
// String strUrl = "jdbc:oracle:thin:@localhost:1521:tc12";
// String strUserName = "infodba";
// String strPassword = "infodba";
//
// DataBaseControl dbc = new DataBaseControl(strDriver, strUrl, strUserName, strPassword);
// dbc.openDataBase();
// String newid = dbc.getNewCode("1123456746", "01", "55");
// System.out.println(newid);
// dbc.closeDataBase();
// String min = "099";
// String max = "999";
// String lsh = "";
// long parseLong = Long.parseLong(min)+1;
// System.out.println(parseLong);
// lsh = parseLong + "";
// if (lsh.length() < max.length()) {
// int temp = max.length() - lsh.length();
// while (temp > 0) {
// lsh = "0" +lsh;
// temp--;
// }
// }
// System.out.println(lsh);
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,114 @@
<?xml version="1.0" encoding="GBK" ?>
<rules>
<rule id="B00" type="电动助力转向管柱带中间轴总成(管柱+中间轴+控制器)" ERP="3101" />
<rule id="B01" type="管柱+中间轴" ERP="null" />
<rule id="F00" type="转向器带拉杆总成" ERP="313203" />
<rule id="Z00" type="中间轴总成" ERP="313202" />
<rule id="K00" type="控制器总成" ERP="313204" />
<rule id="K01" type="控制器" ERP="313204" />
<rule id="M00" type="电机" ERP="1304" />
<rule id="C00" type="电动转向管柱带ECU总成管柱+控制器)" ERP="3102" />
<rule id="C01" type="EPS转向管柱总成管柱" ERP="313201" />
<rule id="C02" type="减速箱体及转向轴组件" ERP="220201" />
<rule id="C03" type="减速机构及传感器组件(机头)" ERP="220201" />
<rule id="C04" type="传感器外组件" ERP="220201" />
<rule id="C05" type="箱体组件" ERP="220201" />
<rule id="C06" type="蜗杆组件" ERP="220201" />
<rule id="C07" type="传感器内组件" ERP="220201" />
<rule id="C08" type="输入轴及扭杆组件" ERP="220201" />
<rule id="C09" type="输入轴B级扭杆组件" ERP="220201" />
<rule id="C10" type="输入轴B组件" ERP="220201" />
<rule id="C11" type="蜗轮轴组件" ERP="220201" />
<rule id="C12" type="蜗轮轴小组件" ERP="220202" />
<rule id="C13" type="管柱组件带转向轴组件" ERP="220202" />
<rule id="C14" type="转向轴组件" ERP="220101" />
<rule id="C15" type="管柱组件" ERP="220302" />
<rule id="C16" type="上管柱组件" ERP="220302" />
<rule id="C17" type="上管柱焊装组件" ERP="220302" />
<rule id="C18" type="上安装板焊接组件" ERP="220302" />
<rule id="C19" type="调节手柄组件" ERP="220302" />
<rule id="C20" type="下管柱组件" ERP="220302" />
<rule id="C21" type="下支架组件" ERP="220302" />
<rule id="C22" type="节叉组件" ERP="220103" />
<rule id="C23+" type="不在上述组件图号依次递加" ERP="null" />
<rule id="B00" type="电动助力转向器带拉杆总成" ERP="310300" />
<rule id="B01" type="电动转向器总成" ERP="220203" />
<rule id="C01" type="传动机构组件" ERP="220203" />
<rule id="C02" type="壳体组件" ERP="220203" />
<rule id="C03" type="传感器内组件" ERP="220101" />
<rule id="C04" type="传感器外组件" ERP="220101" />
<rule id="C05" type="齿轮组件" ERP="220101" />
<rule id="C06" type="蜗杆组件" ERP="220101" />
<rule id="C07" type="齿轮小组件" ERP="220101" />
<rule id="C08" type="输入轴组件" ERP="220202" />
<rule id="C09" type="传感器带护套组件" ERP="220202" />
<rule id="C09+" type="其他组件" ERP="null" />
<rule id="null" type="轴类" ERP="210100" />
<rule id="111" type="蜗轮轴" ERP="" />
<rule id="112" type="输入轴A输入轴" ERP="" />
<rule id="113" type="输入轴B" ERP="" />
<rule id="114" type="扭杆" ERP="" />
<rule id="115" type="转向轴" ERP="" />
<rule id="116" type="蜗杆" ERP="" />
<rule id="117" type="花键套" ERP="" />
<rule id="118" type="齿轮" ERP="" />
<rule id="119" type="齿条" ERP="" />
<rule id="11*" type="其余轴类" ERP="" />
<rule id="null" type="壳体类" ERP="210200" />
<rule id="211" type="减速箱体" ERP="" />
<rule id="212" type="端盖" ERP="" />
<rule id="213" type="壳体" ERP="" />
<rule id="214" type="壳体B" ERP="" />
<rule id="215" type="法兰盖" ERP="" />
<rule id="216" type="电机法兰" ERP="" />
<rule id="217" type="传感器壳体" ERP="" />
<rule id="21*" type="其余" ERP="" />
<rule id="null" type="钣金件及管柱类" ERP="110000" />
<rule id="311" type="上管柱" ERP="null" />
<rule id="312" type="下管柱" ERP="null" />
<rule id="321" type="组合开关支架" ERP="" />
<rule id="322" type="固定支架" ERP="" />
<rule id="323" type="上安装板" ERP="" />
<rule id="324" type="U型支架" ERP="" />
<rule id="325" type="调节手柄" ERP="" />
<rule id="326" type="固定板" ERP="" />
<rule id="327" type="下支架" ERP="" />
<rule id="328" type="控制器支架" ERP="" />
<rule id="32*" type="其余支架" ERP="" />
<rule id="" type="螺栓、螺母及螺柱类" ERP="130100" />
<rule id="41*" type="螺栓类" ERP="" />
<rule id="42*" type="螺母类" ERP="" />
<rule id="43*" type="螺柱类" ERP="" />
<rule id="44*" type="其余" ERP="" />
<rule id="" type="轴承类" ERP="130200" />
<rule id="51*" type="深沟球轴承" ERP="" />
<rule id="52*" type="滚针轴承" ERP="" />
<rule id="53*" type="滑动轴承" ERP="" />
<rule id="54*" type="其余轴承" ERP="" />
<rule id="61*" type="卡圈及挡圈类" ERP="130500" />
<rule id="71*" type="金属类" ERP="110000" />
<rule id="" type="橡胶及非金属类" ERP="130300" />
<rule id="81*" type="橡胶类" ERP="" />
<rule id="82*" type="拉脱块" ERP="" />
<rule id="83*" type="其余非金属类" ERP="" />
<rule id="" type="电子元器件类" ERP="130500" />
<rule id="911" type="导线" ERP="" />
<rule id="912" type="尼龙波纹管" ERP="" />
<rule id="913" type="接插件护套" ERP="" />
<rule id="914" type="接插件端子" ERP="" />
<rule id="915" type="集磁环屏蔽罩" ERP="" />
<rule id="91*" type="其余" ERP="" />
<rule id="S01" type="导磁环组件" ERP="" />
<rule id="S02" type="集磁环注塑件" ERP="" />
<rule id="S04" type="PCB板组件" ERP="" />
</rules>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/core-renderer.jar"/>
<classpathentry kind="lib" path="lib/iTextAsian.jar"/>
<classpathentry kind="lib" path="lib/iTextAsianCmaps.jar"/>
<classpathentry kind="lib" path="lib/itextpdf-5.0.6.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cn.net.connor.pdf.lao.image</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

@ -0,0 +1,435 @@
package com.connor.pdf;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
public class SignPdfLao {
public static void main(String[] args) {
int pageCount = 1;
SignPdfLao signPdf = new SignPdfLao();
String dataPath = args[0];
String pdfPath = args[1];
String outs = args[2];
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\老世宝PDF\\A4图纸模板.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\A4图纸模板.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\TC模板CATIAPDF\\SHIBAO_A4_页_1.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\SHIBAO_A4_页_1.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\TC模板CATIAPDF\\SHIBAO_SO_A4_页_1.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\SHIBAO_SO_A4_页_1.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\TC模板CATIAPDF\\AA.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\AA.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\TC模板CATIAPDF\\A4图纸模板.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\A4图纸模板.PDF";
Map<String, String> dataMap = signPdf.getData(dataPath);
try {
System.out.println("=====开始签字=====");
PdfReader reader = new PdfReader(pdfPath);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outs));
Rectangle rectangle = reader.getPageSize(1);
Float[] fposition = signPdf.getSize(rectangle);
BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", true);
float x1 = 0.0F;
float x2 = 0.0F;
float x3 = 0.0F;
float x4 = 0.0F;
float y1 = 0.0F;
float y2 = 0.0F;
float y3 = 0.0F;
float y4 = 0.0F;
if (fposition[0] == 2384.0F && fposition[1] == 3370.0F) { // A0
x1 = 2870.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 2900.0F;
x3 = 2971.0F;
x4 = 3003.0F;
} else if (fposition[0] == 2384.0F && fposition[1] == 1684.0F) { // A1
x1 = 1885.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1913.0F;
x3 = 1985.0F;
x4 = 2016.0F;
} else if (fposition[0] == 1684.0F && fposition[1] == 1191.0F) { // A2
x1 = 1183.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1214.0F;
x3 = 1285.0F;
x4 = 1316.0F;
} else if (fposition[0] == 1191.0F && fposition[1] == 842.0F) { // A3
x1 = 703.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 735.0F;
x3 = 805.0F;
x4 = 837.0F;
} else if (fposition[0] == 842.0F && fposition[1] == 595.0F) { // A4
x1 = 110.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 142.0F;
x3 = 213.0F;
x4 = 243.0F;
} else if (fposition[0] == 3370.4F && fposition[1] == 2383.94F) { // CATIA A0
x1 = 2870.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 2902.0F;
x3 = 2971.0F;
x4 = 3003.0F;
} else if (fposition[0] == 2383.94F && fposition[1] == 1683.78F) { // CATIA A1
x1 = 1885.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1914.0F;
x3 = 1986.0F;
x4 = 2017.0F;
} else if (fposition[0] == 1683.78F && fposition[1] == 1190.56F) { // CATIA A2
x1 = 1183.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1214.0F;
x3 = 1285.0F;
x4 = 1316.0F;
} else if (fposition[0] == 1190.56F && fposition[1] == 841.89F) { // CATIA A3
x1 = 703.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 735.0F;
x3 = 805.0F;
x4 = 837.0F;
} else if (fposition[0] == 595.28F && fposition[1] == 841.89F) { // CATIA A4
x1 = 110.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 142.0F;
x3 = 213.0F;
x4 = 243.0F;
} else if (fposition[0] == 5054.18F && fposition[1] == 2383.94F) { // CATIA S0 A0
x1 = 4554.0F;
y1 = 61.0F;
y2 = 47.0F;
y3 = 33.0F;
y4 = 19.0F;
x2 = 4585.5F;
x3 = 4585.5F;
x4 = 4585.5F;
} else if (fposition[0] == 6740.79F && fposition[1] == 2383.94F) { // CATIA S0 A1
x1 = 6240.0F;
y1 = 61.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 6272.0F;
x3 = 6272.0F;
x4 = 6272.0F;
} else if (fposition[0] == 8424.57F && fposition[1] == 2383.94F) { // CATIA S0 A2
x1 = 7925.0F;
y1 = 60.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 7957.0F;
x3 = 7957.0F;
x4 = 7957.0F;
} else if (fposition[0] == 10111.19F && fposition[1] == 2383.94F) { // CATIA S0 A3
x1 = 9614.0F;
y1 = 60.0F;
y2 = 46.0F;
y3 = 32.0F;
y4 = 18.0F;
x2 = 9643.0F;
x3 = 9643.0F;
x4 = 9643.0F;
} else if (fposition[0] == 11794.97F && fposition[1] == 2383.94F) { // CATIA S0 A4
x1 = 11295.0F;
y1 = 60.0F;
y2 = 46.0F;
y3 = 32.0F;
y4 = 18.0F;
x2 = 11327.0F;
x3 = 11327.0F;
x4 = 11327.0F;
} else if (fposition[0] == 1684.0F && fposition[1] == 2384.0F) { // A1
x1 = 1885.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1913.0F;
x3 = 1985.0F;
x4 = 2016.0F;
} else if (fposition[0] == 1191.0F && fposition[1] == 1684.0F) { // A2
x1 = 1183.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1214.0F;
x3 = 1285.0F;
x4 = 1316.0F;
} else if (fposition[0] == 842.0F && fposition[1] == 1191.0F) { // A3
x1 = 703.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 735.0F;
x3 = 805.0F;
x4 = 837.0F;
} else if (fposition[0] == 595.0F && fposition[1] == 842.0F) { // A4
x1 = 110.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 142.0F;
x3 = 213.0F;
x4 = 243.0F;
}
if (dataMap.containsKey("编制")) {
String value = (String) dataMap.get("编制");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y1).floatValue());
content.showText(value);
content.endText();
// signPdf.signBZ(pageCount, value, content, reader, stamper, Integer.valueOf(275));
}
if (dataMap.containsKey("校对")) {
String value = (String) dataMap.get("校对");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y2).floatValue());
content.showText(value);
content.endText();
// signPdf.signBZ(pageCount, value, content, reader, stamper, Integer.valueOf(476));
}
if (dataMap.containsKey("会签")) {
String value = (String) dataMap.get("会签");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y3).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("批准")) {
String value = (String) dataMap.get("批准");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y4).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("编制日期")) {
String value = (String) dataMap.get("编制日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 6.2F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y1).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("校对日期")) {
String value = (String) dataMap.get("校对日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 6.2F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y2).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("会签日期")) {
String value = (String) dataMap.get("会签日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 6.2F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y3).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("批准日期")) {
String value = (String) dataMap.get("批准日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 6.2F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y4).floatValue());
content.showText(value);
content.endText();
}
stamper.close();
reader.close();
System.out.println("=====签字结束=====");
} catch (Exception e) {
e.printStackTrace();
}
}
public Map<String, String> getData(String filePath) {
String lineTxt = "";
Map<String, String> dataMap = new HashMap<>();
try {
String encoding = "GBK";
File file = new File(filePath);
if ((file.isFile()) && (file.exists())) {
InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
lineTxt = bufferedReader.readLine();
System.out.println("linttxt=======" + lineTxt);
read.close();
} else {
System.out.println("找不到指定的文件");
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}
String[] dataList = null;
if ((lineTxt != null) && (lineTxt.length() > 0) && (lineTxt.split("\\|") != null))
dataList = lineTxt.split("\\|");
else {
dataList[0] = "";
}
for (int i = 0; i < dataList.length; i++) {
System.out.println("dataList=======" + dataList[i]);
String[] datas = null;
datas = dataList[i].split("=");
if ((datas != null) && (datas.length > 1)) {
dataMap.put(datas[0], datas[1]);
}
}
return dataMap;
}
public Float[] getSize(Rectangle rectangle) {
Float[] sizef = new Float[2];
float toleft = rectangle.getLeft();
float tobottom = rectangle.getBottom();
float toright = rectangle.getRight();
float totop = rectangle.getTop();
JFomPdfBean bean = new JFomPdfBean();
bean.setH(Float.valueOf(toright - toleft));
bean.setW(Float.valueOf(totop - tobottom));
sizef[0] = bean.getH();
sizef[1] = bean.getW();
System.out.println("bean.getH------------>................." + bean.getH());
System.out.println("bean.getW------------>................." + bean.getW());
return sizef;
}
public void signBZ(int pageCount, String value, PdfContentByte content, PdfReader reader, PdfStamper stamper,
Integer x) {
for (int i = 2; i <= pageCount; i++) {
int width = x.intValue();
SignPdfLao pdf = new SignPdfLao();
Rectangle rectangle = reader.getPageSize(i);
System.out.println("=========第" + i + "页=========");
Float[] fposition = pdf.getSize(rectangle);
try {
BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", true);
String[] values = value.split(" ");
if (values != null)
for (int j = 0; j < values.length; j++) {
content = stamper.getUnderContent(i);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 11.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(width).floatValue(), Float.valueOf(30.0F).floatValue());
content.showText(values[j]);
content.endText();
width += 63;
}
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

@ -0,0 +1,58 @@
if (fposition[0] == 2384.0 && fposition[1] == 3370.0F) { // A0
x1 = 3010.0F;
y1 = 220.0F;
} else if (fposition[0] == 2384.0F && fposition[1] == 1684.0F) { // A1
x1 = 2020.0F;
y1 = 220.0F;
} else if (fposition[0] == 1684.0F && fposition[1] == 1191.0F) { // A2
x1 = 1310.0F;
y1 = 220.0F;
} else if (fposition[0] == 1191.0F && fposition[1] == 842.0F) { // A3
x1 = 850.0F;
y1 = 200.0F;
} else if (fposition[0] == 842.0F && fposition[1] == 595.0F) { // A4
x1 = 250.0F;
y1 = 200.0F;
}else if (fposition[0] == 3370.4F && fposition[1] == 2383.94F) { // CATIA A0
x1 = 2870.0F;
y1 = 162.0F;
} else if (fposition[0] == 2383.94F && fposition[1] == 1683.78F) { // CATIA A1
x1 = 1885.0F;
y1 = 162.0F;
} else if (fposition[0] == 1683.78F && fposition[1] == 1190.56F) { // CATIA A2
x1 = 1183.0F;
y1 = 162.0F;
} else if (fposition[0] == 1190.56F && fposition[1] == 841.89F) { // CATIA A3
x1 = 703.0F;
y1 = 148.0F;
} else if (fposition[0] == 595.28F && fposition[1] == 841.89F) { // CATIA A4
x1 = 110.0F;
y1 = 148.0F;
} else if (fposition[0] == 5054.18F && fposition[1] == 2383.94F) { // CATIA S0 A0
x1 = 4554.0F;
y1 = 161.0F;
} else if (fposition[0] == 6740.79F && fposition[1] == 2383.94F) { // CATIA S0 A1
x1 = 6240.0F;
y1 = 161.0F;
} else if (fposition[0] == 8424.57F && fposition[1] == 2383.94F) { // CATIA S0 A2
x1 = 7925.0F;
y1 = 160.0F;
} else if (fposition[0] == 10111.19F && fposition[1] == 2383.94F) { // CATIA S0 A3
x1 = 9614.0F;
y1 = 160.0F;
} else if (fposition[0] == 11794.97F && fposition[1] == 2383.94F) { // CATIA S0 A4
x1 = 11295.0F;
y1 = 160.0F;
}else if (fposition[0] == 1684.0F && fposition[1] == 2384.0F) { // A1
x1 = 1885.0F;
y1 = 210.0F;
} else if (fposition[0] == 1191.0F && fposition[1] == 1684.0F) { // A2
x1 = 1183.0F;
y1 = 210.0F;
} else if (fposition[0] == 842.0F && fposition[1] == 1191.0F) { // A3
x1 = 703.0F;
y1 = 190.0F;
} else if (fposition[0] == 595.0F && fposition[1] == 842.0F) { // A4
x1 = 110.0F;
y1 = 190.0F;
}

@ -0,0 +1,435 @@
package com.connor.pdf;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
public class SignPdfLao {
public static void main(String[] args) {
int pageCount = 1;
SignPdfLao signPdf = new SignPdfLao();
String dataPath = args[0];
String pdfPath = args[1];
String outs = args[2];
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\老世宝PDF\\A4图纸模板.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\A4图纸模板.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\TC模板CATIAPDF\\SHIBAO_A4_页_1.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\SHIBAO_A4_页_1.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\TC模板CATIAPDF\\SHIBAO_SO_A4_页_1.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\SHIBAO_SO_A4_页_1.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\TC模板CATIAPDF\\AA.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\AA.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\TC模板CATIAPDF\\A4图纸模板.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\A4图纸模板.PDF";
Map<String, String> dataMap = signPdf.getData(dataPath);
try {
System.out.println("=====开始签字=====");
PdfReader reader = new PdfReader(pdfPath);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outs));
Rectangle rectangle = reader.getPageSize(1);
Float[] fposition = signPdf.getSize(rectangle);
BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", true);
float x1 = 0.0F;
float x2 = 0.0F;
float x3 = 0.0F;
float x4 = 0.0F;
float y1 = 0.0F;
float y2 = 0.0F;
float y3 = 0.0F;
float y4 = 0.0F;
if (fposition[0] == 2384.0F && fposition[1] == 3370.0F) { // A0
x1 = 2870.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 2900.0F;
x3 = 2971.0F;
x4 = 3003.0F;
} else if (fposition[0] == 2384.0F && fposition[1] == 1684.0F) { // A1
x1 = 1885.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1913.0F;
x3 = 1985.0F;
x4 = 2016.0F;
} else if (fposition[0] == 1684.0F && fposition[1] == 1191.0F) { // A2
x1 = 1183.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1214.0F;
x3 = 1285.0F;
x4 = 1316.0F;
} else if (fposition[0] == 1191.0F && fposition[1] == 842.0F) { // A3
x1 = 703.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 735.0F;
x3 = 805.0F;
x4 = 837.0F;
} else if (fposition[0] == 842.0F && fposition[1] == 595.0F) { // A4
x1 = 110.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 142.0F;
x3 = 213.0F;
x4 = 243.0F;
} else if (fposition[0] == 3370.4F && fposition[1] == 2383.94F) { // CATIA A0
x1 = 2870.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 2902.0F;
x3 = 2971.0F;
x4 = 3003.0F;
} else if (fposition[0] == 2383.94F && fposition[1] == 1683.78F) { // CATIA A1
x1 = 1885.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1914.0F;
x3 = 1986.0F;
x4 = 2017.0F;
} else if (fposition[0] == 1683.78F && fposition[1] == 1190.56F) { // CATIA A2
x1 = 1183.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1214.0F;
x3 = 1285.0F;
x4 = 1316.0F;
} else if (fposition[0] == 1190.56F && fposition[1] == 841.89F) { // CATIA A3
x1 = 703.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 735.0F;
x3 = 805.0F;
x4 = 837.0F;
} else if (fposition[0] == 595.28F && fposition[1] == 841.89F) { // CATIA A4
x1 = 110.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 142.0F;
x3 = 213.0F;
x4 = 243.0F;
} else if (fposition[0] == 5054.18F && fposition[1] == 2383.94F) { // CATIA S0 A0
x1 = 4554.0F;
y1 = 61.0F;
y2 = 47.0F;
y3 = 33.0F;
y4 = 19.0F;
x2 = 4585.5F;
x3 = 4585.5F;
x4 = 4585.5F;
} else if (fposition[0] == 6740.79F && fposition[1] == 2383.94F) { // CATIA S0 A1
x1 = 6240.0F;
y1 = 61.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 6272.0F;
x3 = 6272.0F;
x4 = 6272.0F;
} else if (fposition[0] == 8424.57F && fposition[1] == 2383.94F) { // CATIA S0 A2
x1 = 7925.0F;
y1 = 60.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 7957.0F;
x3 = 7957.0F;
x4 = 7957.0F;
} else if (fposition[0] == 10111.19F && fposition[1] == 2383.94F) { // CATIA S0 A3
x1 = 9614.0F;
y1 = 60.0F;
y2 = 46.0F;
y3 = 32.0F;
y4 = 18.0F;
x2 = 9643.0F;
x3 = 9643.0F;
x4 = 9643.0F;
} else if (fposition[0] == 11794.97F && fposition[1] == 2383.94F) { // CATIA S0 A4
x1 = 11295.0F;
y1 = 60.0F;
y2 = 46.0F;
y3 = 32.0F;
y4 = 18.0F;
x2 = 11327.0F;
x3 = 11327.0F;
x4 = 11327.0F;
} else if (fposition[0] == 1684.0F && fposition[1] == 2384.0F) { // A1
x1 = 1885.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1913.0F;
x3 = 1985.0F;
x4 = 2016.0F;
} else if (fposition[0] == 1191.0F && fposition[1] == 1684.0F) { // A2
x1 = 1183.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1214.0F;
x3 = 1285.0F;
x4 = 1316.0F;
} else if (fposition[0] == 842.0F && fposition[1] == 1191.0F) { // A3
x1 = 703.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 735.0F;
x3 = 805.0F;
x4 = 837.0F;
} else if (fposition[0] == 595.0F && fposition[1] == 842.0F) { // A4
x1 = 110.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 142.0F;
x3 = 213.0F;
x4 = 243.0F;
}
if (dataMap.containsKey("编制")) {
String value = (String) dataMap.get("编制");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y1).floatValue());
content.showText(value);
content.endText();
// signPdf.signBZ(pageCount, value, content, reader, stamper, Integer.valueOf(275));
}
if (dataMap.containsKey("校对")) {
String value = (String) dataMap.get("校对");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y2).floatValue());
content.showText(value);
content.endText();
// signPdf.signBZ(pageCount, value, content, reader, stamper, Integer.valueOf(476));
}
if (dataMap.containsKey("会签")) {
String value = (String) dataMap.get("会签");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y3).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("批准")) {
String value = (String) dataMap.get("批准");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y4).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("编制日期")) {
String value = (String) dataMap.get("编制日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 6.2F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y1).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("校对日期")) {
String value = (String) dataMap.get("校对日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 6.2F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y2).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("会签日期")) {
String value = (String) dataMap.get("会签日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 6.2F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y3).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("批准日期")) {
String value = (String) dataMap.get("批准日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 6.2F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y4).floatValue());
content.showText(value);
content.endText();
}
stamper.close();
reader.close();
System.out.println("=====签字结束=====");
} catch (Exception e) {
e.printStackTrace();
}
}
public Map<String, String> getData(String filePath) {
String lineTxt = "";
Map<String, String> dataMap = new HashMap<>();
try {
String encoding = "GBK";
File file = new File(filePath);
if ((file.isFile()) && (file.exists())) {
InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
lineTxt = bufferedReader.readLine();
System.out.println("linttxt=======" + lineTxt);
read.close();
} else {
System.out.println("找不到指定的文件");
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}
String[] dataList = null;
if ((lineTxt != null) && (lineTxt.length() > 0) && (lineTxt.split("\\|") != null))
dataList = lineTxt.split("\\|");
else {
dataList[0] = "";
}
for (int i = 0; i < dataList.length; i++) {
System.out.println("dataList=======" + dataList[i]);
String[] datas = null;
datas = dataList[i].split("=");
if ((datas != null) && (datas.length > 1)) {
dataMap.put(datas[0], datas[1]);
}
}
return dataMap;
}
public Float[] getSize(Rectangle rectangle) {
Float[] sizef = new Float[2];
float toleft = rectangle.getLeft();
float tobottom = rectangle.getBottom();
float toright = rectangle.getRight();
float totop = rectangle.getTop();
JFomPdfBean bean = new JFomPdfBean();
bean.setH(Float.valueOf(toright - toleft));
bean.setW(Float.valueOf(totop - tobottom));
sizef[0] = bean.getH();
sizef[1] = bean.getW();
System.out.println("bean.getH------------>................." + bean.getH());
System.out.println("bean.getW------------>................." + bean.getW());
return sizef;
}
public void signBZ(int pageCount, String value, PdfContentByte content, PdfReader reader, PdfStamper stamper,
Integer x) {
for (int i = 2; i <= pageCount; i++) {
int width = x.intValue();
SignPdfLao pdf = new SignPdfLao();
Rectangle rectangle = reader.getPageSize(i);
System.out.println("=========第" + i + "页=========");
Float[] fposition = pdf.getSize(rectangle);
try {
BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", true);
String[] values = value.split(" ");
if (values != null)
for (int j = 0; j < values.length; j++) {
content = stamper.getUnderContent(i);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 11.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(width).floatValue(), Float.valueOf(30.0F).floatValue());
content.showText(values[j]);
content.endText();
width += 63;
}
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

@ -0,0 +1,314 @@
package com.sgcc.test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Image;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfGState;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
/**
*
*
* @author wang
* @version 1.0.0
*/
public class StamperLao {
public static void main(String[] args) {
String pdfUrl = "C:\\测试用例\\A3图纸模板V4.0.PDF";
String newPdfUrl = "C:\\测试用例\\A3图纸模板V4.02.PDF";
String imageFile = "C:\\测试用例\\configsk.txt";
String dateSign = "2025-4-23";
String method = "sk".toLowerCase();
String isSignDate = "Y";
// String pdfUrl = args[0];
// String newPdfUrl = args[1];
// String imageFile = args[2];
// String dateSign = args[3];
// String method = args[4].toLowerCase();
// String isSignDate = args[5];
sign(pdfUrl, newPdfUrl, imageFile,dateSign, method, isSignDate);
}
public static void sign(String pdfUrl, String newPdfUrl, String imageFile, String dateSign,String method,String isSignDate) {
try {
String imageUrl = "";
FileReader fReader = new FileReader(imageFile);
char[] buf = new char[128];
int len;
while ((len = fReader.read(buf)) != -1) {
imageUrl= new String(buf, 0, len);
}
imageUrl = imageUrl.split("=")[1];
System.out.println(imageUrl);
System.out.println("imageUrl : " + imageUrl);
System.out.println("method : " + method);
PdfReader reader = new PdfReader(pdfUrl);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(newPdfUrl));
Rectangle rectangle = reader.getPageSize(1);
Float[] fposition = getSize(rectangle);
float x1 = 0.0F;
float y1 = 0.0F;
if (fposition[0] == 2384.0 && fposition[1] == 3370.0F) { // A0
System.out.println("A0");
if (method.equals("sk")) {
x1 = 2718.42F;
y1 = 28.3F;
} else{
x1 = 2718.42F;
y1 = 170.0F;
}
} else if (fposition[0] == 2384.0F && fposition[1] == 1684.0F) { // A1
System.out.println("A1");
if (method.equals("sk")) {
x1 = 1731.9F;
y1 = 28.3F;
} else {
x1 = 1731.9F;
y1 = 170.0F;
}
} else if (fposition[0] == 1684.0F && fposition[1] == 1191.0F) { // A2
System.out.println("A2");
if (method.equals("sk")) {
x1 = 1031.8F;
y1 = 28.3F;
} else {
x1 = 1031.8F;
y1 = 170.0F;
}
} else if (fposition[0] == 1191.0F && fposition[1] == 842.0F) { // A3
System.out.println("A3");
if (method.equals("sk")) {
x1 = 552.7F;
y1 = 14.1F;
} else {
x1 = 552.7F;
y1 = 155.9F;
}
} else if (fposition[0] == 842.0F && fposition[1] == 595.0F) { // A4
System.out.println("A4");
if (method.equals("sk")) {
x1 = 714.3F;
y1 = 467.7F;
} else {
x1 = 629.2F;
y1 = 467.7F;
}
} else if (fposition[0] == 3370.4F && fposition[1] == 2383.94F) { // CATIA A0
System.out.println("CATIA A0");
if (method.equals("sk")) {
x1 = 2718.4F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 2718.4F;
y1 = 170.0F;
}else {
x1 = 1628.5F;
y1 = 1163.6F;
}
} else if (fposition[0] == 2383.94F && fposition[1] == 1683.78F) { // CATIA A1
System.out.println("CATIA A1");
if (method.equals("sk")) {
x1 = 1731.9F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 1731.9F;
y1 = 170.0F;
}else {
x1 = 629.2F;
y1 = 813.5F;
}
} else if (fposition[0] == 1683.78F && fposition[1] == 1190.56F) { // CATIA A2
System.out.println("CATIA A2");
if (method.equals("sk")) {
x1 = 1031.8F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 1031.8F;
y1 = 170.0F;
}else {
x1 = 629.2F;
y1 = 566.9F;
}
} else if (fposition[0] == 1190.56F && fposition[1] == 841.89F) { // CATIA A3
System.out.println("CATIA A3");
if (method.equals("sk")) {
x1 = 552.7F;
y1 = 14.1F;
} else if(method.equals("ls")){
x1 = 552.7F;
y1 = 155.9F;
}else {
x1 = 538.6F;
y1 = 392.5F;
}
} else if (fposition[0] == 595.28F && fposition[1] == 841.89F) { // CATIA A4
System.out.println("CATIA A4");
if (method.equals("sk")) {
x1 = 467.7F;
y1 = 714.3F;
} else if(method.equals("ls")){
x1 = 467.7F;
y1 = 629.2F;
}else {
x1 = 240.9F;
y1 = 392.5F;
}
} else if (fposition[0] == 5054.18F && fposition[1] == 2383.94F) { // CATIA S0 A0
System.out.println("CATIA S0 A0");
if (method.equals("sk")) {
x1 = 4402.2F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 4402.2F;
y1 = 170.1F;
}else {
x1 = 2470.4F;
y1 = 1163.6F;
}
} else if (fposition[0] == 6740.79F && fposition[1] == 2383.94F) { // CATIA S0 A1
System.out.println("CATIA S0 A1");
if (method.equals("sk")) {
x1 = 6088.8F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 6088.8F;
y1 = 170.1F;
}else {
x1 = 3313.7F;
y1 = 1163.6F;
}
} else if (fposition[0] == 8424.57F && fposition[1] == 2383.94F) { // CATIA S0 A2
System.out.println("CATIA S0 A2");
if (method.equals("sk")) {
x1 = 7772.6F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 7772.6F;
y1 = 170.1F;
}else {
x1 = 4155.6F;
y1 = 1163.6F;
}
} else if (fposition[0] == 10111.19F && fposition[1] == 2383.94F) { // CATIA S0 A3
System.out.println("CATIA S0 A3");
if (method.equals("sk")) {
x1 = 9459.2F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 9459.2F;
y1 = 170.1F;
}else {
x1 = 4998.9F;
y1 = 1163.6F;
}
} else if (fposition[0] == 11794.97F && fposition[1] == 2383.94F) { // CATIA S0 A4
System.out.println("CATIA S0 A4");
if (method.equals("sk")) {
x1 = 11143F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 11143F;
y1 = 170.1F;
}else {
x1 = 5840.8F;
y1 = 1163.6F;
}
} else if (fposition[0] == 1684.0F && fposition[1] == 2384.0F) { // A1
System.out.println("-A1");
x1 = 1885.0F;
y1 = 210.0F;
} else if (fposition[0] == 1191.0F && fposition[1] == 1684.0F) { // A2
System.out.println("-A2");
x1 = 1183.0F;
y1 = 210.0F;
} else if (fposition[0] == 842.0F && fposition[1] == 1191.0F) { // A3
System.out.println("-A3");
x1 = 703.0F;
y1 = 190.0F;
} else if (fposition[0] == 595.0F && fposition[1] == 842.0F) { // A4
System.out.println("-A4");
if (method.equals("sk")) {
x1 = 467.7F;
y1 = 714.3F;
} else {
x1 = 467.7F;
y1 = 629.2F;
}
}
System.out.println("当前盖章x1坐标:" + x1);
System.out.println("当前盖章y1坐标:" + y1);
Image img = Image.getInstance(imageUrl);
img.setAbsolutePosition(x1, y1);
if(method.equals("zf")) {
img.scalePercent(41);
}else {
img.scalePercent(46);
}
PdfContentByte under = stamper.getOverContent(1);
// 1. 插入图片(带透明度)
PdfGState imgState = new PdfGState();
imgState.setFillOpacity(0.9f);
// 应用透明度状态
under.setGState(imgState);
under.saveState();
under.addImage(img);
PdfGState fontState = new PdfGState();
under.setGState(fontState);
under.saveState();
// 2. 插入时间字符串formattedTime2
// 定义字体Times New Roman常规小四红色
if (method.equals("ls") && isSignDate.equals("Y")) {
BaseFont baseFont = BaseFont.createFont("c:/windows/fonts/times.ttf", // Times New Roman 字体文件路径
BaseFont.WINANSI, BaseFont.EMBEDDED);
under.beginText();
under.setFontAndSize(baseFont, 12);
under.setColorFill(new BaseColor(225, 0, 0));
// under.setTextMatrix(x1+161, y1 + 60);
under.setTextMatrix(x1 + 50, y1 + 6);
under.showText(dateSign);
under.endText();
}
under.restoreState();
fReader.close();
stamper.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static Float[] getSize(Rectangle rectangle) {
Float[] sizef = new Float[2];
float toleft = rectangle.getLeft();
float tobottom = rectangle.getBottom();
float toright = rectangle.getRight();
float totop = rectangle.getTop();
sizef[0] = (Float.valueOf(toright - toleft));
sizef[1] = (Float.valueOf(totop - tobottom));
System.out.println("bean.getH------------>................." + sizef[0]);
System.out.println("bean.getW------------>................." + sizef[1]);
return sizef;
}
}

@ -0,0 +1,337 @@
package com.sgcc.test;
import java.io.FileOutputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Image;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfGState;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
LocalDateTime now = LocalDateTime.now();
String formattedTime1 = now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
String formattedTime2 = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
float opacity = Float.parseFloat("0.9"); // 范围0.0~1.01.0为不透明)
String[] pdfNames = new String[] {"A3图纸模板V4.0"};
int count = 0;
String[] pdfUrls = new String[] { "C:\\测试用例\\" + pdfNames[count++] + ".PDF"};
// String[] imageNames = new String[] {"ls","skjs","skgy"};
String[] imageNames = new String[] { "sk" };
int cnt = 0;
// String[] imageUrls = new String[] {"C:\\测试用例\\"+imageNames[cnt++]+".png","C:\\测试用例\\"+imageNames[cnt++]+".png"
// ,"C:\\测试用例\\"+imageNames[cnt++]+".png"};
String[] imageUrls = new String[] { "C:\\测试用例\\" + imageNames[cnt++] + ".png"};
for (int i = 0; i < pdfUrls.length; i++) {
// for (int j = 0; j < imageUrls.length; j++) {
// System.out.println("========>Begin : "+ pdfUrls[i]);
// String tempTime = now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
// String newPdfUrl = "C:\\测试用例\\盖章\\" + pdfNames[i] + "_"+ imageNames[j] + "_" + tempTime +".PDF";
// String method = imageNames[j];
// System.out.println("pngName : "+ method);
// sign(pdfUrls[i],newPdfUrl,imageUrls[j],"",method,opacity);
// System.out.println("========>End : "+ newPdfUrl);
// System.out.println();
// }
System.out.println("========>Begin : " + pdfUrls[i]);
String tempTime = now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
String newPdfUrl = "C:\\测试用例\\盖章\\" + pdfNames[i] + "_" + imageNames[0] + "_" + tempTime + ".PDF";
System.out.println("pngName : " + imageNames[0]);
sign(pdfUrls[i], newPdfUrl, imageUrls[0], formattedTime2, imageNames[0], opacity);
System.out.println("========>End : " + newPdfUrl);
System.out.println();
sign(newPdfUrl, "C:\\测试用例\\盖章\\" + pdfNames[i] + "_" + imageNames[1] + "_" + tempTime + ".PDF",
imageUrls[1], formattedTime2, imageNames[1], opacity);
}
}
public static void sign(String pdfUrl, String newPdfUrl, String imageUrl, String dateSign, String method,
float opacity) {
// try(FileInputStream fis = new FileInputStream(imageFile);
// InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8)) {
try {
// String imageUrl = "";
// FileReader fReader = new FileReader(imageFile);
// char[] buf = new char[128];
// int len;
// while ((len = fReader.read(buf)) != -1) {
// imageUrl= new String(buf, 0, len);
// }
// imageUrl = imageUrl.split("=")[1];
// System.out.println(imageUrl);
// String imageUrl = "";
// StringBuilder content = new StringBuilder();
// char[] buffer = new char[1024];
// int len;
// while ((len = isr.read(buffer)) != -1) {
// content.append(buffer, 0, len);
// }
// imageUrl = content.toString().split("=")[1];
// System.out.println(imageUrl);
PdfReader reader = new PdfReader(pdfUrl);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(newPdfUrl));
Rectangle rectangle = reader.getPageSize(1);
Float[] fposition = getSize(rectangle);
float x1 = 0.0F;
float y1 = 0.0F;
if (fposition[0] == 2384.0 && fposition[1] == 3370.0F) { // A0
System.out.println("A0");
if (method.equals("sk")) {
x1 = 2718.42F;
y1 = 28.3F;
} else{
x1 = 2718.42F;
y1 = 170.0F;
}
} else if (fposition[0] == 2384.0F && fposition[1] == 1684.0F) { // A1
System.out.println("A1");
if (method.equals("sk")) {
x1 = 1731.9F;
y1 = 28.3F;
} else {
x1 = 1731.9F;
y1 = 170.0F;
}
} else if (fposition[0] == 1684.0F && fposition[1] == 1191.0F) { // A2
System.out.println("A2");
if (method.equals("sk")) {
x1 = 1031.8F;
y1 = 28.3F;
} else {
x1 = 1031.8F;
y1 = 170.0F;
}
} else if (fposition[0] == 1191.0F && fposition[1] == 842.0F) { // A3
System.out.println("A3");
if (method.equals("sk")) {
x1 = 552.7F;
y1 = 14.1F;
} else {
x1 = 552.7F;
y1 = 155.9F;
}
} else if (fposition[0] == 842.0F && fposition[1] == 595.0F) { // A4
System.out.println("A4");
if (method.equals("sk")) {
x1 = 714.3F;
y1 = 467.7F;
} else {
x1 = 629.2F;
y1 = 467.7F;
}
} else if (fposition[0] == 3370.4F && fposition[1] == 2383.94F) { // CATIA A0
System.out.println("CATIA A0");
if (method.equals("sk")) {
x1 = 2718.4F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 2718.4F;
y1 = 170.0F;
}else {
x1 = 1628.5F;
y1 = 1163.6F;
}
} else if (fposition[0] == 2383.94F && fposition[1] == 1683.78F) { // CATIA A1
System.out.println("CATIA A1");
if (method.equals("sk")) {
x1 = 1731.9F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 1731.9F;
y1 = 170.0F;
}else {
x1 = 629.2F;
y1 = 813.5F;
}
} else if (fposition[0] == 1683.78F && fposition[1] == 1190.56F) { // CATIA A2
System.out.println("CATIA A2");
if (method.equals("sk")) {
x1 = 1031.8F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 1031.8F;
y1 = 170.0F;
}else {
x1 = 629.2F;
y1 = 566.9F;
}
} else if (fposition[0] == 1190.56F && fposition[1] == 841.89F) { // CATIA A3
System.out.println("CATIA A3");
if (method.equals("sk")) {
x1 = 552.7F;
y1 = 14.1F;
} else if(method.equals("ls")){
x1 = 552.7F;
y1 = 155.9F;
}else {
x1 = 538.6F;
y1 = 392.5F;
}
} else if (fposition[0] == 595.28F && fposition[1] == 841.89F) { // CATIA A4
System.out.println("CATIA A4");
if (method.equals("sk")) {
x1 = 467.7F;
y1 = 714.3F;
} else if(method.equals("ls")){
x1 = 467.7F;
y1 = 629.2F;
}else {
x1 = 240.9F;
y1 = 392.5F;
}
} else if (fposition[0] == 5054.18F && fposition[1] == 2383.94F) { // CATIA S0 A0
System.out.println("CATIA S0 A0");
if (method.equals("sk")) {
x1 = 4402.2F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 4402.2F;
y1 = 170.1F;
}else {
x1 = 2470.4F;
y1 = 1163.6F;
}
} else if (fposition[0] == 6740.79F && fposition[1] == 2383.94F) { // CATIA S0 A1
System.out.println("CATIA S0 A1");
if (method.equals("sk")) {
x1 = 6088.8F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 6088.8F;
y1 = 170.1F;
}else {
x1 = 3313.7F;
y1 = 1163.6F;
}
} else if (fposition[0] == 8424.57F && fposition[1] == 2383.94F) { // CATIA S0 A2
System.out.println("CATIA S0 A2");
if (method.equals("sk")) {
x1 = 7772.6F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 7772.6F;
y1 = 170.1F;
}else {
x1 = 4155.6F;
y1 = 1163.6F;
}
} else if (fposition[0] == 10111.19F && fposition[1] == 2383.94F) { // CATIA S0 A3
System.out.println("CATIA S0 A3");
if (method.equals("sk")) {
x1 = 9459.2F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 9459.2F;
y1 = 170.1F;
}else {
x1 = 4998.9F;
y1 = 1163.6F;
}
} else if (fposition[0] == 11794.97F && fposition[1] == 2383.94F) { // CATIA S0 A4
System.out.println("CATIA S0 A4");
if (method.equals("sk")) {
x1 = 11143F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 11143F;
y1 = 170.1F;
}else {
x1 = 5840.8F;
y1 = 1163.6F;
}
} else if (fposition[0] == 1684.0F && fposition[1] == 2384.0F) { // A1
System.out.println("-A1");
x1 = 1885.0F;
y1 = 210.0F;
} else if (fposition[0] == 1191.0F && fposition[1] == 1684.0F) { // A2
System.out.println("-A2");
x1 = 1183.0F;
y1 = 210.0F;
} else if (fposition[0] == 842.0F && fposition[1] == 1191.0F) { // A3
System.out.println("-A3");
x1 = 703.0F;
y1 = 190.0F;
} else if (fposition[0] == 595.0F && fposition[1] == 842.0F) { // A4
System.out.println("-A4");
if (method.equals("sk")) {
x1 = 467.7F;
y1 = 714.3F;
} else {
x1 = 467.7F;
y1 = 629.2F;
}
}
System.out.println("当前盖章x1坐标:" + x1);
System.out.println("当前盖章y1坐标:" + y1);
Image img = Image.getInstance(imageUrl);
img.setAbsolutePosition(x1, y1);
PdfContentByte under = stamper.getOverContent(1);
// 1. 插入图片(带透明度)
PdfGState imgState = new PdfGState();
imgState.setFillOpacity(opacity);
// 应用透明度状态
under.setGState(imgState);
under.saveState();
under.addImage(img);
PdfGState fontState = new PdfGState();
under.setGState(fontState);
under.saveState();
// 2. 插入时间字符串formattedTime2
// 定义字体Times New Roman常规小四红色
if (method.equals("ls")) {
BaseFont baseFont = BaseFont.createFont("c:/windows/fonts/times.ttf", // Times New Roman 字体文件路径
BaseFont.WINANSI, BaseFont.EMBEDDED);
under.beginText();
under.setFontAndSize(baseFont, 12);
under.setColorFill(new BaseColor(225, 0, 0));
// under.setTextMatrix(x1+161, y1 + 60);
under.setTextMatrix(x1 + 50, y1 + 8);
under.showText(dateSign);
under.endText();
}
under.restoreState();
stamper.close();
// fReader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static Float[] getSize(Rectangle rectangle) {
Float[] sizef = new Float[2];
float toleft = rectangle.getLeft();
float tobottom = rectangle.getBottom();
float toright = rectangle.getRight();
float totop = rectangle.getTop();
sizef[0] = (Float.valueOf(toright - toleft));
sizef[1] = (Float.valueOf(totop - tobottom));
System.out.println("bean.getH------------>................." + sizef[0]);
System.out.println("bean.getW------------>................." + sizef[1]);
return sizef;
}
}

@ -0,0 +1,58 @@
if (fposition[0] == 2384.0 && fposition[1] == 3370.0F) { // A0
x1 = 3010.0F;
y1 = 220.0F;
} else if (fposition[0] == 2384.0F && fposition[1] == 1684.0F) { // A1
x1 = 2020.0F;
y1 = 220.0F;
} else if (fposition[0] == 1684.0F && fposition[1] == 1191.0F) { // A2
x1 = 1310.0F;
y1 = 220.0F;
} else if (fposition[0] == 1191.0F && fposition[1] == 842.0F) { // A3
x1 = 850.0F;
y1 = 200.0F;
} else if (fposition[0] == 842.0F && fposition[1] == 595.0F) { // A4
x1 = 250.0F;
y1 = 200.0F;
}else if (fposition[0] == 3370.4F && fposition[1] == 2383.94F) { // CATIA A0
x1 = 2870.0F;
y1 = 162.0F;
} else if (fposition[0] == 2383.94F && fposition[1] == 1683.78F) { // CATIA A1
x1 = 1885.0F;
y1 = 162.0F;
} else if (fposition[0] == 1683.78F && fposition[1] == 1190.56F) { // CATIA A2
x1 = 1183.0F;
y1 = 162.0F;
} else if (fposition[0] == 1190.56F && fposition[1] == 841.89F) { // CATIA A3
x1 = 703.0F;
y1 = 148.0F;
} else if (fposition[0] == 595.28F && fposition[1] == 841.89F) { // CATIA A4
x1 = 110.0F;
y1 = 148.0F;
} else if (fposition[0] == 5054.18F && fposition[1] == 2383.94F) { // CATIA S0 A0
x1 = 4554.0F;
y1 = 161.0F;
} else if (fposition[0] == 6740.79F && fposition[1] == 2383.94F) { // CATIA S0 A1
x1 = 6240.0F;
y1 = 161.0F;
} else if (fposition[0] == 8424.57F && fposition[1] == 2383.94F) { // CATIA S0 A2
x1 = 7925.0F;
y1 = 160.0F;
} else if (fposition[0] == 10111.19F && fposition[1] == 2383.94F) { // CATIA S0 A3
x1 = 9614.0F;
y1 = 160.0F;
} else if (fposition[0] == 11794.97F && fposition[1] == 2383.94F) { // CATIA S0 A4
x1 = 11295.0F;
y1 = 160.0F;
}else if (fposition[0] == 1684.0F && fposition[1] == 2384.0F) { // A1
x1 = 1885.0F;
y1 = 210.0F;
} else if (fposition[0] == 1191.0F && fposition[1] == 1684.0F) { // A2
x1 = 1183.0F;
y1 = 210.0F;
} else if (fposition[0] == 842.0F && fposition[1] == 1191.0F) { // A3
x1 = 703.0F;
y1 = 190.0F;
} else if (fposition[0] == 595.0F && fposition[1] == 842.0F) { // A4
x1 = 110.0F;
y1 = 190.0F;
}

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="llib/core-renderer.jar"/>
<classpathentry kind="lib" path="llib/iTextAsian.jar"/>
<classpathentry kind="lib" path="llib/iTextAsianCmaps.jar"/>
<classpathentry kind="lib" path="llib/itextpdf-5.0.6.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cn.net.connor.pdf.xin.image</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

@ -0,0 +1,218 @@
package com.sgcc.test;
import java.io.FileOutputStream;
import java.io.FileReader;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfGState;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.Rectangle;
/**
*
*
* @author wang
* @version 1.0.0
*/
public class StamperXin {
public static void main(String[] args) {
String pdfUrl = args[0];
String newPdfUrl = args[1];
String imageFile = args[2];
String dateSign = args[3];
String method = args[4].toLowerCase();
String isSignDate = args[5];
sign(pdfUrl, newPdfUrl, imageFile,dateSign, method, isSignDate);
}
public static void sign(String pdfUrl, String newPdfUrl, String imageFile, String dateSign,String method,String isSignDate) {
try {
String imageUrl = "";
FileReader fReader = new FileReader(imageFile);
char[] buf = new char[128];
int len;
while ((len = fReader.read(buf)) != -1) {
imageUrl= new String(buf, 0, len);
}
imageUrl = imageUrl.split("=")[1];
System.out.println(imageUrl);
System.out.println("imageUrl : " + imageUrl);
System.out.println("method : " + method);
PdfReader reader = new PdfReader(pdfUrl);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(newPdfUrl));
Rectangle rectangle = reader.getPageSize(1);
Float[] fposition = getSize(rectangle);
float x1 = 0.0F;
float y1 = 0.0F;
if (fposition[0].floatValue() == 2384.0F && fposition[1].floatValue() == 3370.0F) {// A0-HENGBAN
System.out.println("A0-HENGBAN");
if (method.equals("sk")) {
x1 = 2690.1F;
y1 = 56.7F;
} else if(method.equals("ls")){
x1 = 2690.1F;
y1 = 198.4F;
}else {
x1 = 1628.5F;
y1 = 1163.6F;
}
} else if (fposition[0].floatValue() == 2384.0F && fposition[1].floatValue() == 1684.0F) {// A1-HENGBAN
System.out.println("A1-HENGBAN");
if (method.equals("sk")) {
x1 = 1732F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 1732F;
y1 = 170.1F;
}else {
x1 = 1131F;
y1 = 817.8F;
}
} else if (fposition[0].floatValue() == 1684.0F && fposition[1].floatValue() == 1191.0F) {// A2-HENGBAN
System.out.println("A2-HENGBAN");
if (method.equals("sk")) {
x1 = 1695.1F;
y1 = 56.7F;
} else if(method.equals("ls")){
x1 = 1695.1F;
y1 = 198.4F;
}else {
x1 = 785.2F;
y1 = 566.9F;
}
} else if (fposition[0].floatValue() == 1191.0F && fposition[1].floatValue() == 842.0F) {// A3-HENGBAN
System.out.println("A3-HENGBAN");
if (method.equals("sk")) {
x1 = 538.6F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 538.6F;
y1 = 170.1F;
}else {
x1 = 538.6F;
y1 = 392.6F;
}
} else if (fposition[0].floatValue() == 842.0F && fposition[1].floatValue() == 595.0F) {// A4-HENGBAN
System.out.println("A4-HENGBAN");
if (method.equals("sk")) {
x1 = 189.9F;
y1 = 28.3F;
} else if(method.equals("ls")){
x1 = 189.9F;
y1 = 170.1F;
}else {
x1 = 364.3F;
y1 = 269.3F;
}
} else if (fposition[0].floatValue() == 595.0F && fposition[1].floatValue() == 842.0F) {// A4-SHUBANG
System.out.println("A4-SHUBANG");
if (method.equals("sk")) {
x1 = 453.6F;
y1 = 700.1F;
} else if(method.equals("ls")){
x1 = 453.6F;
y1 = 615F;
}else {
x1 = 240.9F;
y1 = 392.6F;
}
} else if (fposition[0] == 2384.0F && fposition[1] == 5056.0F) {// 1.5A0
x1 = 4550.0F;
y1 = 260.0F;
}else if (fposition[0] == 3370.4F && fposition[1] == 2383.94F) {//A0
} else if (fposition[0] == 5055.6F && fposition[1] == 2383.94F) {//A01.5
System.out.println("A01.5");
if (method.equals("sk")) {
x1 = 4373.9F;
y1 = 56.7F;
} else if(method.equals("ls")){
x1 = 4373.9F;
y1 = 198.4F;
}else {
x1 = 2470.4F;
y1 = 1163.6F;
}
} else if (fposition[0] == 2383.94F && fposition[1] == 1683.78F) {// A1
x1 = 1848.0F;
y1 = 260.0F;
} else if (fposition[0] == 1683.78F && fposition[1] == 1190.56F) {// A2
x1 = 1178.0F;
y1 = 230.0F;
} else if (fposition[0] == 1190.56F && fposition[1] == 841.89F) {// A3
x1 = 686.0F;
y1 = 230.0F;
} else if (fposition[0] == 595.28F && fposition[1] == 841.89F) {// A4
x1 = 91.0F;
y1 = 230.0F;
} else if (fposition[0] == 841.89F && fposition[1] == 595.28F) {// A4HEN
}
System.out.println("当前盖章x1坐标:" + x1);
System.out.println("当前盖章y1坐标:" + y1);
Image img = Image.getInstance(imageUrl);
img.setAbsolutePosition(x1, y1);
if(method.equals("zf")) {
img.scalePercent(41);
}else {
img.scalePercent(46);
}
PdfContentByte under = stamper.getOverContent(1);
// 1. 插入图片(带透明度)
PdfGState imgState = new PdfGState();
imgState.setFillOpacity(0.9f);
// 应用透明度状态
under.setGState(imgState);
under.saveState();
under.addImage(img);
PdfGState fontState = new PdfGState();
under.setGState(fontState);
under.saveState();
// 2. 插入时间字符串formattedTime2
// 定义字体Times New Roman常规小四红色
if (method.equals("ls") && isSignDate.equals("Y")) {
BaseFont baseFont = BaseFont.createFont("c:/windows/fonts/times.ttf", // Times New Roman 字体文件路径
BaseFont.WINANSI, BaseFont.EMBEDDED);
under.beginText();
under.setFontAndSize(baseFont, 12);
under.setColorFill(new BaseColor(225, 0, 0));
// under.setTextMatrix(x1+161, y1 + 60);
under.setTextMatrix(x1 + 50, y1 + 6);
under.showText(dateSign);
under.endText();
}
under.restoreState();
fReader.close();
stamper.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static Float[] getSize(Rectangle rectangle) {
Float[] sizef = new Float[2];
float toleft = rectangle.getLeft();
float tobottom = rectangle.getBottom();
float toright = rectangle.getRight();
float totop = rectangle.getTop();
sizef[0] = (Float.valueOf(toright - toleft));
sizef[1] = (Float.valueOf(totop - tobottom));
System.out.println("bean.getH------------>................." + sizef[0]);
System.out.println("bean.getW------------>................." + sizef[1]);
return sizef;
}
}

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/core-renderer.jar"/>
<classpathentry kind="lib" path="lib/itext-2.0.3.jar"/>
<classpathentry kind="lib" path="lib/iText-5.0.2.jar"/>
<classpathentry kind="lib" path="lib/iTextAsian.jar"/>
<classpathentry kind="lib" path="lib/iTextAsianCmaps.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.connor.pdf</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

Binary file not shown.

@ -0,0 +1,41 @@
package com.connor.pdf;
public class JFomPdfBean {
private Float w = 0.0f;
private Float h = 0.0f;
private Float wi = 0.0f;
private Float hi = 0.0f;
public Float getW() {
return w;
}
public void setW(Float w) {
this.w = w;
}
public Float getH() {
return h;
}
public void setH(Float h) {
this.h = h;
}
public Float getWi() {
return wi;
}
public void setWi(Float wi) {
this.wi = wi;
}
public Float getHi() {
return hi;
}
public void setHi(Float hi) {
this.hi = hi;
}
}

@ -0,0 +1,431 @@
package com.connor.pdf;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class SignPdfXin {
public static void main(String[] args) {
int pageCount = 1;
SignPdfXin signPdf = new SignPdfXin();
String dataPath = args[0];
String pdfPath = args[1];
String outs = args[2];
// String dataPath = "C:\\Users\\infodba\\Desktop\\新世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\新世宝PDF\\A4-SHUBANG.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\新世宝CAD输出\\A4-SHUBANG.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\新世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\新世宝CAD\\1.5A0.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\新世宝CAD输出\\1.5A0.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\新世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\新世宝CAD\\A4-SHUBANG.PDF";//A0-HENGBAN A4-SHUBANG
// String outs = "C:\\Users\\infodba\\Desktop\\新世宝CAD输出\\A4-SHUBANG.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\新世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\新建文件夹 (4)\\新世宝\\A4HENG.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\新世宝CAD输出\\A4HENG.PDF";
Map<String, String> dataMap = signPdf.getData(dataPath);
try {
PdfReader reader = new PdfReader(pdfPath);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outs));
Rectangle rectangle = reader.getPageSize(1);
Float[] fposition = signPdf.getSize(rectangle);
BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", true);
float x1 = 0.0F;
float x2 = 0.0F;
float x3 = 0.0F;
float x4 = 0.0F;
float y1 = 0.0F;
float y2 = 0.0F;
float y3 = 0.0F;
float y4 = 0.0F;
if (fposition[0] == 2384.0F && fposition[1] == 3370.0F) {// A0-HENGBAN
x1 = 2834.0F;
y1 = 110.0F;
y2 = 90.0F;
y3 = 70.0F;
y4 = 52.0F;
x2 = 2871.0F;
x3 = 2950.0F;
x4 = 2980.0F;
System.out.println("aaaaa");
} else if (fposition[0] == 2384.0F && fposition[1] == 1684.0F) {// A1-HENGBAN
x1 = 1837.0F;
y1 = 110.0F;
y2 = 90.0F;
y3 = 70.0F;
y4 = 50.0F;
x2 = 1870.0F;
x3 = 1950.0F;
x4 = 1985.0F;
} else if (fposition[0] == 1684.0F && fposition[1] == 1191.0F) {// A2-HENGBAN
x1 = 1176.0F;
y1 = 83.0F;
y2 = 62.0F;
y3 = 43.0F;
y4 = 23.0F;
x2 = 1210.0F;
x3 = 1288.0F;
x4 = 1324.0F;
} else if (fposition[0] == 1191.0F && fposition[1] == 842.0F) {// A3-HENGBAN
x1 = 686.0F;
y1 = 82.0F;
y2 = 60.0F;
y3 = 40.0F;
y4 = 21.0F;
x2 = 719.0F;
x3 = 800.0F;
x4 = 833.0F;
} else if (fposition[0] == 842.0F && fposition[1] == 595.0F) {// A4-HENGBAN
x1 = 338.0F;
y1 = 80.0F;
y2 = 61.0F;
y3 = 42.0F;
y4 = 24.0F;
x2 = 370.0F;
x3 = 450.0F;
x4 = 483.0F;
} else if (fposition[0] == 595.0F && fposition[1] == 842.0F) {// A4-SHUBANG
x1 = 93.0F;
y1 = 80.0F;
y2 = 61.0F;
y3 = 42.0F;
y4 = 24.0F;
x2 = 127.0F;
x3 = 205.0F;
x4 = 238.0F;
} else if (fposition[0] == 2384.0F && fposition[1] == 5056.0F) {// 1.5A0
x1 = 4520.0F;
y1 = 108.0F;
y2 = 90.0F;
y3 = 70.0F;
y4 = 52.0F;
x2 = 4555.0F;
x3 = 4635.0F;
x4 = 4670.0F;
}else if (fposition[0] == 3370.4F && fposition[1] == 2383.94F) {//A0
x1 = 2837.0F;
y1 = 110.0F;
y2 = 90.0F;
y3 = 70.0F;
y4 = 50.0F;
x2 = 2870.0F;
x3 = 2950.0F;
x4 = 2985.0F;
} else if (fposition[0] == 5055.6F && fposition[1] == 2383.94F) {//A01.5
x1 = 4520.0F;
y1 = 110.0F;
y2 = 90.0F;
y3 = 70.0F;
y4 = 50.0F;
x2 = 4555.0F;
x3 = 4635.0F;
x4 = 4670.0F;
} else if (fposition[0] == 2383.94F && fposition[1] == 1683.78F) {// A1
x1 = 1848.0F;
y1 = 110.0F;
y2 = 90.0F;
y3 = 70.0F;
y4 = 50.0F;
x2 = 1883.0F;
x3 = 1963.0F;
x4 = 1998.0F;
} else if (fposition[0] == 1683.78F && fposition[1] == 1190.56F) {// A2
x1 = 1178.0F;
y1 = 83.0F;
y2 = 62.0F;
y3 = 43.0F;
y4 = 23.0F;
x2 = 1212.0F;
x3 = 1290.0F;
x4 = 1326.0F;
} else if (fposition[0] == 1190.56F && fposition[1] == 841.89F) {// A3
x1 = 686.0F;
y1 = 82.0F;
y2 = 60.0F;
y3 = 40.0F;
y4 = 21.0F;
x2 = 719.0F;
x3 = 800.0F;
x4 = 833.0F;
} else if (fposition[0] == 595.28F && fposition[1] == 841.89F) {// A4
x1 = 91.0F;
y1 = 80.0F;
y2 = 61.0F;
y3 = 42.0F;
y4 = 24.0F;
x2 = 125.0F;
x3 = 203.0F;
x4 = 236.0F;
} else if (fposition[0] == 841.89F && fposition[1] == 595.28F) {// A4HEN
x1 = 338.0F;
y1 = 80.0F;
y2 = 61.0F;
y3 = 42.0F;
y4 = 24.0F;
x2 = 370.0F;
x3 = 450.0F;
x4 = 483.0F;
}
if (dataMap.containsKey("设计")) {
String value = dataMap.get("设计");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y1).floatValue());
content.showText(value);
content.endText();
// signPdf.signBZ(pageCount, value, content, reader, stamper, Integer.valueOf(275));
}
if (dataMap.containsKey("校对")) {
String value = dataMap.get("校对");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y2).floatValue());
content.showText(value);
content.endText();
// signPdf.signBZ(pageCount, value, content, reader, stamper, Integer.valueOf(476));
}
if (dataMap.containsKey("审核")) {
String value = dataMap.get("审核");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y3).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("工艺")) {
String value = dataMap.get("工艺");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y4).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("标准化")) {
String value = dataMap.get("标准化");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x3).floatValue(), Float.valueOf(y1).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("会签")) {
String value = dataMap.get("会签");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x3).floatValue(), Float.valueOf(y3).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("批准")) {
String value = dataMap.get("批准");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x3).floatValue(), Float.valueOf(y4).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("设计日期")) {
String value = dataMap.get("设计日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 7.5F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y1).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("校对日期")) {
String value = dataMap.get("校对日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 7.5F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y2).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("审核日期")) {
String value = dataMap.get("审核日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 7.5F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y3).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("工艺日期")) {
String value = dataMap.get("工艺日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 7.5F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y4).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("标准化日期")) {
String value = dataMap.get("标准化日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 7.5F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x4).floatValue(), Float.valueOf(y1).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("会签日期")) {
String value = dataMap.get("会签日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 7.5F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x4).floatValue(), Float.valueOf(y3).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("批准日期")) {
String value = dataMap.get("批准日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 7.5F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x4).floatValue(), Float.valueOf(y4).floatValue());
content.showText(value);
content.endText();
}
stamper.close();
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public Map<String, String> getData(String filePath) {
String lineTxt = "";
Map<Object, Object> dataMap = new HashMap<Object, Object>();
try {
String encoding = "GBK";
File file = new File(filePath);
if (file.isFile() && file.exists()) {
InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
lineTxt = bufferedReader.readLine();
System.out.println("linttxt=======" + lineTxt);
read.close();
} else {
}
} catch (Exception e) {
e.printStackTrace();
}
String[] dataList = null;
if (lineTxt != null && lineTxt.length() > 0 && lineTxt.split("\\|") != null) {
dataList = lineTxt.split("\\|");
} else {
dataList[0] = "";
}
for (int i = 0; i < dataList.length; i++) {
System.out.println("dataList=======" + dataList[i]);
String[] datas = null;
datas = dataList[i].split("=");
if (datas != null && datas.length > 1)
dataMap.put(datas[0], datas[1]);
}
return (Map) dataMap;
}
public Float[] getSize(Rectangle rectangle) {
Float[] sizef = new Float[2];
float toleft = rectangle.getLeft();
float tobottom = rectangle.getBottom();
float toright = rectangle.getRight();
float totop = rectangle.getTop();
JFomPdfBean bean = new JFomPdfBean();
bean.setH(Float.valueOf(toright - toleft));
bean.setW(Float.valueOf(totop - tobottom));
sizef[0] = bean.getH();
sizef[1] = bean.getW();
System.out.println("bean.getH------------>................." + bean.getH());
System.out.println("bean.getW------------>................." + bean.getW());
return sizef;
}
public void signBZ(int pageCount, String value, PdfContentByte content, PdfReader reader, PdfStamper stamper,
Integer x) {
for (int i = 2; i <= pageCount; i++) {
int width = x.intValue();
SignPdfXin pdf = new SignPdfXin();
Rectangle rectangle = reader.getPageSize(i);
System.out.println("=========+ i + ");
Float[] fposition = pdf.getSize(rectangle);
try {
BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", true);
String[] values = value.split(" ");
if (values != null)
for (int j = 0; j < values.length; j++) {
content = stamper.getUnderContent(i);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 11.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(width).floatValue(), Float.valueOf(30.0F).floatValue());
content.showText(values[j]);
content.endText();
width += 63;
}
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/core-renderer.jar"/>
<classpathentry kind="lib" path="lib/itext-2.0.3.jar"/>
<classpathentry kind="lib" path="lib/iText-5.0.2.jar"/>
<classpathentry kind="lib" path="lib/iTextAsian.jar"/>
<classpathentry kind="lib" path="lib/iTextAsianCmaps.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.connor.pdfLao</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7

@ -0,0 +1,41 @@
package com.connor.pdf;
public class JFomPdfBean {
private Float w = 0.0f;
private Float h = 0.0f;
private Float wi = 0.0f;
private Float hi = 0.0f;
public Float getW() {
return w;
}
public void setW(Float w) {
this.w = w;
}
public Float getH() {
return h;
}
public void setH(Float h) {
this.h = h;
}
public Float getWi() {
return wi;
}
public void setWi(Float wi) {
this.wi = wi;
}
public Float getHi() {
return hi;
}
public void setHi(Float hi) {
this.hi = hi;
}
}

@ -0,0 +1,435 @@
package com.connor.pdf;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
public class SignPdfLao {
public static void main(String[] args) {
int pageCount = 1;
SignPdfLao signPdf = new SignPdfLao();
String dataPath = args[0];
String pdfPath = args[1];
String outs = args[2];
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\老世宝PDF\\A4图纸模板.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\A4图纸模板.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\TC模板CATIAPDF\\SHIBAO_A4_页_1.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\SHIBAO_A4_页_1.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\TC模板CATIAPDF\\SHIBAO_SO_A4_页_1.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\SHIBAO_SO_A4_页_1.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\TC模板CATIAPDF\\AA.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\AA.PDF";
// String dataPath = "C:\\Users\\infodba\\Desktop\\老世宝签字.txt";
// String pdfPath = "C:\\Users\\infodba\\Desktop\\TC模板CATIAPDF\\A4图纸模板.PDF";
// String outs = "C:\\Users\\infodba\\Desktop\\老世宝CAD输出\\A4图纸模板.PDF";
Map<String, String> dataMap = signPdf.getData(dataPath);
try {
System.out.println("=====开始签字=====");
PdfReader reader = new PdfReader(pdfPath);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outs));
Rectangle rectangle = reader.getPageSize(1);
Float[] fposition = signPdf.getSize(rectangle);
BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", true);
float x1 = 0.0F;
float x2 = 0.0F;
float x3 = 0.0F;
float x4 = 0.0F;
float y1 = 0.0F;
float y2 = 0.0F;
float y3 = 0.0F;
float y4 = 0.0F;
if (fposition[0] == 2384.0F && fposition[1] == 3370.0F) { // A0
x1 = 2870.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 2900.0F;
x3 = 2971.0F;
x4 = 3003.0F;
} else if (fposition[0] == 2384.0F && fposition[1] == 1684.0F) { // A1
x1 = 1885.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1913.0F;
x3 = 1985.0F;
x4 = 2016.0F;
} else if (fposition[0] == 1684.0F && fposition[1] == 1191.0F) { // A2
x1 = 1183.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1214.0F;
x3 = 1285.0F;
x4 = 1316.0F;
} else if (fposition[0] == 1191.0F && fposition[1] == 842.0F) { // A3
x1 = 703.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 735.0F;
x3 = 805.0F;
x4 = 837.0F;
} else if (fposition[0] == 842.0F && fposition[1] == 595.0F) { // A4
x1 = 110.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 142.0F;
x3 = 213.0F;
x4 = 243.0F;
} else if (fposition[0] == 3370.4F && fposition[1] == 2383.94F) { // CATIA A0
x1 = 2870.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 2902.0F;
x3 = 2971.0F;
x4 = 3003.0F;
} else if (fposition[0] == 2383.94F && fposition[1] == 1683.78F) { // CATIA A1
x1 = 1885.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1914.0F;
x3 = 1986.0F;
x4 = 2017.0F;
} else if (fposition[0] == 1683.78F && fposition[1] == 1190.56F) { // CATIA A2
x1 = 1183.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1214.0F;
x3 = 1285.0F;
x4 = 1316.0F;
} else if (fposition[0] == 1190.56F && fposition[1] == 841.89F) { // CATIA A3
x1 = 703.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 735.0F;
x3 = 805.0F;
x4 = 837.0F;
} else if (fposition[0] == 595.28F && fposition[1] == 841.89F) { // CATIA A4
x1 = 110.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 142.0F;
x3 = 213.0F;
x4 = 243.0F;
} else if (fposition[0] == 5054.18F && fposition[1] == 2383.94F) { // CATIA S0 A0
x1 = 4554.0F;
y1 = 61.0F;
y2 = 47.0F;
y3 = 33.0F;
y4 = 19.0F;
x2 = 4585.5F;
x3 = 4585.5F;
x4 = 4585.5F;
} else if (fposition[0] == 6740.79F && fposition[1] == 2383.94F) { // CATIA S0 A1
x1 = 6240.0F;
y1 = 61.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 6272.0F;
x3 = 6272.0F;
x4 = 6272.0F;
} else if (fposition[0] == 8424.57F && fposition[1] == 2383.94F) { // CATIA S0 A2
x1 = 7925.0F;
y1 = 60.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 7957.0F;
x3 = 7957.0F;
x4 = 7957.0F;
} else if (fposition[0] == 10111.19F && fposition[1] == 2383.94F) { // CATIA S0 A3
x1 = 9614.0F;
y1 = 60.0F;
y2 = 46.0F;
y3 = 32.0F;
y4 = 18.0F;
x2 = 9643.0F;
x3 = 9643.0F;
x4 = 9643.0F;
} else if (fposition[0] == 11794.97F && fposition[1] == 2383.94F) { // CATIA S0 A4
x1 = 11295.0F;
y1 = 60.0F;
y2 = 46.0F;
y3 = 32.0F;
y4 = 18.0F;
x2 = 11327.0F;
x3 = 11327.0F;
x4 = 11327.0F;
} else if (fposition[0] == 1684.0F && fposition[1] == 2384.0F) { // A1
x1 = 1885.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1913.0F;
x3 = 1985.0F;
x4 = 2016.0F;
} else if (fposition[0] == 1191.0F && fposition[1] == 1684.0F) { // A2
x1 = 1183.0F;
y1 = 62.0F;
y2 = 48.0F;
y3 = 34.0F;
y4 = 20.0F;
x2 = 1214.0F;
x3 = 1285.0F;
x4 = 1316.0F;
} else if (fposition[0] == 842.0F && fposition[1] == 1191.0F) { // A3
x1 = 703.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 735.0F;
x3 = 805.0F;
x4 = 837.0F;
} else if (fposition[0] == 595.0F && fposition[1] == 842.0F) { // A4
x1 = 110.0F;
y1 = 48.0F;
y2 = 34.0F;
y3 = 20.0F;
y4 = 6.0F;
x2 = 142.0F;
x3 = 213.0F;
x4 = 243.0F;
}
if (dataMap.containsKey("编制")) {
String value = (String) dataMap.get("编制");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y1).floatValue());
content.showText(value);
content.endText();
// signPdf.signBZ(pageCount, value, content, reader, stamper, Integer.valueOf(275));
}
if (dataMap.containsKey("校对")) {
String value = (String) dataMap.get("校对");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y2).floatValue());
content.showText(value);
content.endText();
// signPdf.signBZ(pageCount, value, content, reader, stamper, Integer.valueOf(476));
}
if (dataMap.containsKey("会签")) {
String value = (String) dataMap.get("会签");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y3).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("批准")) {
String value = (String) dataMap.get("批准");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 9.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x1).floatValue(), Float.valueOf(y4).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("编制日期")) {
String value = (String) dataMap.get("编制日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 6.2F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y1).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("校对日期")) {
String value = (String) dataMap.get("校对日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 6.2F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y2).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("会签日期")) {
String value = (String) dataMap.get("会签日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 6.2F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y3).floatValue());
content.showText(value);
content.endText();
}
if (dataMap.containsKey("批准日期")) {
String value = (String) dataMap.get("批准日期");
PdfContentByte content = stamper.getUnderContent(1);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 6.2F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(x2).floatValue(), Float.valueOf(y4).floatValue());
content.showText(value);
content.endText();
}
stamper.close();
reader.close();
System.out.println("=====签字结束=====");
} catch (Exception e) {
e.printStackTrace();
}
}
public Map<String, String> getData(String filePath) {
String lineTxt = "";
Map<String, String> dataMap = new HashMap<>();
try {
String encoding = "GBK";
File file = new File(filePath);
if ((file.isFile()) && (file.exists())) {
InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
lineTxt = bufferedReader.readLine();
System.out.println("linttxt=======" + lineTxt);
read.close();
} else {
System.out.println("找不到指定的文件");
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}
String[] dataList = null;
if ((lineTxt != null) && (lineTxt.length() > 0) && (lineTxt.split("\\|") != null))
dataList = lineTxt.split("\\|");
else {
dataList[0] = "";
}
for (int i = 0; i < dataList.length; i++) {
System.out.println("dataList=======" + dataList[i]);
String[] datas = null;
datas = dataList[i].split("=");
if ((datas != null) && (datas.length > 1)) {
dataMap.put(datas[0], datas[1]);
}
}
return dataMap;
}
public Float[] getSize(Rectangle rectangle) {
Float[] sizef = new Float[2];
float toleft = rectangle.getLeft();
float tobottom = rectangle.getBottom();
float toright = rectangle.getRight();
float totop = rectangle.getTop();
JFomPdfBean bean = new JFomPdfBean();
bean.setH(Float.valueOf(toright - toleft));
bean.setW(Float.valueOf(totop - tobottom));
sizef[0] = bean.getH();
sizef[1] = bean.getW();
System.out.println("bean.getH------------>................." + bean.getH());
System.out.println("bean.getW------------>................." + bean.getW());
return sizef;
}
public void signBZ(int pageCount, String value, PdfContentByte content, PdfReader reader, PdfStamper stamper,
Integer x) {
for (int i = 2; i <= pageCount; i++) {
int width = x.intValue();
SignPdfLao pdf = new SignPdfLao();
Rectangle rectangle = reader.getPageSize(i);
System.out.println("=========第" + i + "页=========");
Float[] fposition = pdf.getSize(rectangle);
try {
BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", true);
String[] values = value.split(" ");
if (values != null)
for (int j = 0; j < values.length; j++) {
content = stamper.getUnderContent(i);
content.beginText();
content.setColorFill(Color.BLACK);
content.setFontAndSize(base, 11.0F);
content.setTextRise(14.0F);
content.setTextMatrix(Float.valueOf(width).floatValue(), Float.valueOf(30.0F).floatValue());
content.showText(values[j]);
content.endText();
width += 63;
}
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

Binary file not shown.

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/k.util_1.0.0.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.connor.wj.plm</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

@ -0,0 +1,23 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plm
Bundle-SymbolicName: com.connor.wj.plm;singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: com.connor.wj.plm.Activator
Bundle-Vendor: CONNOR
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
com.teamcenter.rac.aifrcp;bundle-version="12000.1.0",
com.teamcenter.rac.ui;bundle-version="12000.1.0",
com.teamcenter.rac.kernel;bundle-version="12000.1.0",
com.teamcenter.rac.ui.commands;bundle-version="12000.1.0",
com.teamcenter.rac.util;bundle-version="12000.1.0",
com.teamcenter.rac.external;bundle-version="12000.1.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: com.connor.wj.plm
Bundle-ActivationPolicy: lazy
Export-Package: com.connor.wj.plm,
com.connor.wj.plm.dialogs,
com.connor.wj.plm.handlers
Bundle-ClassPath: .,
lib/k.util_1.0.0.jar

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save