PDF Form Filler, VeryPDF Blog

Suppprt Barcode Generation in PDF Form Filler SDK product

#ifndef __PDFFORMFUNC_H__
#define __PDFFORMFUNC_H__

#include <windows.h>

#ifdef __cplusplus
extern "C" {
#endif

#define EXTERN __declspec(dllexport)

//PDFForm_SetLicenseKey
//Parameters:
//  lpLicenseKey: a License Key which issued by VeryPDF
EXTERN void WINAPI PDFForm_SetLicenseKey(LPCTSTR lpLicenseKey);

//PDFForm_MergeFDFIntoPDF
//  Merge FDF file into an existing PDF file and generate a new filled PDF file.
//Parameters:
//  lpInPDF: input PDF file
//  lpInFDF: input FDF file
//  lpOutPDF: merged PDF file
//Return value:
//  TRUE is success, FALSE is fail
EXTERN BOOL WINAPI PDFForm_MergeFDFIntoPDF(LPCTSTR lpInPDF, LPCTSTR lpInFDF, LPCTSTR lpOutPDF);
EXTERN BOOL WINAPI PDFForm_MergeXFDFIntoPDF(LPCTSTR lpInPDF, LPCTSTR lpInFDF, LPCTSTR lpOutPDF);

//PDFForm_ExtractFDFFromPDF
//  Extract FDF file from a filled PDF file.
//Parameters:
//  lpInPDF: input PDF file
//  lpOutFDF: output FDF file
//Return value:
//  TRUE is success, FALSE is fail
EXTERN BOOL WINAPI PDFForm_ExtractFDFFromPDF(LPCTSTR lpInPDF, LPCTSTR lpOutFDF);
//PDFForm_FlattenPDF
//  Flatten a form filled PDF file
//Parameters:
//  lpInPDF: input PDF file
//  lpOutPDF: output PDF file
//Return value:
//  TRUE is success, FALSE is fail
EXTERN BOOL WINAPI PDFForm_FlattenPDF(LPCTSTR lpInPDF, LPCTSTR lpOutPDF);

//PDFForm_EncryptPDF
//  Encrypt a PDF file.
//Parameters:
//  lpInPDF: input PDF file
//  lpUserPwd: user password
//  lpOwnerPwd: owner password
//  lpPermissions: permissions, it can be following values,
//     Printing // top quality printing
//     ModifyContents = ModifyContents | Assembly
//     Copy = Copy | ScreenReaders
//     ModifyAnnotations = ModifyAnnotations | FillIn
//     FillIn
//     ScreenReaders
//     Assembly
//     DegradedPrinting
//  nKeyLen: 128 or 40 bits
//  lpOutPDF: output PDF file
//Return value:
//  TRUE is success, FALSE is fail
EXTERN BOOL WINAPI PDFForm_EncryptPDF(LPCTSTR lpInPDF, LPCTSTR lpUserPwd, LPCTSTR lpOwnerPwd, LPCTSTR lpPermissions,
int nKeyLen, LPCTSTR lpOutPDF);

//PDFForm_Alloc
//Return value:
// 0 is an error, other values are valid ID.
EXTERN long WINAPI PDFForm_Alloc();
//PDFForm_Free
//Parameters:
//  id: a valid ID returned by PDFForm_Alloc() function
//
//Return value:
//  0 is success, other values are indicate an error
EXTERN long WINAPI PDFForm_Free(long id);

//PDFForm_SetTextField
//Parameters:
//  id: a valid ID returned by PDFForm_Alloc() function
//  lpFieldName: form field name
//  lpFieldValue: form field value
//
//Return value:
//  if return value less than zero, it is indicate an error,
//  if return value large than zero, it is the number of form fields in the list
EXTERN long WINAPI PDFForm_SetTextField(long id, LPCTSTR lpFieldName, LPCTSTR lpFieldValue);

//PDFForm_SetCheckBox
//Parameters:
//  id: a valid ID returned by PDFForm_Alloc() function
//  lpFieldName: form field name
//  lpFieldValue: form field value
//
//Return value:
//  if return value less than zero, it is indicate an error,
//  if return value large than zero, it is the number of form fields in the list
EXTERN long WINAPI PDFForm_SetCheckBox(long id, LPCTSTR lpFieldName, LPCTSTR lpFieldValue);

//PDFForm_Apply
//Parameters:
//  id: a valid ID returned by PDFForm_Alloc() function
//  lpInFile: input PDF file
//  lpOutFile: output PDF file
//  bFlatten: make the output file flatten or not
//
//Return value:
//  0 is success, other values are indicate an error
//  -6: create FDF file error
//  -7: import form data into PDF file error
//  -8: flatten filled PDF file error
EXTERN long WINAPI PDFForm_Apply(long id, LPCTSTR lpInFile, LPCTSTR lpOutFile, LONG bFlatten);

//PDFForm_ClearFields
//Parameters:
//  id: a valid ID returned by PDFForm_Alloc() function
//
//Return value:
//  0 is success, other values are indicate an error
EXTERN long WINAPI PDFForm_ClearFields(long id);

//PDFForm_RepairFormFonts
//Repair fonts layout in PDF forms
//Parameters:
//  lpInPDF: input PDF file
//  lpOutFDF: output FDF file
//Return value:
//  TRUE is success, FALSE is fail
EXTERN BOOL WINAPI PDFForm_RepairFormFonts(LPCTSTR lpInPDF, LPCTSTR lpOutPDF);
//PDFForm_InsertDataMatrixImageIntoPDF
//Insert DataMatrix Image Into PDF file
//Parameters:
//  lpInPDF: input PDF file
//  lpOutFDF: output FDF file
//  lpFormName: DataMatrix form name
//  lpBarcodeText: Barcode text
//Return value:
//  TRUE is success, FALSE is fail
//
//int bRet = PDFForm_InsertDataMatrixImageIntoPDF("C:\\test.pdf", "C:\\out.pdf", "Datamatrix", "01034009377771791712073110BXBWWW22");
EXTERN BOOL WINAPI PDFForm_InsertDataMatrixImageIntoPDF(LPCTSTR lpInFile, LPCTSTR lpOutFile, LPCTSTR lpFormName, LPCTSTR lpBarcodeText);

//PDFForm_InsertBarcodeIntoPDF
//Insert Barcode into PDF file
//Parameters:
//  lpInPDF: input PDF file
//  lpOutFDF: output FDF file
//  lpFormName: Barcode form name
//  lpFormType: Barcode type, lpFormType supports following CodeType:
//   private enum CodeType
//   {
//    Code128,
//    Code39,
//    Codabar,
//    Datamatrix,
//    EAN,
//    Inter25,
//    PDF417,
//    Postnet
//   }
//  lpFormValue: Barcode text
//Return value:
//  TRUE is success, FALSE is fail
//
EXTERN BOOL WINAPI PDFForm_InsertBarcodeIntoPDF(LPCTSTR lpInFile, LPCTSTR lpOutFile, LPCTSTR lpFormName, LPCTSTR lpFormType, LPCTSTR lpFormValue);

//PDFForm_InsertBarcodeIntoPDF2
//Insert Barcode into PDF file
//Parameters:
//  lpInPDF: input PDF file
//  lpOutFDF: output FDF file
//  lpFormValues: Parameters FieldIdBarcode, TypeBarcode, FieldValueBarcode as a string-list (separated by for example newline).
//   Then we would do ONE call instead of n-times calling the proc with
//   the n as the number of special fields
//  Barcode type supports following CodeType:
//   private enum CodeType
//   {
//    Code128,
//    Code39,
//    Codabar,
//    Datamatrix,
//    EAN,
//    Inter25,
//    PDF417,
//    Postnet
//   }
//Return value:
//  TRUE is success, FALSE is fail
//
//e.g.,
//
//string strFormValues;
//strFormValues += "BarCode1[0]=>Code128=>1234567890";
//strFormValues += "\n";
//strFormValues += "BarCode2[0]=>Code39=>1234567890";
//strFormValues += "\n";
//strFormValues += "BarCode3[0]=>Codabar=>A1234567890A";
//PDFForm_InsertBarcodeIntoPDF2("C:\\test.pdf", "C:\\out.pdf", strFormValues.c_str());
//
EXTERN BOOL WINAPI PDFForm_InsertBarcodeIntoPDF2(LPCTSTR lpInFile, LPCTSTR lpOutFile, LPCTSTR lpFormValues);

#ifdef __cplusplus
}
#endif

#endif

//Example code 1:

#include <windows.h>
#include "../vc++/pdfformfunc.h"
#include <io.h>
#include <stdio.h>

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);
}

void main(int argc, char *argv[])
{
char szBarcodeTemp[MAX_PATH];
GetModulePath(szBarcodeTemp, "Barcode-temp.pdf");
char szBarcodeNew[MAX_PATH];
GetModulePath(szBarcodeNew, "_Barcode-out.pdf");
CopyFile(szBarcodeTemp, szBarcodeNew, FALSE);

BOOL bRet = FALSE;
PDFForm_SetLicenseKey("XXXXXXXXXXXXXXXXXXXXX");
bRet = PDFForm_InsertBarcodeIntoPDF(szBarcodeNew, szBarcodeNew, "BarCode1[0]", "Code128", "1234567890");
bRet = PDFForm_InsertBarcodeIntoPDF(szBarcodeNew, szBarcodeNew, "BarCode2[0]", "Code39", "1234567890");
bRet = PDFForm_InsertBarcodeIntoPDF(szBarcodeNew, szBarcodeNew, "BarCode3[0]", "Codabar", "A1234567890A");
bRet = PDFForm_InsertBarcodeIntoPDF(szBarcodeNew, szBarcodeNew, "BarCode4[0]", "Datamatrix", "01034009377771791712073110BXBWWW22");
bRet = PDFForm_InsertBarcodeIntoPDF(szBarcodeNew, szBarcodeNew, "BarCode5[0]", "EAN", "01234567890100");
bRet = PDFForm_InsertBarcodeIntoPDF(szBarcodeNew, szBarcodeNew, "BarCode6[0]", "Inter25", "123456789");
bRet = PDFForm_InsertBarcodeIntoPDF(szBarcodeNew, szBarcodeNew, "BarCode7[0]", "PDF417", "1234567890");
bRet = PDFForm_InsertBarcodeIntoPDF(szBarcodeNew, szBarcodeNew, "BarCode8[0]", "Postnet", "1234567890");
printf("Return value is: %d\n", bRet);
return;
}

===================================

Example code 2:

#include <windows.h>
#include "../vc++/pdfformfunc.h"
#include <io.h>
#include <stdio.h>
#include <string>
using namespace std;

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);
}

void main(int argc, char *argv[])
{
char szBarcodeTemp[MAX_PATH];
GetModulePath(szBarcodeTemp, "Barcode-temp.pdf");
char szBarcodeNew[MAX_PATH];
GetModulePath(szBarcodeNew, "_Barcode-out2.pdf");

BOOL bRet = FALSE;
PDFForm_SetLicenseKey("XXXXXXXXXXXXXXXXXXXXX");

string strFormValues;
strFormValues += "BarCode1[0]=>Code128=>1234567890";
strFormValues += "\n";
strFormValues += "BarCode2[0]=>Code39=>1234567890";
strFormValues += "\n";
strFormValues += "BarCode3[0]=>Codabar=>A1234567890A";
strFormValues += "\n";
strFormValues += "BarCode4[0]=>Datamatrix=>01034009377771791712073110BXBWWW22";
strFormValues += "\n";
strFormValues += "BarCode5[0]=>EAN=>01234567890100";
strFormValues += "\n";
strFormValues += "BarCode6[0]=>Inter25=>123456789";
strFormValues += "\n";
strFormValues += "BarCode7[0]=>PDF417=>1234567890";
strFormValues += "\n";
strFormValues += "BarCode8[0]=>Postnet=>1234567890";
bRet = PDFForm_InsertBarcodeIntoPDF2(szBarcodeTemp, szBarcodeNew, strFormValues.c_str());

printf("Return value is: %d\n", bRet);
return;
}
============================================

I tried the new dll but had a problem to call the function, although I do exactly the same (I think so)
as I did with using BarcodeIntoPDF when I got it in the first release.
In the document I screenshoted the message and the .dll and .lib version info. I think PDFFom.dll / PDFform.lib are the only changed files ?!

And that is the .NET-program-source I'm using.
================================
Sorry for the mistake, the new pdfform.dll file does contain “_PDFForm_InsertBarcodeIntoPDF2@12” function name, this is wrong, we have corrected this problem in the new pdfform.dll file just now, please download new DLL file from following URL to try again,

XXXXXXXXXXXXXXXX

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)
PDFStamp Command Line

veryAddTextEx questions

Hello VeryPDF Support,

Is it possible to set the backcolor of a text stamp?  We have an instance where the desired font color is black and the entire document is redacted making it black as well, so the stamp is not visible (please see “black.pdf”).

In another instance, we have seen unusually large stamp on an image (please see “zoom.pdf”).  Is there a setting to alleviate this from happening?   We’re using veryAddTextEx().
Thank you!
===========================
>>Is it possible to set the backcolor of a text stamp?  We have an instance where the
>>desired font color is black and the entire document is redacted making it black as
>>well, so the stamp is not visible (please see “black.pdf”).

You can use following code to stamp your PDF file, please refer to an example "black-out.pdf" file in attachment, this PDF file is stamped by following code, if you wish hide this text, you can simple set font color to black, then you will not able to see the text stamp,

~~~~~~~~~~~~~~~~
 id=oTest.veryOpenEx(strInPDF, strOutPDF)
 if id>0 then
  '% Every even page%
  'oTest.verySetFunctionEx id, 131, -2, -2, 0,0
 
  oTest.veryAddTextEx id, 2, _
      "This is a test.", _
      2666666,17, _
      0,200,0,0, _
      0, _
      0,0,32, _
      0,0,0
  oTest.veryCloseEx id
~~~~~~~~~~~~~~~~

>>In another instance, we have seen unusually large stamp on an image (please see “zoom.pdf”). 
>>Is there a setting to alleviate this from happening?   We’re using veryAddTextEx().

This is because the paper size in your PDF file is too small, please reduce the font size to 10 or 5 to try again, then you will able to stamp this PDF file correctly.

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)
PDF Split-Merge

split a PDF by the bookmarks and name the new files using the bookmarks

We are interested in your product, however I have a question. Is it possible to split a PDF by the bookmarks and name the new files using the bookmarks?
=============================
You can use "bookmark" or "bookmark2" option to name the output PDF files,

bookmark    : split PDF file by bookmarks, append page number to filenames
bookmark2   : split PDF file by bookmarks, without page number in filenames

for example,

"C:\Program Files\VeryPDF PDF Split-Merge v3.0\pdfpg.exe" bookmark C:\A.pdf C:\split
"C:\Program Files\VeryPDF PDF Split-Merge v3.0\pdfpg.exe" bookmark2 C:\A.pdf C:\
"C:\Program Files\VeryPDF PDF Split-Merge v3.0\pdfpg.exe" bookmark2 C:\A.pdf C:\out\

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)
Spool File Page Counter SDK

Counting the exact number of pages in any PDF document

Counting the exact number of pages in any PDF document

'-----------------------------------------------------------------
' IF you have ability then for PDF 1.3 version also
' Open file  pdf in binarymode
' Read last 50 lines of that file
' In between somewhere u will find a line
'   "/count xx" pages the xx is # of pages

'MADE ON 14TH AUG 06
'-----------------------------------------------------------------------
' open the PDF  in binary mode & count the pages
' search for "/N  xx"
'             or "/Count xx"

Public Sub pagecount(sfilename As String)
On Error GoTo a
Dim nFileNum As Integer
Dim s As String
Dim c As Integer
Dim pos, pos1 As Integer
pos = 0
pos1 = 0
c = 0
' Get an available file number from the system
nFileNum = FreeFile
'OPEN the PDF file in Binary mode
Open sfilename For Binary Lock Read Write As #nFileNum
  ' Get the data from the file
  Do Until EOF(nFileNum)
    Input #1, s
    c = c + 1
    If c <= 10 Then
        pos = InStr(s, "/N")
    End If
    pos1 = InStr(s, "/count")
       If pos > 0 Or pos1 > 0 Then
            Close #nFileNum
            s = Trim(Mid(s, pos, 10))
            s = Replace(s, "/N", "")
            s = Replace(s, "/count", "")
            s = Replace(s, " ", "")
            s = Replace(s, "/", "")
            For i = 65 To 125
                    s = Replace(s, Chr(i), "")
            Next
            pages = Val(Trim(s))
            If pages < 0 Then
                pages = 1
            End If
            Close #nFileNum
            Exit Sub
        End If
        'imp only 1000 lines searches
        If c >= 1000 Then
             GoTo a
        End If
  Loop
    Close #nFileNum
    Exit Sub
a:
    Close #nFileNum
    pages = 1
    Exit Sub
End Sub
============================================
I actually went with a combined approach. Since I have exec disabled on my server I wanted to stick with a PHP based solution, so ended up with this:

Code:

function getNumPagesPdf($filepath){
    $fp = @fopen(preg_replace("/\[(.*?)\]/i", "",$filepath),"r");
    $max=0;
    while(!feof($fp)) {
            $line = fgets($fp,255);
            if (preg_match('/\/Count [0-9]+/', $line, $matches)){
                    preg_match('/[0-9]+/',$matches[0], $matches2);
                    if ($max<$matches2[0]) $max=$matches2[0];
            }
    }
    fclose($fp);
    if($max==0){
        $im = new imagick($filepath);
        $max=$im->getNumberImages();
    }

    return $max;
}
If it can't figure things out because there are no Count tags, then it uses the imagick php extension. The reason I do a two-fold approach is because the latter is quite slow.
==================================================
Try this :

<?php
if (!$fp = @fopen($_REQUEST['file'],"r")) {
        echo 'failed opening file '.$_REQUEST['file'];
}
else {
        $max=0;
        while(!feof($fp)) {
                $line = fgets($fp,255);
                if (preg_match('/\/Count [0-9]+/', $line, $matches)){
                        preg_match('/[0-9]+/',$matches[0], $matches2);
                        if ($max<$matches2[0]) $max=$matches2[0];
                }
        }
        fclose($fp);
echo 'There '.($max<2?'is ':'are ').$max.' page'.($max<2?'':'s').' in '. $_REQUEST['file'].'.';
}
?>

The Count tag shows the number of pages in the different nodes. The parent node has the sum of the others in its Count tag, so this script just looks for the max (that is the number of pages).

You can also use Spool File Page Counter SDK to count the pages in PDF file, Spool File Page Counter SDK can be downloaded from following web page,

http://www.verydoc.com/spool-page-count.html

Advanced PDF Tools Command Line has ability to count the PDF pages too, Advanced PDF Tools Command Line can be downloaded from following web page,

http://www.verypdf.com/pdfinfoeditor/index.html#dl

VN:F [1.9.20_1166]
Rating: 9.0/10 (1 vote cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)
docPrint Pro

A4 be changed to Letter, Layout was changed after convertion

Dear Support team,

When we convert the document in Excel to PDF file using docPrint Pro v5.0, the margin is increased and contents shrinks. The paper size of original Excel document is "A4". Please kindly advice how we can convert the Excel to PDF without changing the original page setting in Excel. Is there any setting change required to retain the Excel format?

Thank you for your support in advance.
================================
Can you please let us know what version of MS Excel are you using? MS Excel 2003 does change the paper size from A4 to Letter during printing, if you are using MS Excel 2003, we suggest you may upgrade it to MS Excel 2007 or 2010 to try again, we hoping MS Excel 2007 or 2010 will work better for you.

If you are prefer to use MS Excel 2003, you can force to select A4 paper size on the docPrint PDF Driver, then you can print your Excel to docPrint PDF Driver to create a new PDF file at A4 paper, we hoping this solution will work fine for you too.

VeryPDF
=================================
It worked fine when we selected the A4 paper on the docPrint PDF Driver and changed page setting.

Thank you very much for the advice.
VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)