这是我使用 DocuSign Api 为多个动态文档构建信封的代码。它对我来说工作正常,但主要问题是它在每个文档的第一页上放置了“在此处签名”选项卡。但是,我想把它放在每份文件的最后一页。我怎样才能在 laravel 中做到这一点?有人可以为此建议我吗?
private function buildEnvelope($envelopeFiles, $user): EnvelopeDefinition
{
$recipientEmail = $user->email;
$recipientName = $user->first_name . " " . $user->last_name;
// Create an array to store all CompositeTemplate objects
$compositeTemplates = [];
foreach ($envelopeFiles as $index => $documentPath) {
$fileContent = file_get_contents($documentPath);
$fileName = pathinfo($documentPath, PATHINFO_BASENAME);
$fileExtension = pathinfo($documentPath, PATHINFO_EXTENSION);
// Create a Document object for the current document
$document = new Document([
'document_base64' => base64_encode($fileContent),
'name' => $fileName,
'file_extension' => $fileExtension,
'document_id' => $index + 1
]);
// Create a SignHere tab for the current document
$signHereTab = new SignHere([
'document_id' => $index + 1,
'page_number' => 1,
'recipient_id' => '1',
'tab_label' => 'Sign Here',
'x_position' => '70',
'y_position' => '780'
]);
// Create a Tabs object for the current document with the SignHere tab
$tabs = new Tabs([
'sign_here_tabs' => [$signHereTab]
]);
// Create a Signer object for the recipient with the Tabs object
$recipient = new Signer([
'email' => $recipientEmail,
'name' => $recipientName,
'recipient_id' => '1',
'routing_order' => '1',
'tabs' => $tabs
]);
// Create an InlineTemplate object for the current document with the recipient
$recipients = new Recipients(['signers' => [$recipient]]);
$inlineTemplate = new InlineTemplate([
'sequence' => $index + 1,
'recipients' => $recipients
]);
// Create a CompositeTemplate object for the current document with the Document
$compositeTemplate = new CompositeTemplate([
'inline_templates' => [$inlineTemplate],
'document' => $document
]);
// Add the CompositeTemplate object to the array of CompositeTemplate objects
$compositeTemplates[] = $compositeTemplate;
}
// Create the EnvelopeDefinition object with all the CompositeTemplate objects and other settings
$envelopeDefinition = new EnvelopeDefinition([
'composite_templates' => $compositeTemplates,
'email_subject' => "Please sign the documents",
'status' => "sent"
]);
return $envelopeDefinition;
}
这条线:
'page_number' => 1,
是你需要更新的,但问题是如果每个文档/信封的页数都是可变的,而你不知道有多少,你必须先调用 API 才能知道。如果您知道它有 4 页,则将“1”替换为“4”,否则您必须进行 3 次 API 调用:
注意: 在您使用 API 将文档发送到 DocuSign 之前,DocuSign 无法告诉您文档有多少页。