import os
from asposepdfcloud import PdfApi, models
from asposepdfcloud.api_client import ApiClient
# Replace with your Aspose Cloud App key and App SID
app_key = 'app_key personal'
app_sid = 'app_sid personal'
# Initialize the PdfApi client
pdf_api_client = ApiClient(app_key=app_key, app_sid=app_sid)
pdf_api = PdfApi(pdf_api_client)
def process_pdf_files_in_folder(input_folder, output_folder):
# Ensure the output folder exists
os.makedirs(output_folder, exist_ok=True)
# Iterate over all PDF files in the input folder
for filename in os.listdir(input_folder):
if filename.endswith(".pdf"):
input_file_path = os.path.join(input_folder, filename)
remote_name = filename
copied_file = f'processed_{filename}'
# Upload PDF file to cloud storage
pdf_api.upload_file(remote_name, input_file_path)
# Copy the file
pdf_api.copy_file(remote_name, copied_file)
# Replace text
text_replace = models.TextReplace(old_value='Watermark instead', new_value='', regex=True)
text_replace_list = models.TextReplaceListRequest(text_replaces=[text_replace])
pdf_api.post_document_text_replace(copied_file, text_replace_list)
# Download the processed file to the local system
output_file_path = os.path.join(output_folder, copied_file)
# Retrieve the file content from the cloud
response = pdf_api.download_file(copied_file)
# Open a file stream to write the downloaded content
with open(output_file_path, 'wb') as file:
# Write the content to the file
file.write(response)
print(f'Processed and saved: {output_file_path}')
# Use specific folder paths
process_pdf_files_in_folder(r'D:\input', r'D:\output')
D:\>python rm.py
host: https://api.aspose.cloud/v3.0
tokenUrl: https://api.aspose.cloud/connect/token
Traceback (most recent call last):
File "D:\rm.py", line 49, in
process_pdf_files_in_folder(r'D:\input', r'D:\output')
File "D:\rm.py", line 44, in process_pdf_files_in_folder
file.write(response)
TypeError: a bytes-like object is required, not 'str'
Множественные изменения кода по-прежнему не работают, нужен работоспособный код.
# Iterate over all PDF files in the input folder for filename in os.listdir(input_folder): if filename.endswith(".pdf"): input_file_path = os.path.join(input_folder, filename) remote_name = filename copied_file = f'processed_{filename}'
# Upload PDF file to cloud storage pdf_api.upload_file(remote_name, input_file_path)
# Copy the file pdf_api.copy_file(remote_name, copied_file)
# Download the processed file to the local system output_file_path = os.path.join(output_folder, copied_file)
# Retrieve the file content from the cloud response = pdf_api.download_file(copied_file)
# Open a file stream to write the downloaded content with open(output_file_path, 'wb') as file: # Write the content to the file file.write(response)
print(f'Processed and saved: {output_file_path}')
# Use specific folder paths process_pdf_files_in_folder(r'D:\input', r'D:\output') [/code] Ошибка при запуске кода следующая: [code]D:\>python rm.py host: https://api.aspose.cloud/v3.0 tokenUrl: https://api.aspose.cloud/connect/token Traceback (most recent call last): File "D:\rm.py", line 49, in process_pdf_files_in_folder(r'D:\input', r'D:\output') File "D:\rm.py", line 44, in process_pdf_files_in_folder file.write(response) TypeError: a bytes-like object is required, not 'str' [/code] Множественные изменения кода по-прежнему не работают, нужен работоспособный код.
Я создал приложение Spring Patch и упаковала его в виде файла JAR. Однако, когда я пытаюсь загрузить его в SCDF (работа в контейнере Docker), SCDF не может получить доступ к файлу JAR, и я не уверен, как установить соединение между SCDF (Docker) и...
Я создал приложение Spring Patch и упаковала его в виде файла JAR. Однако, когда я пытаюсь загрузить его в SCDF (работа в контейнере Docker), SCDF не может получить доступ к файлу JAR, и я не уверен, как установить соединение между SCDF (Docker) и...
Слишком долго боролся с этим и нуждаюсь в помощи.
Я генерирую возобновляемый URL-адрес на php, который затем передаю в свое угловое приложение для загрузки файла.
Мои файлы успешно загружаются в хранилище, о чем свидетельствует то, что имя файла...