Add barcode text into PDF file by PDFStamp SDK product

using PDFStampCom;

#region InsertBarcode
public bool InsertBarcode(string pdfDstTranFilePath, string strInsertBarcodeFilePath, string strBarcodeEncodeString, string strBarcodeImagePath, string strDestBarcodeFileName, string strPolicyNumber, string v_Batch_No, string v_Batch_Date, string v_Destination, string v_PageNumber, string v_Doc_Separator_Code, int v_POTransactionFK, string strCopyType, string v_EmtyPagePath, string strPRFormID, string v_strBarcodeType, string v_DataBaseServer, string v_DataBase, string v_UserName, string v_Password)
        {
            try
            {
                if (File.Exists(pdfDstTranFilePath))
                {
                    TotalPageCount = 0;
                    BarcodePageNo = Convert.ToInt32(v_PageNumber);

                    //New Tool
                    //A COM reference is set for PDFStampCom
                    PDFStampCom.CPDFStamp pdfstamp = new PDFStampCom.CPDFStamp();

                   //Open the original PDF file and the New PDF file that will have the
                   //barcode added to it
                    int pdfstamp_id = pdfstamp.veryOpenEx(pdfDstTranFilePath, strInsertBarcodeFilePath);

                int pagecount = pdfstamp.veryGetFunctionEx(id, Very_Get_PdfPageCount, 0, 0, null, null);
                for (int Page = 1; Page <= pagecount; Page++)
                {
                    string strStampBuf;
                    long left, top, pagewidth, pageheight;

                    left = pdfstamp.veryGetFunctionEx(id, Very_Get_PageBoxForStamp, Page, 0, "left", null);
                    top = pdfstamp.veryGetFunctionEx(id, Very_Get_PageBoxForStamp, Page, 0, "top", null);
                    pagewidth = pdfstamp.veryGetFunctionEx(id, Very_Get_PageBoxForStamp, Page, 0, "width", null);
                    pageheight = pdfstamp.veryGetFunctionEx(id, Very_Get_PageBoxForStamp, Page, 0, "height", null);
                   
                    //We need to control which pages the stamp goes on
                    int iRet = pdfstamp.verySetFunctionEx(id, Very_Set_Range, Page, 1, null, null);
                    strStampBuf = "Page:" + (pagecount - Page + 1).ToString() + ", Page Box: [" + left.ToString() + " " + top.ToString() + " " + pagewidth.ToString() + " " + pageheight.ToString() + "]";
                   
                    // Barcode data to encode
                    strBarcodeString = strBarcodeEncodeString + v_strPageNumber + "*";
                    strBarcodeString = strBarcodeString.Replace("*", "");
                   
                    int status = 0;
                                       
                    //Signal PDFStamp to embed the barcode font into the PDF file
                    //If this isn't called, the system viewing the file must have the
                    //FONT_CODE39 installed
                    status = pdfstamp.verySetFunctionEx(pdfstamp_id, Convert.ToInt32(ESetFunctionCode.EmbeddFont), 1, NO_OP, NO_OP.ToString(), NO_OP.ToString());

                    //Set the page(s) that get the barcode will affect
                    //If this isn't called, all pages will get the barcode!
                    //status = pdfstamp.verySetFunctionEx(pdfstamp_id, Convert.ToInt32(ESetFunctionCode.PageRange), 1, NO_PAGES_TO_STAMP, NO_OP.ToString(), NO_OP.ToString());

                    //Add the barcode to the specified pages of the PDF file
                    status = pdfstamp.veryAddTextEx(pdfstamp_id, Convert.ToInt32(EPosition.Left_Center), "*" + strBarcodeString + "*", int.Parse(COLOR_BLACK, System.Globalization.NumberStyles.AllowHexSpecifier), LEFT_ALIGN, Convert.ToInt32(-5), Convert.ToInt32(0), ROTATE_90, Convert.ToInt32(ELayer.Overlay), HOLLOW_SOLID, NO_OP, FONT_CODE39, FONT_SIZE, Convert.ToInt32(EAction.None), "", NO_OP);
                                }

                    //'The commented code below proves a barcode can be placed on multiple
                    //' pages between a single open/close.
                    //'
                    //'set the page to 3, assuming 1 was entered via the form
                    //status = pdfstamp.verySetFunctionEx( _
                    //                                    pdfstamp_id, _
                    //                                    ESetFunctionCode.PageRange, _
                    //                                    3, _
                    //                                    NO_PAGES_TO_STAMP, _
                    //                                    NO_OP, _
                    //                                    NO_OP _
                    //                                   )

                    //'Add the exact same barcode to the PDF file for page 3
                    //'This is a test to determine that VeryPDF can hit multiple pages in one
                    //'  open/close session
                    //'Important: In reality, portions of the barcode will change for page 3 and
                    //' that will need to be reflected in the barcode text being added.
                    //status = _
                    //    pdfstamp.veryAddTextEx( _
                    //                            pdfstamp_id, _
                    //                            EPosition.Left_Center, _
                    //                            "*" & tx_barcode_text.Text & "*", _
                    //                            Integer.Parse(COLOR_BLACK, Globalization.NumberStyles.AllowHexSpecifier), _
                    //                            LEFT_ALIGN, _
                    //                            Convert.ToInt32(tx_lr_adj.Text), _
                    //                            Convert.ToInt32(tx_tb_adj.Text), _
                    //                            ROTATE_90, _
                    //                            ELayer.Overlay, _
                    //                            HOLLOW_SOLID, _
                    //                            NO_OP, _
                    //                            FONT_CODE39, _
                    //                            FONT_SIZE, _
                    //                            EAction.None, _
                    //                            "", _
                    //                            NO_OP _
                    //                           )

                    //Close the PDF file
                    pdfstamp.veryCloseEx(pdfstamp_id);

                }
                   
                if (File.Exists(pdfDstTranFilePath))
                {
                    File.Delete(pdfDstTranFilePath);
                }
                //if (File.Exists(strSrcBarcodeFilePath))
                //{
                //    strDestBarcodeFileName = strBarcodePath + strSrcBarcodeFileName;
                //    File.Copy(strSrcBarcodeFilePath, strDestBarcodeFileName, true);
                //    File.Delete(strSrcBarcodeFilePath);
                //    File.Delete(pdfDstTranFilePath);
                //    File.Delete(strBarcodeImagePath);
                //}
            }
            catch (Exception ex)
            {
                m_objQsTrace.Trace_Information(ex);
            }
            return true;
        }
        #endregion

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