BCL easyConverter SDK Word
easyConverter SDK Usermanual
PDF-to-Word Programming API  |  Download Free Trial  |  Contact Us to Purchase

ConvertToWord2 Method

Convert a PDF document to an Word stream. The Word output is stored in memory.

byte[] ConvertToWord2(string InputFileName,
                      string Password,
                      int From,
                      int To)

Function ConvertToWord2(InputFileName As String(),
                        Password As String,
                        From As Integer,
                        To As Integer)
                        As Byte()
def ConvertToWord2(self, strInputFileName, strPassword, intFrom, intTo)




byte[] ConvertToWord2(String InputFileName,
                      String Password,
                      int From,
                      int To) throws PDF2WordException

function ConvertToWord2($strInputFileName, $strPassword, $intFrom, $intTo)




BclWdhrError ConvertToWord2(BclPDF2Word * pPdf2Word,
                            const wchar_t * InputFileName,
                            const wchar_t * Password,
                            int From, int To,
                            unsigned char * * pOutStream, unsigned * pOutStreamSize);
Function ConvertToWord2(InputFileName As String,
                        [Password] As Variant,
                        [From] As Variant,
                        [To] As Variant)
                        As Variant

Parameters

InputFileName

Input file name in absolute path format.

Password (optional)

Password to open the PDF document if any.

From (optional)

The starting page number to convert.

To (optional)

The ending page number to convert.

Return Values

Word Stream.

Exception Handling

Please refer to the list of return exceptions.

Example Usage

using BCL.easyConverter.Word;
...
PDF2Word pdf2word = new PDF2Word();
try
{
   pdf2word.OutputDocumentFormat = optOutputDocumentFormat.OPT_OUTPUT_DOCX;
   byte[] outputStream = pdf2word.ConvertToWord2(@"c:\test\input.pdf");
   System.IO.File.WriteAllBytes(@"c:\test\output.docx", outputArray);
}
catch(PDF2WordException ex)
{
   Console.WriteLine(ex.Message);
}
finally
{
   pdf2word.Dispose();
}
Imports BCL.easyConverter.Word
...
Dim pdf2word As New PDF2Word()
Dim inputStream As Byte()
Dim outputStream As Byte()
Try
   pdf2word.OutputDocumentFormat = optOutputDocumentFormat.OPT_OUTPUT_DOCX
   outputStream = pdf2word.ConvertToWord2("c:\test\input.pdf")
   System.IO.File.WriteAllBytes("c:\test\output.docx", outputArray)
Catch ex As PDF2WordException
   System.Console.WriteLine(ex.Message)
Finally
   pdf2word.Dispose()
End Try
import PDF2Word

def file_put_contents(filename, data):
   f = open(filename, "wb")
   try:
      f.write(data)
   finally:
      f.close()

pdf2word = PDF2Word.PDF2Word()
try:
   inputFilename = "c:\\test\\input.pdf"
   outputFilename = "c:\\temp\\output.docx"
   pdf2word.setOutputDocumentFormat(PDF2Word.optOutputDocumentFormat.OPT_OUTPUT_DOCX)
   outputStream = pdf2word.ConvertToWord2(inputFilename)
   file_put_contents(outputFilename, outputStream)
except PDF2Word.PDF2WordException as ex:
   print(ex)
PDF2Word pdf2word = new PDF2Word();
try
{
   pdf2word.setOutputDocumentFormat(optOutputDocumentFormat.OPT_OUTPUT_DOCX);
   byte[] byteArrOutput = pdf2word.ConvertToWord2("c:\\test\\input.pdf", "", 0, -1);
   File fileout = new File("c:\\test\\output.docx");
   FileOutputStream fos = new FileOutputStream(fileout.getCanonicalPath());
   fos.write(byteArrOutput);
   fos.close();
}
catch(PDF2WordException e)
{
   System.out.println(e);
}
finally
{
   pdf2word.dispose();
}
<?php
require("PDF2Word.php");
$pdf2word = new BCL\easyConverter\Word\PDF2Word();
try
{
   $inputFilename = "c:\\test\\input.pdf";
   $outputFilename = "c:\\temp\\output.docx";
   $pdf2word->setOutputDocumentFormat(BCL\easyConverter\Word\optOutputDocumentFormat::OPT_OUTPUT_DOCX);
   $outputStream = $pdf2word->ConvertToWord2($inputFilename);
   file_put_contents($outputFilename, $outputStream);
}
catch(BCL\easyConverter\Word\PDF2WordException $ex)
{
   echo $ex->getMessage(), "\n";
}
?>
#include <stdio.h>
#include <windows.h>
#include "easyConverter.h"

int main()
{
   HMODULE hPDF2WordDll = LoadLibraryW(L"C:\\Program Files\\BCL Technologies\\easyConverter SDK 5\\Rtf\\easyConverter.dll");
   if(!hPDF2WordDll)
   {
      printf("easyConverter could not be loaded.\n");
      return 1;
   }
   else
   {
      BclWdhrError error;
      BclPDF2Word* pPdf2Word = CreatePDF2Word(hPDF2WordDll);
      if(!pPdf2Word)
      {
         printf("easyConverter could not be initialized.\n");
         FreeLibrary(hPDF2WordDll);
         return 1;
      }

      unsigned char* pOutputStream = NULL;
      unsigned outputSize = 0;

      pPdf2Word-<OutputDocumentFormat = BCL_WD_OPT_OUTPUT_DOCX;
      error = pPdf2Word->ConvertToWord2(pPdf2Word, L"c:\\test\\input.pdf", L"", 0, -1, &pOutputStream, &outputSize);
      if(error)
      {
         printf("Conversion failed with error %d.\n", error);
         FreeLibrary(hPDF2WordDll);
         return 1;
      }

      FILE* fout = fopen("c:\\test\\output.docx", "wb");
      fwrite(pOutputStream, 1, outputSize, fout);
      fclose(fout);

      // Note: there is no need to free(pOutputStream), Dispose takes care of that.
      pPdf2Word->Dispose(pPdf2Word);
      FreeLibrary(hPDF2WordDll);
      return 0;
   }
}
On Error GoTo Convert_Err

        oConverter = CreateObject("EasyConverter.PDF2Word.5")
        arrWord = oConverter.ConvertToWord2(inFileName)

        ' Save binary data To disk using ADO stream object
        Set oADO = CreateObject("ADODB.Stream")
        oADO.Type = 1 ' 1: adTypeBinary
        oADO.Open
        oADO.Write arrWord
        Call oADO.SaveToFile("C:\test\output.docx", 2) ' 2: adSaveCreateOverwrite
        oADO.Close

        MsgBox("Success", vbOKOnly + vbInformation)

Convert_End:

        oConverter = Nothing
        Exit Sub

Convert_Err:

        ' Handle error
         MsgBox("Error(" + CStr(Err.Number) + ")", vbOKOnly + vbInformation)

        Resume Convert_End