Chỉnh sửa Word tệp hoặc PDF trong C++ SDK

Sử dụng REST API để chỉnh sửa tệp trong C++ theo chương trình

Khi các nhà phát triển sửa đổi tài liệu bằng giải pháp C++ đã cho, những gì thực sự đang được chỉnh sửa là Mô hình Đối tượng Tài liệu (DOM). Do đó, hầu hết mọi thay đổi đều có thể được thực hiện đối với tài liệu được biểu thị dưới dạng DOM. Với C++ SDK được cung cấp, nhà phát triển có thể dễ dàng chỉnh sửa tài liệu: sửa đổi văn bản, cập nhật bảng, thêm hình ảnh, v.v. Chỉ cần tải Word, PDF hoặc tệp của bạn ở định dạng tải được hỗ trợ, thực hiện các thay đổi cần thiết theo chương trình và xuất kết quả sang định dạng lưu được hỗ trợ.

Xem đoạn mã

Chỉnh sửa tài liệu trong C++ bằng REST API

Thư viện C++ của chúng tôi cung cấp cho các nhà phát triển khả năng sửa đổi tài liệu trực tiếp bằng cách chỉnh sửa Mô hình đối tượng tài liệu (DOM), có nghĩa là không cần cài đặt thêm phần mềm.

Điều quan trọng cần biết là sử dụng giải pháp C++ này, bạn có thể chỉnh sửa tài liệu ở bất kỳ định dạng nào được hỗ trợ. Ví dụ: có thể tải tệp ở PDF định dạng, DOCX, DOC, RTF, ODT, EPUB, HTML và các định dạng khác, sau đó sửa đổi tệp này và lưu ở định dạng tương tự hoặc ở bất kỳ định dạng nào khác được hỗ trợ.

Chỉnh sửa văn bản trong C++

Trường hợp phổ biến nhất để chỉnh sửa Word, PDF hoặc bất kỳ tài liệu nào khác là chỉnh sửa văn bản. Với giải pháp phần mềm đã cho, bạn có thể thêm, sửa đổi hoặc xóa văn bản bằng C++ trong tài liệu.

Chỉnh sửa bảng trong C++

Một tùy chọn chỉnh sửa tài liệu phổ biến khác là chỉnh sửa bảng. C++ SDK của chúng tôi cho phép bạn làm việc với các bảng và văn bản trong các ô của bảng.

Các nhà phát triển C++ có thể thêm hoặc xóa bảng và ô bảng, cũng như thêm, chỉnh sửa và xóa văn bản bên trong chúng.

Thêm hình ảnh vào tài liệu bằng C++

Bên cạnh việc chỉnh sửa văn bản và bảng, có một tùy chọn phổ biến khác: thêm hình ảnh vào tài liệu trong C++. Các nhà phát triển C++ cũng có thể thêm hình ảnh vào tệp bằng DOM.

Chỉnh sửa tài liệu trực tuyến

Hãy dùng thử C++ SDK mạnh mẽ này và đánh giá một số tùy chọn trong chỉnh sửa tài liệu. Sử dụng ví dụ sau, tải tài liệu của bạn và thực hiện một số thay đổi: thêm văn bản, thêm bảng và ô trong bảng có văn bản hoặc chèn hình ảnh vào tài liệu:

Tải lên tài liệu bạn muốn sửa đổi
Mã vận hành
Tải lên hình ảnh bạn muốn chèn
Chọn định dạng mục tiêu từ danh sách
using namespace aspose::words::cloud;

auto config = std::make_shared<ApiConfiguration>(L"####-####-####-####-####", 
   L"##################");
auto wordsApi = std::make_shared<WordsApi>(config);

auto requestDocument = std::shared_ptr<std::istream>(new std::ifstream(
   std::filesystem::path(L"Input.docx"), std::istream::binary));
auto requestParagraph = std::make_shared<aspose::words::cloud::models::ParagraphInsert>();
requestParagraph->setText(std::make_shared<std::wstring>(L"Morbi enim nunc faucibus a."));

std::shared_ptr<requests::InsertParagraphOnlineRequest> insertParagraphRequest(
    new requests::InsertParagraphOnlineRequest(
        requestDocument, requestParagraph
    )
);
auto insertParagraph = wordsApi->insertParagraphOnline(insertParagraphRequest);

std::shared_ptr<requests::ConvertDocumentRequest> convertRequest(
    new requests::ConvertDocumentRequest(
        insertParagraph->document->values.begin,
          std::make_shared<std::wstring>(L"docx")
    )
);
auto convert = wordsApi->convertDocument(convertRequest);
using namespace aspose::words::cloud;

auto config = std::make_shared<ApiConfiguration>(L"####-####-####-####-####", 
   L"##################");
auto wordsApi = std::make_shared<WordsApi>(config);

auto requestDocument = std::shared_ptr<std::istream>(new std::ifstream(
   std::filesystem::path(L"Input.docx"), std::istream::binary));
auto requestTable = std::make_shared<aspose::words::cloud::models::TableInsert>();
requestTable->setColumnsCount(std::make_shared<int32_t>(1));
requestTable->setRowsCount(std::make_shared<int32_t>(2));

std::shared_ptr<requests::InsertTableOnlineRequest> insertTableRequest(
    new requests::InsertTableOnlineRequest(
        requestDocument, requestTable, std::make_shared<std::wstring>(L"")
    )
);
auto insertTable = wordsApi->insertTableOnline(insertTableRequest);

std::shared_ptr<requests::ConvertDocumentRequest> convertRequest(
    new requests::ConvertDocumentRequest(
        insertTable->document->values.begin,
          std::make_shared<std::wstring>(L"docx")
    )
);
auto convert = wordsApi->convertDocument(convertRequest);
using namespace aspose::words::cloud;

auto config = std::make_shared<ApiConfiguration>(L"####-####-####-####-####", 
   L"##################");
auto wordsApi = std::make_shared<WordsApi>(config);

auto requestDocument = std::shared_ptr<std::istream>(new std::ifstream(
   std::filesystem::path(L"Input1.docx"), std::istream::binary));

auto requestDrawingObject = 
   std::make_shared<aspose::words::cloud::models::DrawingObjectInsert>();
requestDrawingObject->setHeight(std::make_shared<double>(0));
requestDrawingObject->setLeft(std::make_shared<double>(0));
requestDrawingObject->setTop(std::make_shared<double>(0));
requestDrawingObject->setWidth(std::make_shared<double>(0));
requestDrawingObject->setRelativeHorizontalPosition(
   std::make_shared<aspose::words::cloud::models::DrawingObjectInsert::RelativeHorizontalPosition>(
      aspose::words::cloud::models::DrawingObjectInsert::RelativeHorizontalPosition::MARGIN));
requestDrawingObject->setRelativeVerticalPosition(
   std::make_shared<aspose::words::cloud::models::DrawingObjectInsert::RelativeVerticalPosition>(
      aspose::words::cloud::models::DrawingObjectInsert::RelativeVerticalPosition::MARGIN));
requestDrawingObject->setWrapType(
   std::make_shared<aspose::words::cloud::models::DrawingObjectInsert::WrapType>(
      aspose::words::cloud::models::DrawingObjectInsert::WrapType::INLINE));

auto requestImageFile = std::shared_ptr<std::istream>(new std::ifstream(
   std::filesystem::path(L"Input2.docx"), std::istream::binary));
std::shared_ptr<requests::InsertDrawingObjectOnlineRequest> insertDrawingObjectRequest(
    new requests::InsertDrawingObjectOnlineRequest(
        requestDocument, requestDrawingObject, requestImageFile, 
		   std::make_shared<std::wstring>(L"sections/0")
    )
);
auto insertDrawingObject = wordsApi->insertDrawingObjectOnline(insertDrawingObjectRequest);

std::shared_ptr<requests::ConvertDocumentRequest> convertRequest(
    new requests::ConvertDocumentRequest(
        insertDrawingObject->document->values.begin,
          std::make_shared<std::wstring>(L"docx")
    )
);
auto convert = wordsApi->convertDocument(convertRequest);
Mã vận hành
  
Sao chép mã C++ vào khay nhớ tạm

Cách chỉnh sửa tệp trong C++

  1. Cài đặt 'Aspose. AdWords Cloud cho C++'
  2. Thêm tham chiếu thư viện (nhập thư viện) vào dự án C++ của bạn
  3. Tải tài liệu để chỉnh sửa trong C++
  4. Chèn nội dung vào đầu tài liệu
  5. Tải xuống tài liệu kết quả từ bộ nhớ đám mây

C++ thư viện để sử dụng chỉnh sửa tài liệu

Sao Aspose.Words Cloud SDK for C++ từ GitHub. Bạn có thể tìm thông tin chi tiết về cách xây dựng và định cấu hình SDK trong phần "How to use the SDK".

Để nhanh chóng nhận được thông tin xác thực bảo mật cần thiết và truy cập REST API của chúng tôi, vui lòng làm theo các Instructions sau trong tài liệu.

yêu cầu hệ thống

Tham khảo Repository Documentation để xem chi tiết.

5%

Đăng ký cập nhật sản phẩm của Aspose

Nhận bản tin hàng tháng và ưu đãi gửi trực tiếp đến hộp thư của bạn.

© Aspose Pty Ltd 2001-2024. Đã đăng ký Bản quyền.