PNG
JPG
BMP
TIFF
PDF
如何通过云 PHP SDK 在 PDF 页脚中添加文本
要在 PDF 页脚中添加文本,我们将使用 Aspose.PDF Cloud PHP SDK 此云 SDK 帮助 PHP 程序员使用 Aspose.PDF REST API 开发基于云的 PDF 创建、注释、编辑和转换应用程序。只需在 Aspose for Cloud 创建一个帐户并获取您的应用程序信息。一旦拥有 App SID 和密钥,您就可以使用 Aspose.PDF Cloud PHP SDK。
包管理器控制台命令
composer install
通过云 PHP 添加页脚文本的步骤
Aspose.PDF Cloud 开发人员可以轻松加载并添加文本到 PDF 页脚,仅需几行代码。
- 上传 PDF 文档
- 通过添加文本页脚修改 PDF
- 下载更新后的文档
使用 PHP 在 PDF 页脚中添加文本
private function _create_rest_api() {
$credentials = json_decode(file_get_contents("./Credentials/credentials.json"), true);
$configAuth = new Configuration();
$configAuth->setAppKey($credentials['key']);
$configAuth->setAppSid($credentials['id']);
$this->pdfApi = new PdfApi(null, $configAuth);
}
public function __construct($config) {
$this->configParams = $config;
$this->_create_rest_api();
}
public function uploadDocument() {
$filePath = $this->configParams['LOCAL_FOLDER'] . $this->configParams['PDF_DOCUMENT_NAME'];
$fileData = file_get_contents($filePath);
$response = $this->pdfApi->uploadFile($this->configParams['PDF_DOCUMENT_NAME'], $fileData);
if ($response->getCode() === 200) {
echo "Uploaded file: {$filePath}\n";
} else {
echo 'Failed to upload file.';
}
}
public function downloadResult() {
$response = $this->pdfApi->downloadFile($this->configParams['PDF_DOCUMENT_NAME']);
$filePath = $this->configParams['LOCAL_FOLDER'] . $this->configParams['LOCAL_RESULT_DOCUMENT_NAME'];
if ($response->getCode() === 200) {
file_put_contents($filePath, $response->getContents());
echo "Downloaded: $filePath\n";
} else {
echo "Failed to download file.";
}
}
public function addTextFooter () {
$textFooter = new TextFooter(array(
'background' => true,
'value' => $this->configParams['FOOTER_VALUE'],
'horizontal_alignment' => \Aspose\PDF\Model\HorizontalAlignment::CENTER,
));
$resultFooter = $this->pdfApi->postDocumentTextFooter($this->configParams['PDF_DOCUMENT_NAME'], $textFooter);
if ($resultFooter->getCode() === 200) {
echo 'Successfully appended text footer "' . $this->configParams['FOOTER_VALUE'] . '"';
}
else
throw new Error("Unexpected error : can't append text footer!");
}
function main() {
global $configParams;
try {
$pdfHeaderFooter = new PdfHeaderFooter($configParams);
$pdfHeaderFooter->uploadDocument();
$pdfHeaderFooter->addTextFooter();
$pdfHeaderFooter->downloadResult();
} catch (\Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
}
在 PDF 中处理页脚
在 PDF 页脚中添加文本能增强文档的组织性、专业性和可用性。这对于品牌推广、法律合规、导航和安全至关重要,使其成为商业、学术和官方文档的宝贵功能。 使用 Aspose.PDF Cloud PHP SDK 将页脚添加到 PDF 文档中。
使用我们的 PHP 库,您可以:
- 添加 PDF 文档的文本或图像格式的页眉和页脚。
- 向 PDF 文档添加表格和图章(文本或图像)。
- 将多个 PDF 文档附加到现有文件中。
- 处理 PDF 附件、注释和表单字段。
- 对 PDF 文档应用加密或解密并设置密码。
- 从页面或整个 PDF 文档中删除所有图章和表格。
- 根据 ID 从 PDF 文档中删除特定图章或表格。
- 替换 PDF 页面或整个文档中的单个或多个文本实例。
- 支持将 PDF 文档转换为各种其他文件格式。
- 提取 PDF 文件的各种元素并优化 PDF 文档。
- 您可以尝试我们的免费应用程序在线测试该功能。