PNG
JPG
BMP
TIFF
PDF
如何通过 Cloud PHP SDK 在 PDF 的页眉中添加文本
要在 PDF 的页眉中添加文本,我们将使用 Aspose.PDF Cloud PHP SDK 此 Cloud SDK 协助 PHP 程序员使用 PHP 编程语言通过 Aspose.PDF REST API 开发基于云的 PDF 创建、注释、编辑和转换应用程序。只需在 Aspose for Cloud 创建一个帐户并获取您的应用程序信息。一旦您拥有 App SID 和密钥,您就可以开始使用 Aspose.PDF Cloud PHP SDK。
Package Manager Console Command
composer install
通过 Cloud 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 addTextHeader () {
$textHeader = new TextHeader(array(
'background' => true,
'value' => $this->configParams['HEADER_VALUE'],
'horizontal_alignment' => \Aspose\PDF\Model\HorizontalAlignment::CENTER,
));
$resultHeader = $this->pdfApi->postDocumentTextFooter($this->configParams['PDF_DOCUMENT_NAME'], $textHeader);
if ($resultHeader->getCode() === 200) {
echo 'Successfully appended text footer "' . $this->configParams['HEDAER_VALUE'] .'"';
}
else
throw new Error("Unexpected error : can't append text footer!");
}
function main() {
global $configParams;
try {
$pdfHeaderFooter = new PdfHeaderFooter($configParams);
$pdfHeaderFooter->uploadDocument();
$pdfHeaderFooter->addTextHeader();
$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 文档。
- 您可以尝试我们的免费应用在线测试功能。