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

ConvertToWord3 Method

Convert a PDF stream to Word stream. Both input and output are coming from memory stream.

byte[] ConvertToWord3(byte[] InStream,
                      string Password,
                      int From,
                      int To)

Function ConvertToWord3(InStream As Byte(),
                        Password As String,
                        From As Integer,
                        To As Integer)
                        As Byte()
def ConvertToWord3(self, binaryInStream, strPassword, intFrom, intTo)




byte[] ConvertToWord3(byte[] InStream,
                      String Password,
                      int From,
                      int To) throws PDF2WordException

function ConvertToWord3($binaryInStream, $strPassword, $intFrom, $intTo)




BclWdhrError ConvertToWord3(BclPDF2Word * pPdf2Word,
                            const unsigned char * InStream, unsigned InStreamSize,
                            const wchar_t * Password,
                            int From, int To,
                            unsigned char * * pOutStream, unsigned * pOutStreamSize);
Function ConvertToWord3(InStream As Variant,
                        [Password] As Variant,
                        [From] As Variant,
                        [To] As Variant)
                        As Variant

Parameters

InStream

Input PDF stream.

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[] inputStream = System.IO.File.ReadAllBytes(@"c:\test\input.pdf");
   byte[] outputStream = pdf2word.ConvertToWord3(inputStream);
   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
   inputStream = System.IO.File.ReadAllBytes("c:\test\input.pdf")
   outputStream = pdf2word.ConvertToWord3(inputStream)
   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


# reads a file into a binary memory stream
def file_get_contents(filename):
   f = open(filename, "rb")
   try:
      return f.read()
   finally:
      f.close()

# writes a binary memory stream to a file
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:\\test\\output.docx"
   inputStream = file_get_contents(inputFilename)
   pdf2word.setOutputDocumentFormat(PDF2Word.optOutputDocumentFormat.OPT_OUTPUT_DOCX)
   outputStream = pdf2word.ConvertToWord3(inputStream)
   file_put_contents(outputFilename, outputStream)
except PDF2Word.PDF2WordException as ex:
   print(ex)
PDF2Word pdf2word = new PDF2Word();
try
{
   pdf2word.setOutputDocumentFormat(optOutputDocumentFormat.OPT_OUTPUT_DOCX);
   File filein = new File("c:\\test\\input.pdf");
   FileInputStream fis = new FileInputStream(filein.getCanonicalPath());
   byte[] byteArrInput = new byte[(int)filein.length()];
   fis.read(byteArrInput);
   fis.close();
   byte[] byteArrOutput = pdf2word.ConvertToWord3(byteArrInput, "", 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:\\test\\output.docx";
   $inputStream = file_get_contents($inputFilename);
   $pdf2word->setOutputDocumentFormat(BCL\easyConverter\Word\optOutputDocumentFormat::OPT_OUTPUT_DOCX);
   $outputStream = $pdf2word->ConvertToWord3($inputStream);
   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;
      }

      FILE* fin = fopen("c:\\test\\input.pdf", "rb");
      fseek(fin, 0L, SEEK_END);
      size_t inputSize = ftell(fin);
      fseek(fin, 0L, SEEK_SET);
      unsigned char* pInputStream = (unsigned char*)malloc(inputSize);
      fread(pInputStream, 1, inputSize, fin);
      fclose(fin);

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

      pPdf2Word-<OutputDocumentFormat = BCL_WD_OPT_OUTPUT_DOCX;
      error = pPdf2Word->ConvertToWord3(pPdf2Word, pInputStream, inputSize, L"", 0, -1, &pOutputStream, &outputSize);
      free(pInputStream);
      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")

        ' convert PDF string into byte array using ADO stream object
        Set oADO = CreateObject("ADODB.Stream")
        oADO.Charset = "Windows-1252"
        oADO.Type = 2 ' 2: adTypeText
        oADO.Open
        oADO.WriteText strPDF
        oADO.Position = 0
        oADO.Type = 1 ' 1: adTypeBinary
        arrPDF = oADO.Read
        oADO.Close
  
        arrWord = oConverter.ConvertToWord3(arrPDF)

        ' 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