Home > Products Windows > PDF to TXT Converter


The Functions in PDF to TXT COM Component

1.Functions

//////////////////////////////////////////////
//1.int PDF2TXT(char *szPDFName,char *szTXTName)
//Description:
// Convert PDF file to Text file.
//
//Parameters:
// szPDFName : Input PDF file name
// szTXTName : Output Text file name
//
//Return value:
// 1 : successed
// 0 : failed
//////////////////////////////////////////////
extern "C" __declspec(dllexport) int __stdcall PDF2TXT(char *szPDFName,char *szTXTName);

//////////////////////////////////////////////
//2.int SetTXTFormat(int bFormatTXTFile)
//Description:
// Set text format in generated TXT file.
//
//Parameters:
// bFormatTXTFile : 1 indicate keep text format
// : 0 indicate remove text format
//
//Return value:
// Return previous flag.
//////////////////////////////////////////////
extern "C" __declspec(dllexport) int __stdcall SetTXTFormat(int _bFormatTXTFile);

//////////////////////////////////////////////
//3.int SetZoomRatio(int iZoomRatio)
//Description:
// Set PDF scale options, default is 100, range from 1 to 200.
//
//Parameters:
// iZoomRatio : scale ratio, date range from 1 to 200
//
//Return value:
// Return previous scale ratio.
//////////////////////////////////////////////
extern "C" __declspec(dllexport) int __stdcall SetZoomRatio(int _iZoomRatio);

//////////////////////////////////////////////
//4.void SetPageSeparator(char *pszPageSymbol)
//Description:
// Set page separator.
//
//Parameters:
// pszPageSymbol: page separator, if pszPageSymbol is NULL, the page separator will 
//be removed from the result text file.
//
//Return value:
// none.
//////////////////////////////////////////////
extern "C" __declspec(dllexport) void __stdcall SetPageSeparator(char *pszPageSymbol);

//////////////////////////////////////////////
//5.void SetPageTBMargin(int top, int bottom)
//Description:
// Set page top and bottom margin, top margin is from top side (0 position) up to "top" 
//value, bottom value indicate distance from top (0 position) up to "bottom" value, the valid 
//region is from "top" up to "bottom".
//
//Parameters:
// top : top margin, unit is pixel
// bottom : the distance from top side, unit is pixel, if top and bottom equal -1, the 
//valid region is entire page.
//
//Return value:
// none
//////////////////////////////////////////////
extern "C" __declspec(dllexport) void __stdcall SetPageTBMargin(int top, int bottom);

//////////////////////////////////////////////
//6.void SetOpenResultFile(BOOL IsOpen)
//Description:
// Whether open the text file after it be created.
//
//Parameters:
// IsOpen
// TRUE : The generated text file will be auto opened after it created.
// FALSE: Don't auto open the generated text file.
//
//Return value:
// none
//////////////////////////////////////////////
extern "C" __declspec(dllexport) void __stdcall SetOpenResultFile(BOOL IsOpen);

//////////////////////////////////////////////
//7.void SetDeleteBlankLine(BOOL IsDelete)
//Description:
// Whether delete blank lines from the result text file.
//
//Parameters:
// IsDelete
// TRUE : Delete blank lines from the generated text file.
// FALSE: Don't delete the blank lines.
//
//Return value:
// none
//////////////////////////////////////////////
extern "C" __declspec(dllexport) void __stdcall SetDeleteBlankLine(BOOL IsDelete);

//////////////////////////////////////////////
//8.void SetGetDocumentSummary(BOOL IsGetSummary)
//Description:
// Whether read the document summary from the pdf file.
//
//Parameters:
// IsGetSummary
// TRUE : Read document summary from the pdf file.
// FALSE: Don't read the document summary.
//
//Return value:
// none
//////////////////////////////////////////////
extern "C" __declspec(dllexport) void __stdcall SetGetDocumentSummary(BOOL IsGetSummary);

//////////////////////////////////////////////
//9.const char* PDF2TextBuffer(LPCTSTR pdfFile, int *textBufferSize)
//Description:
// Convert a pdf file to a text buffer.
//
//Parameters:
// pdfFile : input pdf filename
// textBufferSize : the size of the return buffer
//
//Return value:
// Point to a text buffer, after you used it, you need use PDF2TextFreeBuffer function to free it.
//////////////////////////////////////////////
extern "C" __declspec(dllexport) const char* __stdcall PDF2TextBuffer(LPCTSTR pdfFile, int *textBufferSize);

//////////////////////////////////////////////
//10.const char* PDFBuffer2TextBuffer(const char* pdfBuffer, int pdfBufferSize,int *textBufferSize)
//Description:
// Convert a pdf buffer to a text buffer.
//
//Parameters:
// pdfBuffer : the pdf file contents
// pdfBufferSize : the size of the pdfBuffer
// textBufferSize : the size of the return buffer
//
//Return value:
// Point to a text buffer, after you used it, please use PDF2TextFreeBuffer function to free it.
//////////////////////////////////////////////
extern "C" __declspec(dllexport) 
const char* __stdcall PDFBuffer2TextBuffer(const char* pdfBuffer, int pdfBufferSize,int *textBufferSize);

//////////////////////////////////////////////
//11.void PDF2TextFreeBuffer(const char* textBuffer)
//Description:
// Free the text buffer
//
//Parameters:
// textBuffer : this paramter is returned by PDF2TextBuffer and PDFBuffer2TextBuffer functions
//
//Return value:
// none.
//////////////////////////////////////////////
extern "C" __declspec(dllexport) void __stdcall PDF2TextFreeBuffer(const char* textBuffer);


2.C++ examples for PDF2TXT COM Component

Convert PDF file to text file:

   
void ConvertPDFFile2TextFile(char *pdffile, char *textfile)
    {
        SetPageSeparator("<<<<<<<<<********>>>>>>>>>>>>>");
        SetZoomRatio(100);
        SetTXTFormat(1);
        SetOpenResultFile(1);
        SetDeleteBlankLine(TRUE);
        PDF2TXT(pdffile,textfile);
    }

Convert PDF file to text buffer:

    void ConvertPDFFile2TextBuffer(char *pdffile, char *textfile)
    {
        SetPageSeparator("<<<<<<<<<********>>>>>>>>>>>>>");
        SetZoomRatio(100);
        SetTXTFormat(1);
        SetOpenResultFile(0);
        SetDeleteBlankLine(TRUE);
        int textBufferSize;
        const char *textbuffer = PDF2TextBuffer(pdffile,&textBufferSize);
        if(textbuffer)
            printf("%s\n",textbuffer);
        PDF2TextFreeBuffer(textbuffer);
    }

Convert PDF buffer to Text buffer:

    void ConvertPDFBuffer2TextBuffer(char *pdffile, char *textfile)
    {
        ......
        ......
        ......
        SetPageSeparator("<<<<<<<<<********>>>>>>>>>>>>>");
        SetZoomRatio(100);
        SetTXTFormat(1);
        SetOpenResultFile(0);
        SetDeleteBlankLine(TRUE);

        int textBufferSize;
        const char *textbuffer = PDFBuffer2TextBuffer(pdfBuffer,m_iFileLength,&textBufferSize);
        if(textbuffer)
            printf("%s\n",textbuffer);
        PDF2TextFreeBuffer(textbuffer);

        delete []pdfBuffer;
    }


3.Technology support

    Main site,
    http://www.verypdf.com/
    Mirror sites,
    http://www.toppdf.com/
    http://www.globalpdf.com/

    If you encounter any problems, please don't hesitate to contact us at support@verypdf.com, thank you.