Quick Guide for PDFelement SDK

The hands-on guide to help you learn how to use PDFelement SDK in seconds.

Home Online Help > Quick Guide For PDFelement SDK

PDF To XML

Function Description

Convert PDF documents to XML documents

Code sample

          bool ConvertToXml(const wchar_t* pdf_path, const wchar_t* dest_path) {
              PDF2Xml pdf_to_xml;
              auto open_result = pdf_to_xml.Open(pdf_path);
              if (open_result == PDF2Xml::kOpenSuccess) {
                  return pdf_to_xml.Save(dest_path);
          }
          return false;
          }
          

 

Method: PDF2Xml::Open

  • Description: Open the PDF document
  • Parameters Description:

Parameter

Type

Must

Description

file_path

const char* or

const wchar_t*

Yes

PDF document path.

password

const unsigned char*

No

Password

password_length

size_t

No

Password length

Return type:

Type

Description

    /**

    * @brief Open result

    */

    enum OpenResult {

        kOpenFailed,

        kOpenSuccess,

        kOpenNeedPassword = 4,

    };

Whether the opening is successful.

Code sample

          PDF2Xml pdf_to_xml;
          unsigned char pwd[100] = {  "123456" };
          auto open_result = pdf_to_xml.Open(L"F:\\source\\test.pdf", pwd, 6u);
          if (open_result != PDF2Xml::kOpenSuccess) {
              switch (open_result) {
                  case PDF2Xml::kOpenFailed:
                      std::cerr << "Failed to open the document." << std::endl;
                      break;
                  case PDF2Xml::kOpenNeedPassword:
                      std::cerr << "Document requires password." << std::endl;
                  default:
                      break;
              }
          }
          

 

Method: PDF2Xml::AddPageRange

  • Description: add conversion page range, convert all pages by default.
  • Parameters description:

Parameter

Type

Must

Description

start

unsigned int

Yes

Start Page

end

unsigned int

Yes

End Page

step

unsigned int

No

Step, the default value is 1

Return type:

Type

Description

Void

Code sample

          PDF2Xml pdf_to_xml;
          auto open_result = pdf_to_xml.Open(L"F:\\source\\test.pdf");
          if (open_result == PDF2Xml::kOpenSuccess) {
              pdf_to_xml.AddPageRange(2u,5u);
          }
          

 

Method: PDF2Xml::SetRegion

  • Description: Set the rectangular area of the conversion page
  • Parameters description:

Parameter

Type

Must

Description

left

float

Yes

The x-axis coordinate value of the upper left corner of the rectangular area

top

float

Yes

The y-axis coordinate value of the upper left corner of the rectangular area

right

float

Yes

The x-axis coordinate value of the lower right corner of the rectangular area

bottom

float

Yes

The y-axis coordinate value of the lower right corner of the rectangular area

Return type:

Type

Description

Void

Code sample

          PDF2Xml pdf_to_xml;
          auto open_result = pdf_to_xml.Open(L"F:\\source\\test.pdf");
          if (open_result == PDF2Xml::kOpenSuccess) {
              pdf_to_xml.SetRegion(100,300,200,200);
          }
          

 

Method: PDF2Xml::Save

  • Description: Save the converted document
  • Parameters description:

Parameter

Type

Must

Description

dest_path

const char* or

const wchar_t*

Yes

Destination file path

progress

Progress

No

Save the progress notification object. Default is empty

Return type:

Type

Description

Void

Code sample

          PDF2Xml pdf_to_xml;
          auto open_result = pdf_to_xml.Open(L"F:\\source\\test.pdf");
          if (open_result == PDF2Xml::kOpenSuccess) {
          pdf_to_xml.Save(L"F:\\output\\test.xml");
          }
          

Contact Support Still have confusion or any suggestions? Please contact support and we will reply within 24 hours.

Volume Licensing Program
Digitize paperwork and accelerate the way you create, prepare, and sign documents.
pdfelement brand pic

Available for Windows, Mac, iOS, and Android.

Try Free Try Free Try Free Buy Now
Start your free trial!

Skip and Download

×
Top