Foxit PDF SDK for Linux Foxit PDF SDK for Mac Foxit PDF SDK for Windows

How to generate fill-sign object in pdf file

System requirements

Platform: Windows, Mac, Linux
Programming Language: C, C++, C#, Dotnetcore, Java, Python, Objective-C
License Key requirement: standard license key
SDK Version: Foxit PDF SDK 8.4 or later

What is the fill-sign?

Fill and Sign is a modern document processing feature mainly used to fill out forms in PDF documents and sign documents. It allows users to easily add form elements such as text boxes, select boxes, and date pickers to PDF documents, fill in form information, and add electronic signatures and dates. This function is widely used in the filling and signing process of contracts, forms, reports, and other documents, which can greatly improve the efficiency and accuracy of document processing, helping users complete the signing process more quickly, efficiently, and conveniently.

Next, this article guides you how to use the fill-sign function.

Function introduction of fill-sign

Add various types of fill-sign objects to relevant PDF pages,for example:

● Text fill-sign object.
● Cross mark fill-sign object.
● Signature fill-sign object.
● Check mark fill-sign object.
● Round rectangle fill-sign object.
● Line fill-sign object.
● Dot fill-sign object.
● Initials signature fill-sign object.

You can use these fill-sign type objects to add form elements, such as text boxes, select boxes, radio buttons, checkboxes, etc., to PDF forms so that you can quickly fill and submit the form. In addition, if it is a Signature fill-sign object, Foxit PDF SDK supports multiple signature methods, including handwritten signature, digital signature, timestamp signature, etc., allowing users to quickly sign on PDF files.

How to add fill-sign object to pdf

1. The first step is to create “FillSign” and bind it to the page that needs to be added, and create the fill-sign object , as follows:

2. Then add the fill-sign object that needs to be added to “FillSign”, and you can specify the added coordinate position. As follows:

Add a signature fill-sign object:

If you want to remove the fill-sign object that has been added, please use the “RemoveObject” method.

Attention,”AddObject “can add a new fill-sign object (except text fill-sign object) to related PDF page. If you want to add a new text fill-sign object, see the following display:

3. Finally generate the added fill-sign object:

Code display of Fill-Sign in various languages:

C++

#include <time.h>
#include <iostream>
#include <map>
 
#if defined(_WIN32) || defined(_WIN64)
#include<direct.h>
#else
#include <sys/stat.h>
#endif
 
#include "../../../include/common/fs_common.h"
#include "../../../include/pdf/fs_pdfdoc.h"
#include "../../../include/pdf/fs_pdfpage.h"
#include "../../../include/pdf/fs_fillsign.h"
 
 
using namespace std;
using namespace foxit;
using namespace foxit::common;
using foxit::common::Library;
using namespace pdf;
using namespace foxit::addon;
using namespace graphics;
 
 
static const char* sn = "VQv/htdRKu1rjhk90MTKF+/aCs9DfQRtBF4SNc0GwPlOX8ualGeTJg==";
static const char* key = "ezJvj18mtBp399sXJVWofHfLliq8pf9v7BMskv+zLerFJVWviGEfZ+kCs+nfwjfVTthVUzkIj1qr9k37wnS1f2YSW3jOA/0EfK806dB9bigN097uSthk6eeafc30XHVMSGerLpzYziDW9zL/1oMTZ80YX6Trs0BWaif611VZm/SJ4PkaRzN0sCCOUUKXl8+dUun4a2hGn1fxneYEh8ROSeTXRbNA0ltpL6d4xs+X4o5p+sJBSDjgoProtzbAeTELgzieFZtk/2qbfUzT0Zi3hIIFde/UHOEemCp88Une4k87YS8hK3n5H0s1EJLW8P4QUKdYIFU+r6iLZ3SVrT61l1IBvE0DoO+cUd3GpcA3XnAUamIDwtLzg6c7atTPKDnb3lM25K+LB7/1HIUTMZHmvE2JCuQM7J/c7hkYGoD4KvKl3UIgbGYCyEjQabHNVE0FiSWX7ZlE2RAA6DlzIxWhwhAbz4pkVggWTesZP+vVclWC2Vypebbt2zx+qTVWMNQTsXD9MKUMdOqRAvuytH/Hqw9LE3AoTR6oJE9FWw6NzkXAS2k0ylHHE7kdJh3z3MrCHblR3z1T28O1Me8WbGl1+1WaVEod5gowIsn/ut1/2MLYzyo3DCgDkNr+2nzeZSKIx9J92z6mEwexxlTfOea8cabcYO4QLbyCb+CNq5EhqsVv6UVMDkex6s9YA26WEjj4/Vp8hCKUBavqqqFOJtg8m7EDQQ9G0ZtfX4gLuQulsbluuxynUHrIF0BLdKfKLdAZav3+9lFiA2ORRwLWysYqASdCv4jE4oj2zpTIq4t4iFeOx2/PwJ8fuTMHZkihAbeKolrFq9MZCh6kUg0o1M6kowt8AHPhSG0I1Ng/OCz1lA6m2eBWu2dXtL4P7OJCs447MYgHPhc9k/K+LJvfzOBovIfogZKdwEWbN86ItHVQTDLs3Qlx0qn4tpTJfBcZJUpi03satDiaipWhVNznvr9kDKlGx1VBu+ciqB8MDaC/MGAVeRl+ByqT5t2L6I8koG58o/sNRjMZ1Y5CfFIl5J7j3J2+acYW9vPNrkLgbD5DPAQGhJUlo2K59v62/HrEJDXzz2ue6FEbIASS37X9JdBWqoMav5Ti1dlNpDONbprffNqVyiGromUvTGT4Y9KJWqBCou/p1KzW9s4rCuwzONuKNF7nOqx0lGsCQrL8pkvDwDKJ94lx5oyHZdHNS2xMh98qPo1V7nc=";
#if defined(_WIN32) || defined(_WIN64)
static WString output_path = WString::FromLocal("../output_files/");
static WString input_path = WString::FromLocal("../input_files/");
#else
static WString output_path = WString::FromLocal("./output_files/");
static WString input_path = WString::FromLocal("./input_files/");
#endif
 
class SdkLibMgr {
public:
  SdkLibMgr() : is_initialize_(false){};
  ErrorCode Initialize() {
    ErrorCode error_code = Library::Initialize(sn, key);
    if (error_code != foxit::e_ErrSuccess) {
      printf("Library Initialize Error: %d\n", error_code);
    } else {
      is_initialize_ = true;
    }
    return error_code;
 
  }
  ~SdkLibMgr(){
    if(is_initialize_)
      Library::Release();
  }
private:
  bool is_initialize_;
};
 
int main(int argc, char *argv[])
{
    WString output_directory = output_path + L"fillsign/";
#if defined(_WIN32) || defined(_WIN64)
    _mkdir(String::FromUnicode(output_directory));
#else
    mkdir(String::FromUnicode(output_directory), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
#endif
 
    int err_ret = 0;
    SdkLibMgr sdk_lib_mgr;
    // Initialize library
    ErrorCode error_code = sdk_lib_mgr.Initialize();
    if (error_code != foxit::e_ErrSuccess) {
        return 1;
    }
    cout << "fillsign Start" << endl;
    try {
        WString input_file = input_path + L"blank.pdf";
        PDFDoc doc(input_file);
 
        ErrorCode error_code = doc.Load();
        if (error_code != foxit::e_ErrSuccess) {
            printf("The Doc [%s] Error: %d\n", (const char*)String::FromUnicode(input_file), error_code);
            return 1;
        }
        PDFPage page = doc.GetPage(0);
        page.StartParse();
 
        FillSign fillsign(page);
 
    FillSignObject fillsignobject = fillsign.AddObject(pdf::FillSign::e_FillSignObjectTypeCrossMark, PointF(0, 0), 100, 100);
    fillsignobject = fillsign.AddObject(pdf::FillSign::e_FillSignObjectTypeCheckMark, PointF(100, 100), 50, 100);
        fillsignobject = fillsign.AddObject(pdf::FillSign::e_FillSignObjectTypeRoundRectangle, PointF(200, 200), 100, 50);
        fillsignobject = fillsign.AddObject(pdf::FillSign::e_FillSignObjectTypeLine, PointF(300, 300), 100, 50);
        fillsignobject = fillsign.AddObject(pdf::FillSign::e_FillSignObjectTypeDot, PointF(400, 400), 100, 100);
 
        TextFillSignObjectDataArray textdataarray;
        TextFillSignObjectData textdata;
        TextState textState;
        Font font(Font::e_StdIDHelvetica);
 
        textState.font = font;
        textState.font_size = 20;
        textState.origin_position = PointF(500, 0);
        textState.charspace = 1.0f;
        textdata.text = L"666777888";
        textdata.text_state = textState;
        textdataarray.Add(textdata);
        FillSignObject text = fillsign.AddTextObject(textdataarray, PointF(400, 100), 200, 200);
        text.GenerateContent();
 
        fillsignobject = fillsign.AddObject(pdf::FillSign::e_FillSignObjectTypeSignature, PointF(300, 100), 100, 100);
        Bitmap bitmap(100, 100, foxit::common::Bitmap::e_DIBArgb);
        bitmap.FillRect(0xFFFF0000);
        ((SignatureFillSignObject)fillsignobject).SetBitmap(bitmap);
        fillsignobject.GenerateContent();
        page.GenerateContent();
        WString pdf_new = output_directory + L"new_fillsign.pdf";
        doc.SaveAs(pdf_new);
        cout << "fillsign Finish : All fillsign generated successfully" << endl;
    }
    catch (const Exception& e) {
        cout << e.GetMessage() << endl;
        return 1;
    }
    return err_ret;
}

JAVA

import com.foxit.sdk.pdf.FillSignObject;
import com.foxit.sdk.pdf.TextFillSignObjectDataArray;
import com.foxit.sdk.pdf.TextFillSignObjectData;
import com.foxit.sdk.pdf.SignatureFillSignObject;
import com.foxit.sdk.pdf.graphics.TextState;
import com.foxit.sdk.common.Font;
import com.foxit.sdk.common.Bitmap;
PDFPage page = doc.getPage(0);
 
page.startParse(e_ParsePageNormal, null, false);
FillSign sign = new FillSign(page);
FillSignObject fillsignobject = sign.addObject(e_FillSignObjectTypeCrossMark, new PointF(0, 0), 100, 100,e_Rotation0);
fillsignobject = sign.addObject(e_FillSignObjectTypeCheckMark, new PointF(100, 100), 50, 100, e_Rotation0);
fillsignobject = sign.addObject(e_FillSignObjectTypeRoundRectangle, new PointF(200, 200), 100, 50, e_Rotation0);
fillsignobject = sign.addObject(e_FillSignObjectTypeLine, new PointF(300, 300), 100, 50, e_Rotation0);
fillsignobject = sign.addObject(e_FillSignObjectTypeDot, new PointF(400, 400), 100, 100, e_Rotation0);
 
TextFillSignObjectDataArray textdataarray = new TextFillSignObjectDataArray();
TextFillSignObjectData textdata = new TextFillSignObjectData();
TextState textState = new TextState();
Font font = new Font(e_StdIDHelvetica);
 
textState.setFont(font);
textState.setFont_size(20);
textState.setOrigin_position(new PointF(500, 0));
textState.setCharspace(1.0f);
textdata.setText("666777888");
textdata.setText_state(textState);
textdataarray.add(textdata);
FillSignObject text = sign.addTextObject(textdataarray, new PointF(400, 100), 200, 200, e_Rotation0, false);
text.generateContent();
fillsignobject = sign.addObject(e_FillSignObjectTypeSignature, new PointF(300, 100), 100, 100, e_Rotation0);
Bitmap bitmap = new Bitmap(100, 100, e_DIBArgb, null, 0);
long background_color = 0xFFFF0000;
bitmap.fillRect(background_color, null);
SignatureFillSignObject signature = new SignatureFillSignObject(fillsignobject);
signature.setBitmap(bitmap);
 
fillsignobject.generateContent();
page.generateContent();
 
String pdf_new = output_path + "new_fillsign.pdf";
doc.saveAs(pdf_new, e_SaveFlagNoOriginal);
System.out.println("fillsign Finish : All fillsign generated successfully");

Python

doc = PDFDoc(input_file)
error_code = doc.Load("")
if error_code != e_ErrSuccess:
    print("The Doc [{}] Error: {}\n".format(input_file, error_code))
    return 1
 
page = doc.GetPage(0)
page.StartParse()
fillsign = FillSign(page)
fillsignobject = fillsign.AddObject(FillSign.e_FillSignObjectTypeCrossMark, PointF(0, 0), 100, 100)
fillsignobject = fillsign.AddObject(FillSign.e_FillSignObjectTypeCheckMark, PointF(100, 100), 50, 100)
fillsignobject = fillsign.AddObject(FillSign.e_FillSignObjectTypeRoundRectangle, PointF(200,200), 100, 50)
fillsignobject = fillsign.AddObject(FillSign.e_FillSignObjectTypeLine, PointF(300, 300), 100, 50)
fillsignobject = fillsign.AddObject(FillSign.e_FillSignObjectTypeDot, PointF(400, 400), 100, 100)
 
 
textdataarray = TextFillSignObjectDataArray();
textdata = TextFillSignObjectData();
textState = TextState();
font = Font(Font.e_StdIDHelvetica)
 
textState.font = font
textState.font_size = 20
textState.origin_position = PointF(500, 0)
textState.charspace = 1.0
textdata.text = "666777888"
textdata.text_state = textState
textdataarray.Add(textdata)
 
text = fillsign.AddTextObject(textdataarray, PointF(400, 100), 200, 200)
text.GenerateContent()
fillsignobject = fillsign.AddObject(FillSign.e_FillSignObjectTypeSignature, PointF(300, 100), 100, 100)
 
 
bitmap = Bitmap(100, 100, Bitmap.e_DIBArgb)
bitmap.FillRect(0xFFFF0000)
Signaturefill = SignatureFillSignObject(fillsignobject)
  
Signaturefill.SetBitmap(bitmap)
Signaturefill.GenerateContent()
page.GenerateContent()
 
pdf_new = output_directory + "new_fillsign.pdf"
doc.SaveAs(pdf_new)
print("fillsign Finish: All fillsign generated successfully")

C#

using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using foxit.pdf.graphics;
using foxit.pdf.objects;
using foxit.addon;
 
PDFPage page = doc.GetPage(0);
page.StartParse((int)PDFPage.ParseFlags.e_ParsePageNormal, null, false);
FillSign fillsign = new FillSign(page);
FillSignObject fillsignobject = fillsign.AddObject(FillSign.FillSignObjectType.e_FillSignObjectTypeCrossMark, new PointF(0, 0), 100, 100, Rotation.e_Rotation0);
fillsignobject = fillsign.AddObject(FillSign.FillSignObjectType.e_FillSignObjectTypeCheckMark, new PointF(100, 100), 50, 100, Rotation.e_Rotation0);
fillsignobject = fillsign.AddObject(FillSign.FillSignObjectType.e_FillSignObjectTypeRoundRectangle, new PointF(200, 200), 100, 50, Rotation.e_Rotation0);
fillsignobject = fillsign.AddObject(FillSign.FillSignObjectType.e_FillSignObjectTypeLine, new PointF(300, 300), 100, 50, Rotation.e_Rotation0);
fillsignobject = fillsign.AddObject(FillSign.FillSignObjectType.e_FillSignObjectTypeDot, new PointF(400, 400), 100, 100, Rotation.e_Rotation0);
 
TextFillSignObjectDataArray textdataarray = new TextFillSignObjectDataArray();
TextFillSignObjectData textdata = new TextFillSignObjectData();
TextState textState = new TextState();
using (Font font = new Font(foxit.common.Font.StandardID.e_StdIDHelvetica))
{
    textState.font = font;
    textState.font_size = 20;
    textState.origin_position = new PointF(500, 0);
    textState.charspace = 1.0f;
    textdata.text = "666777888";
    textdata.text_state = textState;
    textdataarray.Add(textdata);
    FillSignObject text = fillsign.AddTextObject(textdataarray, new PointF(400, 100), 200, 200, Rotation.e_Rotation0, false);
    text.GenerateContent();
 
    fillsignobject = fillsign.AddObject(FillSign.FillSignObjectType.e_FillSignObjectTypeSignature, new PointF(300, 100), 100, 100, Rotation.e_Rotation0);
    Bitmap bitmap = new Bitmap(100, 100, Bitmap.DIBFormat.e_DIBArgb);
    bitmap.FillRect(0xFFFF0000, null);
    SignatureFillSignObject Signaturefill = new SignatureFillSignObject(fillsignobject);
    Signaturefill.SetBitmap(bitmap);
    Signaturefill.GenerateContent();
    page.GenerateContent();
    string pdf_new = output_path + "new_fillsign.pdf";
    doc.SaveAs(pdf_new, (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
    Console.WriteLine("fillsign Finish :All fillsign generated successfully");
}

C

#include "../../../include/fs_fillsign_c.h"
#include "../../../include/fs_image_c.h"
FS_FILLSIGN_HANDLE fillsign;
FS_BOOL is_editable = false;
FSDK_FillSign_Create(page,fillsign);
 
FS_FILLSIGNOBJECT_HANDLE fillsignobject;
FSDK_FillSignObject_Create(fillsignobject);
FSPointF point;
point.x = 0;
point.y = 0;
 error_code = FSDK_FillSign_AddObject(fillsign, e_FSFillSignObjectTypeCrossMark, point, 100, 100, e_FSRotation0, fillsignobject);
if (error_code != e_FSErrSuccess) {
    printf("FSFillSignObjectTypeCrossMark error!\n");
    FSDK_PDFDoc_Release(doc);
    FSDK_FillSign_Release(fillsign);
    return 1;
}
 
FSTextFillSignObjectData textdata;
FSTextState textState;
 
FS_FONT_HANDLE font;
FSDK_Font_Create0(e_FSStdIDHelvetica, font);
error_code = FSDK_FillSign_AddTextObject(fillsign, &textdata,1, point, 200, 200, e_FSRotation0,false, text);
FS_BOOL isfinish;
error_code = FSDK_FillSignObject_GenerateContent(text, isfinish);
error_code = FSDK_FillSign_AddObject(fillsign, e_FSFillSignObjectTypeSignature, point, 100, 100, e_FSRotation0, fillsignobject);
if (error_code != e_FSErrSuccess) {
    printf("FillSignObjectTypeSignature error!\n");
    FSDK_PDFDoc_Release(doc);
    FSDK_FillSign_Release(fillsign);
    return 1;
}
 
FS_BITMAP_HANDLE  bitmap;
FSDK_Bitmap_Create(100, 100, e_FSDIBArgb, NULL, 0, bitmap);
FSDK_Bitmap_FillRect(bitmap, 0xFFFF0000, NULL);
FS_SIGNATUREFILLSIGNOBJECT_HANDLE signature;
 
FSDK_SignatureFillSignObject_Create(fillsignobject, signature);
FSDK_SignatureFillSignObject_SetBitmap(signature, bitmap);
FSDK_FillSignObject_GenerateContent(fillsignobject, isfinish);
FSDK_GraphicsObjects_GenerateContent(page, isfinish);
 
wstring pdf_new = output_directory + L"new_fillsign.pdf";
error_code = FSDK_PDFDoc_SaveAs(doc, pdf_new.c_str(), e_FSSaveFlagNoOriginal, isfinish);
cout << "fillsign Finish : All fillsign generated successfully." << endl;

Objective-C

#include "FSPDFObjC.h"
 
FSFillSignObject *fillsignobject = [fillsign addObject:FSFillSignFillSignObjectTypeCrossMark point:point width:100 height:100 rotation:FSRotation0 ];
[point set:100 y:100];
fillsignobject = [fillsign addObject:FSFillSignFillSignObjectTypeCheckMark point:point width:50 height:100 rotation:FSRotation0];
[point set:200 y:200];
fillsignobject = [fillsign addObject:FSFillSignFillSignObjectTypeRoundRectangle point:point width:100 height:50 rotation:FSRotation0];
[point set:300 y:300];
fillsignobject = [fillsign addObject:FSFillSignFillSignObjectTypeLine point:point width:100 height:50 rotation:FSRotation0];
[point set:400 y:400];
fillsignobject = [fillsign addObject:FSFillSignFillSignObjectTypeDot point:point width:100 height:100 rotation:FSRotation0];
 
FSTextState *textState = [[FSTextState alloc] init];
FSFont* font = [[FSFont alloc] initWithFont_id:FSFontStdIDHelvetica];
textState.font = font;
textState.font_size = 20;
[point set:500 y:0];
textState.origin_position = point;
textState.charspace = 1.0f;
 
FSTextFillSignObjectData *textdata = [[FSTextFillSignObjectData alloc] initWithText_state:textState text:@"dsdsdswfwfw"];
FSTextFillSignObjectDataArray *textdataarray =[[FSTextFillSignObjectDataArray alloc] init];
[textdataarray add:textdata ];
[point set:400 y:100];
FSFillSignObject *text = [fillsign addTextObject:textdataarray point:point width:200 height:200 rotation:FSRotation0 is_comb_field_mode:false];
[text generateContent];
 
[point set:300 y:100];
fillsignobject = [fillsign addObject:FSFillSignFillSignObjectTypeSignature point:point width:100 height:100 rotation:FSRotation0 ];
FSBitmap *bitmap = [[FSBitmap alloc] initWithWidth:100 height:100 format:FSBitmapDIBArgb buffer:nil pitch:0];
[bitmap fillRect:0xFFFF0000 rect:nil];
FSSignatureFillSignObject *signature = [[FSSignatureFillSignObject alloc] initWithFillsign_object:fillsignobject];
[signature setBitmap:bitmap];
[fillsignobject generateContent];
[page generateContent];      
 
NSString *output_file = [output_directory stringByAppendingPathComponent:@"new_fillsign.pdf"];
[doc saveAs:output_file save_flags:FSPDFDocSaveFlagRemoveRedundantObjects];
NSLog(@"fillsign Finish : All fillsign generated successfully");

The result display of fill-sign

Updated on October 13, 2023

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: