How to stamp Unicode text with opacity using pdfStamp.dll?

I want to stamp unicode text with opacity from my application.
I did successfully stamp unicode text and opacity using the following links, but not at the same time.

Can we add opacity into the following example?
http://www.verypdf.com/wordpress/201605/how-to-stamp-unicode-characters-to-pdf-pages-using-pdfstamp-dll-from-vb6-42669.html

Or
Can we add unicode text into the following example?
http://www.verypdf.com/wordpress/201311/opacity-in-pdf-stamp-sdkcomdll-library-version-39315.html

Or
any other suggestion please?

I know this can be done by command line version,
But my boss preferred to use dll version.

Customer
-------------------------------------------------------

image
Thanks for your message, you can use PDFStampWriteTextExW() function to stamp unicode text stamp to PDF pages, for example,

#include <stdio.h>
#include <Windows.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <windowsx.h>

typedef enum
{
    /*----------------------- 8 bit code pages ------------------------*/
    cp1250,
    cp1251,
    cp1252,
    cp1253,
    cp1254,
    cp1255,
    cp1256,
    cp1257,
    cp1258,
    cp8859_2,
    cp8859_3,
    cp8859_4,
    cp8859_5,
    cp8859_6,
    cp8859_7,
    cp8859_8,
    cp8859_9,
    cp8859_10,
    cp8859_13,
    cp8859_14,
    cp8859_15,
    cp8859_16,
    cpSymbol,
    cp437,
    cp737,
    cp775,
    cp850,
    cp852,
    cp855,
    cp857,
    cp860,
    cp861,
    cp862,
    cp863,
    cp864,
    cp865,
    cp866,
    cp869,
    cp874,
    cpUnicode,       
    cpCJK_Big5_Uni,    // Big5 plus HKSCS extension.
    cpCJK_EUC_JP_Uni,  // EUC-JP.
    cpCJK_EUC_KR_Uni,  // EUC-KR.
    cpCJK_EUC_TW_Uni,  // CNS-11643-1992 (Planes 1-15).
    cpCJK_GBK_Uni,     // GBK is the Microsoft code page 936 (GB2312, EUC-CN plus GBK extension).
    cpCJK_GB12345_Uni, // GB-12345-1990 (Traditional Chinese form of GB-2312).
    cpCJK_HZ_Uni,      // Mixed ASCII / GB-2312 encoding
    cpCJK_2022_CN_Uni, // ISO-2022-CN-EXT (GB-2312 plus ISO-11643 Planes 1-7).
    cpCJK_2022_JP_Uni, // ISO-2022-JP.
    cpCJK_2022_KR_Uni, // ISO-2022-KR.
    cpCJK_646_CN_Uni,  // ISO-646-CN (GB-1988-80).
    cpCJK_646_JP_Uni,  // ISO-646-JP (JIS_C6220-1969-RO).
    cpCJK_IR_165_Uni,  // ISO-IR-165 (extended version of GB-2312).
    cpCJK_932_Uni,     // Microsoft extended version of SHIFT_JIS.
    cpCJK_949_Uni,     // EUC-KR extended with UHC (Unified Hangul Codes).
    cpCJK_950_Uni,     // Microsoft extended version of Big5.
    cpCJK_JOHAB_Uni,   // JOHAB.       
    cpShiftJIS,     // ShiftJIS charset plus code page 932 extension.
    cpBig5,         // Big5 plus HKSCS extension.
    cpGB2312,       // GB2312 charset plus GBK and cp936 extension.
    cpWansung,      // Wansung
    cpJohab,        // Johab
    cpMacRoman,     // Mac Roman
    cpAdobeStd,     // This is an encoding for Type1 fonts. It should normally not be used.
    cpInternal,     // Internal -> not usable
    cpGlyphIndexes, // Can be used with TrueType and OpenType fonts only. DynaPDF creates a reverse mapping so that copy & paste will work.
    cpPDFDocEnc,    // Internal -> not usable. Used for form fonts. This is a superset of the code page 1252 and MacRoman.
    cpExtCMap,      // Internal -> not usable. This code page is set when a font was loaded with an external cmap.
    cpDingbats      // Internal -> Special encoding for ZapfDingbats
}TCodepage;

//define for VerySetFunction
#define Very_Set_Range                131
#define Very_Get_PdfPageCount        206
#define Very_Get_PageBoxForStamp    260
#define Very_Set_Text_Leading        134
#define Very_Set_Opacity            240
#define Very_Set_EmbedFont            241
#define Very_Get_EmbedFont            241
#define Very_Set_TransparentColor    242
#define Very_Set_ImageLossless        243
#define Very_Set_InsertMultipleImageCopy    244

#define fsNone           0x00000000 // Regular weight (400)
#define fsNormal         0x00000500 // 5
#define fsItalic         0x00000001
#define fsBold           0x2BC00000 // 700 -> The old constant 2 is still supported to preserve backward compatibility

typedef long    (__stdcall *VeryStampRegFunc)(char *reg);
typedef long    (__stdcall *VeryStampLayerOpenFunc)(char *In, char *Out, char *lpFGLayerName,char *lpBGLayerName);
typedef long    (__stdcall *VeryStampOpenFunc)(char *In,char *Out);
typedef void    (__stdcall *VeryStampCloseFunc)(long id);
typedef long    (__stdcall *VeryStampSetFunctionFunc)(long id,long func_code,long para1,long para2,char *para3,char *para4);
typedef long    (__stdcall *VeryStampGetFunctionFunc)(long id,long func_code,long para1,long para2,char *para3,char *para4);
typedef long    (__stdcall *VeryStampAddImageFunc)(long id,long position,
                                                   char *filename,
                                                   long shift_lr,long shift_tb,long rotate,long layer,
                                                   long zoomW,long zoomH,
                                                   long action,char *link,long pageno);
typedef long    (__stdcall *VeryStampAddImageExFunc)(long id,long position, char *filename,
                                                     long shift_lr,long shift_tb,long rotate,long layer,
                                                     long width,long height,
                                                     long action,char *link,long pageno);
typedef long    (__stdcall *VeryStampAddTextFunc)(long id,long position,
                                                  char *string, long color,long alignment,
                                                  long shift_lr,long shift_tb,long rotate,long layer,
                                                  long hollow, long fontcode,char *fontname,long fontsize,
                                                  long action,char *link,long pageno);

typedef long    (__stdcall *VeryStampAddLineFunc)(long id,long position, long width,long color,
                                                  long shift_lr,long shift_tb,long rotate,long layer,
                                                  long zoomW,long zoomH);
typedef long    (__stdcall *VeryStampAddRectFunc)(long id,long sx_,long sy_,long ex_,long ey_,
                                                  long side_width,long side_color,
                                                  long flagFill,long fill_color);
typedef long    (__stdcall *VeryStampAddCircleFunc)(long id,long x,long y, long radius,
                                                    long side_width,long side_color,
                                                    long flagFill,long fill_color);
typedef long    (__stdcall *VeryStampAddEllipseFunc)(long id,long sx_,long sy_,long ex_,long ey_,
                                                     long side_width,long side_color,
                                                     long flagFill,long fill_color);
typedef long    (__stdcall *VeryStampAddCurveToFunc)(long id,long sx_,long sy_,long x1,long y1,
                                                     long x2,long y2,long x3,long y3,
                                                     long side_width,long side_color);

typedef long    (__stdcall *VeryStampAddRectWithLayerFunc)(long id,long sx_,long sy_,long ex_,long ey_,
                                                           long side_width,long side_color,
                                                           long flagFill,long fill_color,long layer);
typedef long    (__stdcall *VeryStampUndoFunc)(char *filename);
typedef long    (__stdcall *VeryStampAddLineExFunc)(long id,long sx,long sy,long ex,long ey,long width,long color);
typedef long    (__stdcall *VeryStampIsStampedFunc)(char *lpPDFFile);

typedef long (__stdcall *VeryStampForm_AllocFunc)();
typedef long (__stdcall *VeryStampForm_FreeFunc)(long id);
typedef long (__stdcall *VeryStampForm_SetTextFieldFunc)(long id, LPCTSTR lpFieldName, LPCTSTR lpFieldValue);
typedef long (__stdcall *VeryStampForm_SetCheckBoxFunc)(long id, LPCTSTR lpFieldName, LPCTSTR lpFieldValue);
typedef long (__stdcall *VeryStampForm_ApplyFunc)(long id, LPCTSTR lpInFile, LPCTSTR lpOutFile, LONG bFlatten);
typedef long (__stdcall *VeryStampForm_ClearFieldsFunc)(long id);

typedef long (__stdcall *VeryStampEncryptPDFFunc)(LPSTR lpInPDF, LPSTR lpOutPDF,char *lpszOpenPwd,char *lpszOwnerPwd,
                            int iKeyLen, int iRestriction);
typedef BOOL (__stdcall *VeryStampDeleteStampFromPagesFunc)(char *lpInPDF, char *lpOutPDF, char *lpPageRange);
typedef long (__stdcall *VeryStampDeleteImagesFromPagesFunc)(char *lpInPDF, char *lpOutPDF, int nWidth, int nHeight, char *lpPageRange);
typedef int  (__stdcall *VeryStampSetLayerPrintFlagFunc)(long id, LPCTSTR lpLayerName, int nFlag);

typedef long (__stdcall *PDFStampOpenFunc)(char *lpInPDF);
typedef BOOL (__stdcall *PDFStampCloseFunc)(long hPDF, char *lpOutPDF);
typedef long (__stdcall *PDFStampSetFontAFunc)(long hPDF, const char* fontName, long fontStyle, double fontSize, long isEmbed, long nCodePage);
typedef BOOL (__stdcall *PDFStampSetFillColorFunc)(long hPDF, long nColor);
typedef BOOL (__stdcall *PDFStampWriteTextAFunc)(long hPDF, double x, double y, const char* lpText);
typedef BOOL (__stdcall *PDFStampWriteTextWFunc)(long hPDF, double x, double y, const unsigned short* lpText);
typedef BOOL (__stdcall *PDFStampWriteTextExAFunc)(long hPDF, double x, double y, const char* lpText, long nLen);
typedef BOOL (__stdcall *PDFStampWriteTextExWFunc)(long hPDF, double x, double y, const unsigned short* lpText, long nLen);
typedef BOOL (__stdcall *PDFStampEditPageFunc)(long hPDF, long nPageIndex);
typedef BOOL (__stdcall *PDFStampEndPageFunc)(long hPDF);
typedef long (__stdcall *PDFStampGetPageCountFunc)(long hPDF);
typedef double (__stdcall *PDFStampGetTextWidthAFunc)(long hPDF, const char* lpText);
typedef double (__stdcall *PDFStampGetTextWidthWFunc)(long hPDF, const unsigned short* lpText);
typedef double (__stdcall *PDFStampGetTextWidthExAFunc)(long hPDF, const char* lpText, long nLen);
typedef double (__stdcall *PDFStampGetTextWidthExWFunc)(long hPDF, const unsigned short* lpText, long nLen);

HMODULE                            g_hVeryW=NULL;

VeryStampRegFunc                VeryStampReg            = NULL;
VeryStampOpenFunc                VeryStampOpen            = NULL;
VeryStampLayerOpenFunc            VeryStampLayerOpen        = NULL;
VeryStampCloseFunc                VeryStampClose            = NULL;
VeryStampSetFunctionFunc        VeryStampSetFunction    = NULL;
VeryStampSetFunctionFunc        VeryStampGetFunction    = NULL;
VeryStampAddImageFunc            VeryStampAddImage        = NULL;
VeryStampAddImageExFunc            VeryStampAddImageEx        = NULL;
VeryStampAddTextFunc            VeryStampAddText        = NULL;
VeryStampAddLineFunc            VeryStampAddLine        = NULL;
VeryStampAddRectFunc            VeryStampAddRect        = NULL;
VeryStampAddRectWithLayerFunc    VeryStampAddRectWithLayer = NULL;
VeryStampUndoFunc                VeryStampUndo            = NULL;
VeryStampIsStampedFunc            VeryStampIsStamped        = NULL;
VeryStampAddLineExFunc            VeryStampAddLineEx        = NULL;
VeryStampAddCircleFunc            VeryStampAddCircle        = NULL;
VeryStampAddEllipseFunc            VeryStampAddEllipse        = NULL;
VeryStampAddCurveToFunc            VeryStampAddCurveTo        = NULL;

VeryStampForm_AllocFunc            VeryStampForm_Alloc            = NULL;
VeryStampForm_FreeFunc            VeryStampForm_Free            = NULL;
VeryStampForm_SetTextFieldFunc    VeryStampForm_SetTextField    = NULL;
VeryStampForm_SetCheckBoxFunc    VeryStampForm_SetCheckBox    = NULL;
VeryStampForm_ApplyFunc            VeryStampForm_Apply            = NULL;
VeryStampForm_ClearFieldsFunc    VeryStampForm_ClearFields    = NULL;

VeryStampEncryptPDFFunc            VeryStampEncryptPDF            = NULL;
VeryStampDeleteStampFromPagesFunc    VeryStampDeleteStampFromPages = NULL;
VeryStampDeleteImagesFromPagesFunc    VeryStampDeleteImagesFromPages = NULL;
VeryStampSetLayerPrintFlagFunc        VeryStampSetLayerPrintFlag = NULL;

PDFStampOpenFunc                PDFStampOpen            = NULL;
PDFStampCloseFunc                PDFStampClose            = NULL;
PDFStampSetFontAFunc            PDFStampSetFontA        = NULL;
PDFStampSetFillColorFunc        PDFStampSetFillColor    = NULL;
PDFStampWriteTextAFunc            PDFStampWriteTextA        = NULL;
PDFStampWriteTextWFunc            PDFStampWriteTextW        = NULL;
PDFStampWriteTextExAFunc        PDFStampWriteTextExA    = NULL;
PDFStampWriteTextExWFunc        PDFStampWriteTextExW    = NULL;
PDFStampEditPageFunc            PDFStampEditPage        = NULL;
PDFStampEndPageFunc                PDFStampEndPage            = NULL;
PDFStampGetPageCountFunc        PDFStampGetPageCount    = NULL;
PDFStampGetTextWidthAFunc        PDFStampGetTextWidthA    = NULL;
PDFStampGetTextWidthWFunc        PDFStampGetTextWidthW    = NULL;
PDFStampGetTextWidthExAFunc        PDFStampGetTextWidthExA    = NULL;
PDFStampGetTextWidthExWFunc        PDFStampGetTextWidthExW    = NULL;

typedef struct DLLFUNCtag{
    char *name1;
    char *name2;
    void **func;
}DLLFunc;
DLLFunc aryDLLFunc[] = {
    {"veryReg", "VeryStampReg", (void**)&VeryStampReg},
    {"veryOpen", "VeryStampOpen", (void**)&VeryStampOpen},
    {"veryClose", "VeryStampClose", (void**)&VeryStampClose},
    {"veryAddText", "VeryStampAddText", (void**)&VeryStampAddText},
    {"veryAddImage", "VeryStampAddImage", (void**)&VeryStampAddImage},
    {"veryAddImageEx", "VeryStampAddImageEx", (void**)&VeryStampAddImageEx},
    {"veryAddLine", "VeryStampAddLine", (void**)&VeryStampAddLine},
    {"veryAddLineEx", "VeryStampAddLineEx", (void**)&VeryStampAddLineEx},
    {"veryAddRect", "VeryStampAddRect", (void**)&VeryStampAddRect},
    {"verySetFunction", "VeryStampSetFunction", (void**)&VeryStampSetFunction},
    {"veryGetFunction", "VeryStampGetFunction", (void**)&VeryStampGetFunction},
    {"veryUndo", "VeryStampUndo", (void**)&VeryStampUndo},
    {"veryAddRectWithLayer", "VeryStampAddRectWithLayer", (void**)&VeryStampAddRectWithLayer},
    {"veryAddCircle", "VeryStampAddCircle", (void**)&VeryStampAddCircle},
    {"veryAddEllipse", "VeryStampAddEllipse", (void**)&VeryStampAddEllipse},
    {"veryAddCurveTo", "VeryStampAddCurveTo", (void**)&VeryStampAddCurveTo},
    {"VeryStampLayerOpen", "VeryStampLayerOpen", (void**)&VeryStampLayerOpen},
    {"veryIsStamped", "VeryStampIsStamped", (void**)&VeryStampIsStamped},
    {"VeryStampForm_Alloc", "VeryStampForm_Alloc", (void**)&VeryStampForm_Alloc},
    {"VeryStampForm_Free", "VeryStampForm_Free", (void**)&VeryStampForm_Free},
    {"VeryStampForm_SetTextField", "VeryStampForm_SetTextField", (void**)&VeryStampForm_SetTextField},
    {"VeryStampForm_SetCheckBox", "VeryStampForm_SetCheckBox", (void**)&VeryStampForm_SetCheckBox},
    {"VeryStampForm_Apply", "VeryStampForm_Apply", (void**)&VeryStampForm_Apply},
    {"VeryStampForm_ClearFields", "VeryStampForm_ClearFields", (void**)&VeryStampForm_ClearFields},
    {"VeryStampEncryptPDF", "VeryStampEncryptPDF", (void**)&VeryStampEncryptPDF},
    {"VeryStampDeleteStampFromPages", "VeryStampDeleteStampFromPages", (void**)&VeryStampDeleteStampFromPages},
    {"VeryStampDeleteImagesFromPages", "VeryStampDeleteImagesFromPages", (void**)&VeryStampDeleteImagesFromPages},
    {"VeryStampSetLayerPrintFlag", "VeryStampSetLayerPrintFlag", (void**)&VeryStampSetLayerPrintFlag},

    {"PDFStampOpen", "PDFStampOpen", (void**)&PDFStampOpen},
    {"PDFStampClose", "PDFStampClose", (void**)&PDFStampClose},
    {"PDFStampSetFontA", "PDFStampSetFontA", (void**)&PDFStampSetFontA},
    {"PDFStampSetFillColor", "PDFStampSetFillColor", (void**)&PDFStampSetFillColor},
    {"PDFStampWriteTextA", "PDFStampWriteTextA", (void**)&PDFStampWriteTextA},
    {"PDFStampWriteTextW", "PDFStampWriteTextW", (void**)&PDFStampWriteTextW},
    {"PDFStampWriteTextExA", "PDFStampWriteTextExA", (void**)&PDFStampWriteTextExA},
    {"PDFStampWriteTextExW", "PDFStampWriteTextExW", (void**)&PDFStampWriteTextExW},
    {"PDFStampEditPage", "PDFStampEditPage", (void**)&PDFStampEditPage},
    {"PDFStampEndPage", "PDFStampEndPage", (void**)&PDFStampEndPage},
    {"PDFStampGetPageCount", "PDFStampGetPageCount", (void**)&PDFStampGetPageCount},
    {"PDFStampSetFillColor", "PDFStampSetFillColor", (void**)&PDFStampSetFillColor},
    {"PDFStampGetTextWidthA", "PDFStampGetTextWidthA", (void**)&PDFStampGetTextWidthA},
    {"PDFStampGetTextWidthW", "PDFStampGetTextWidthW", (void**)&PDFStampGetTextWidthW},
    {"PDFStampGetTextWidthExA", "PDFStampGetTextWidthExA", (void**)&PDFStampGetTextWidthExA},
    {"PDFStampGetTextWidthExW", "PDFStampGetTextWidthExW", (void**)&PDFStampGetTextWidthExW},
};

void    GetModulePath(char *out_path,char *in_name);
BOOL    LoadVeryWDll(void);
void    FreeVeryWDll();

void GetModulePath(char *out_path,char *in_name)
{
    char *p;
    GetModuleFileName(NULL,out_path,256);
    p =strrchr(out_path,'\\');
    p[1]=0;
    strcat(out_path,in_name);
}

BOOL LoadVeryWDll()
{
    int i;
    char path[_MAX_PATH];
    GetModulePath(path,"PdfStamp.dll");
    g_hVeryW=LoadLibrary(path);
    if(g_hVeryW==NULL)
    {
        GetModulePath(path,"verywrite.dll");
        g_hVeryW=LoadLibrary(path);
        if(g_hVeryW==NULL)
            goto Failer;
    }

    for(i = 0; i < sizeof(aryDLLFunc)/sizeof(DLLFunc); i++)
    {
        void *lpFunc = (void*)GetProcAddress(g_hVeryW,aryDLLFunc[i].name1);
        if(lpFunc == NULL)
            lpFunc = (void*)GetProcAddress(g_hVeryW,aryDLLFunc[i].name2);
        if(lpFunc)
            *aryDLLFunc[i].func = lpFunc;
        else
            goto Failer;
    }

    return TRUE;
Failer:
    FreeVeryWDll();
    return FALSE;
}

void FreeVeryWDll()
{
    if(g_hVeryW==NULL)
        return ;
    FreeLibrary(g_hVeryW);
    g_hVeryW=NULL;
}

LPBYTE LoadFileIntoMemory(LPCSTR lpFileName,int& nLength)
{
    LPBYTE lpData = NULL;
    size_t size;
    FILE *fp;
    fp = fopen(lpFileName, "rb");
    if (fp == NULL)
        return NULL;
    fseek(fp, 0, SEEK_END);
    size = ftell(fp);
    lpData = (unsigned char *)malloc(size);
    if(lpData == NULL)
    {
        fclose(fp);
        return NULL;
    }
    fseek(fp, 0, SEEK_SET);
    fread(lpData, 1, size, fp);
    fclose(fp);
    nLength = size;
    return lpData;
}

void main(int argc,char* argv[])
{
    char szPDFFile[256] = {0};
    char szOutFile[256] = {0};
    char szTextFile[256] = {0};
    long id;
    int iRet = 0;
   
    GetModulePath(szTextFile,"Arabic.txt");
    int nLength = 0;
    LPBYTE lpData = LoadFileIntoMemory(szTextFile, nLength);
    if(lpData == NULL)
        return;
    if(*lpData == 0xFF && *(lpData+1) == 0xFE)
    {
        lpData += 2;
        nLength -= 2;
    }
/*
    int nWordCount = nLength/2;
    LPWORD lpDataW = (LPWORD)lpData;
    for(int i = 0; i < nWordCount; i++)
    {
        WORD nTmp = lpDataW[i];
        lpDataW[i] = lpDataW[nWordCount-i-1];
        lpDataW[nWordCount-i-1] = nTmp;
    }
*/
    if(!LoadVeryWDll())
        return;
   
    GetModulePath(szPDFFile,"example.pdf");
    GetModulePath(szOutFile,"textstamp_unicode_out.pdf");
   
    //Register PDFStamp SDK with your License Key
    VeryStampReg ("XXXXXXXXXXXXXXXXXXXXX");
   
    id = PDFStampOpen(szPDFFile);
    if (id > 0)
    {
        for(int i = 1; i <= PDFStampGetPageCount(id); i++)
        {
            if(PDFStampEditPage(id,i) == 1)
            {
                int nCodePage = cp1255;
                long nFont = PDFStampSetFontA(id, "Arial Unicode MS", 0, 12, 1, 39);
                PDFStampSetFillColor(id, 0x000000FF);
                double dbTextLen = PDFStampGetTextWidthExW(id,
                         (unsigned short *)lpData, nLength/2);
                BOOL bRet = PDFStampWriteTextExW(id, 100, 200,
                         (unsigned short *)lpData, nLength/2);
                PDFStampEndPage(id);
            }
        }
        PDFStampClose(id, szOutFile);
    }
               
    FreeVeryWDll();
}

VeryPDF

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Related Posts

This entry was posted in PDF Stamp and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!