Skip to content

压感笔迹 (Pressure Sensitive Ink)

压感笔迹 (PSI) 是一种获取变化电力输出以响应作用于压力感应设备元件上的各种变化压力或受力的技术。在 PDF 中,PSI 通常被用于手写签名,通过捕捉手指或触控笔的压力变化来收集 PSI 数据。PSI 数据包含操作区域的坐标和画布,并用其来绘制 PSI 的外观。福昕 PDF SDK 允许应用程序创建 PSI、访问其属性、操作 ink 笔迹和画布、以及释放 PSI。

创建 PSI 并设置相关属性

c++
#include "include/common/fs_common.h"
#include "include/pdf/fs_pdfdoc.h"
#include "include/pdf/fs_pdfpage.h"
#include "include/pdf/fs_psi.h"

using namespace foxit;
using namespace foxit::common;
using foxit::common::Library;
using namespace pdf;
using namespace annots;

PSI psi(480, 180, true);

// Set ink diameter.
psi.SetDiameter(9);

// Set ink color.
psi.SetColor(0x434236);

// Set ink opacity.
psi.SetOpacity(0.8f);

// Add points to pressure sensitive ink.
float x = 121.3043f;
float y = 326.6846f;
float pressure = 0.0966f;
Path::PointType type = Path::e_TypeMoveTo;
psi.AddPoint(PointF(x, y), type, pressure); 
...
C
#include "include/fs_basictypes_c.h"
#include "include/fs_common_c.h"
#include "include/fs_pdfdoc_c.h"
#include "include/fs_pdfpage_c.h"
#include "include/fs_psi_c.h"

FS_PSI_HANDLE psi;
FSDK_PSI_Create0(480, 180, true, &psi);

// Set ink diameter.
FSDK_PSI_SetDiameter(psi, 9);

// Set ink color.
FSDK_PSI_SetColor(psi, 0x434236);

// Set ink opacity.
FSDK_PSI_SetOpacity(psi, 0.8f);

// Add points to pressure sensitive ink.
float x = 121.3043f;
float y = 326.6846f;
float pressure = 0.0966f;
FSPointType type = e_FSTypeMoveTo;
FSPointF point;
point.x = x;
point.y = y;
FSDK_PSI_AddPoint(psi, point, type, pressure);
...
java
import com.foxit.sdk.pdf.PSI;
import com.foxit.sdk.common.fxcrt.PointF;
...

PSI psi = new PSI(480, 180, true);

// Set ink diameter.
psi.setDiameter(9);

// Set ink color.
psi.setColor(0x434236);

// Set ink opacity.
psi.setOpacity(0.8f);

// Add points to pressure sensitive ink.
float x = 121.3043f;
float y = 326.6846f;
float pressure = 0.0966f;
int type = 1;
PointF point = new PointF(x, y);
psi.addPoint(point, type, pressure); 
...
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    #replace with the python2 lib path
    site.addsitedir('../../../')
    from FoxitPDFSDKPython2 import *
else:
from FoxitPDFSDKPython3 import *

psi = PSI(480, 180, True)

# Set ink diameter.
psi.SetDiameter(9)

# Set ink color.
psi.SetColor(0x434236)

# Set ink opacity.
psi.SetOpacity(0.8)

# Add points to pressure sensitive ink.
x = 121.3043
y = 326.6846
pressure = 0.0966
type = Path.e_TypeMoveTo
psi.AddPoint(PointF(x, y), type, pressure)
objc
#include "FSPDFObjC.h"
...

FSPSI *psi = [[FSPSI alloc] initWithWidth:480 height:180 simulate:YES];

// Set ink diameter.
[psi setDiameter:9];

// Set ink color.
[psi setColor:0x434236];

// Set ink opacity.
[psi setOpacity:0.8f];

// Add points to pressure sensitive ink.
float x = 121.3043f;
float y = 326.6846f;
float pressure = 0.0966f;
FSPathPointType type = FSPathTypeMoveTo;

FSPointF *pt = [[FSPointF alloc] init];
pt.x = 121.3043f;
pt.y = 326.6846f;
[psi addPoint:pt type:type pressure:pressure]; 
...
js
const FSDK = require("@foxitsoftware/foxit-pdf-sdk-node");

let psi = new FSDK.PSI(480, 180, true);

// Set ink diameter.
psi.SetDiameter(9);

// Set ink color.
psi.SetColor(0x434236);

// Set ink opacity.
psi.SetOpacity(0.8);

// Add points to pressure sensitive ink.
let x = 121.3043
let y = 326.6846
let pressure = 0.0966
let type = FSDK.Path.e_TypeMoveTo
psi.AddPoint(new FSDK.PointF(x, y), type, pressure)
csharp
using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using foxit.pdf.annots;
...

PSI psi = new PSI(480, 180, true);

// Set ink diameter.
psi.SetDiameter(9);

// Set ink color.
psi.SetColor(0x434236);

// Set ink opacity.
psi.SetOpacity(0.8f);

// Add points to pressure sensitive ink.
float x = 121.3043f;
float y = 326.6846f;
float pressure = 0.0966f;
Path.PointType type = Path.PointType.e_TypeMoveTo;
foxit.common.fxcrt.PointF pt = new foxit.common.fxcrt.PointF(x, y);
psi.AddPoint(pt, type, pressure);
...