Uwchraddio Ffeil fel Templed
Mae’r canllaw hwn yn eich tywys trwy’r broses gyflawn o greu templed ac uwchlwytho ffeil PDF, delwedd, neu Word i’w defnyddio fel eich templed dogfen yn Legalesign.
Beth fyddwch chi'n ei Ddysgu
Ar ddiwedd y canllaw hwn, byddwch chi’n gwybod sut i:
- Greu templed newydd yn eich grŵp Legalesign
- Cael ID y templed a’r URL uwchlwytho o’r ymateb mwtasiwn
- Uwchlwytho eich ffeil ffynhonnell i’r templed
- Cadarnhau bod yr uwchlwythiad wedi bod yn llwyddiannus
Gofynion Cyntaf
Cyn i chi ddechrau, sicrhewch fod gennych chi:
- Cyfrif Legalesign gyda mynediad API
- Eich tystlythyrau dilysu (gweler ein canllaw dilysu)
- Ffeil PDF, delwedd, neu Word barod i’w huwchlwytho (uchafswm 50MB)
- Eich ID grŵp (y gweithle lle rydych chi am greu’r templed)
Y Broses Gyflawn
Cam 1: Creu Templed
Yn gyntaf, creu templed gwag yn Legalesign. Mae hyn yn dychwelyd ID y templed a URL uwchlwytho wedi’i lofnodi ymlaen llaw ar gyfer y llwytho i fyny PDF. I wneud hyn bydd angen i chi redeg mwtasiwn GraphQL, os nad ydych chi wedi gwneud hyn o’r blaen gweler Cyflwyniad i GraphQL.
Beth yw Templed?
Mae templed yn strwythur dogfen ailadroddadwy yn Legalesign. Unwaith y byddwch chi’n uwchlwytho PDF i templed, gallwch chi:
- Ychwanegu meysydd llofnodi a meysydd ffurflen
- Ei anfon at sawl derbynnydd
- Ei ail-ddefnyddio ar gyfer llofnodwyr gwahanol
Mwtasiwn GraphQL
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
Newidynnau Mewnbwn
{
"input": {
"groupId": "grpYourGroupAPIId",
"title": "Employment Contract Template"
}
}
Esboniad ar y Paramedrau
- groupId: ID 64-sylfaen eich grŵp/gweithle (gallwch ei dynnu o’r URL yn y Console https://console.legalesign.com/)
- title: Enw disgrifiadol ar gyfer eich templed (gallwch ei newid yn ddiweddarach)
- uploadOptions (dewisol): Opsiynau prosesu a gaiff eu cymhwyso wrth lwytho’r PDF i fyny:
pdfFieldsImport: true— mewnforio meysydd ffurflen PDF wedi’u mewnosod fel meysydd templedprocessTags: true— prosesu tagiau testun Legalesign yn y ddogfen ar lwytho
Cam 2: Tynnu ID y Templed a'r URL Uwchlwytho
Mae’r mwtasiwn yn dychwelyd gwrthrych templateCreateOutput. Cadwch y maes id a’r llinyn uploadUrl.
Enghraifft o ymateb:
{
"data": {
"createTemplate": {
"id": "dHBsYjQ5YTg5NWQtYWRhMy0xMWYwLWIxZGMtMDY5NzZlZmU0MzIx",
"uploadUrl": "https://s3.amazonaws.com/bucket/path?signature=..."
}
}
}
Mae ID y templed yn llinyn wedi’i amgodio gyda Base64. Cadwch y ddau werth o’r ymateb. Mae’r uploadUrl yn berthnasol am gyfnod byr ac dylid ei ddefnyddio’n ddi-oed.
Cam 3: Uwchlwythwch Eich PDF
Defnyddiwch y uploadUrl a ddychwelwyd i uwchlwytho’ch ffeil PDF yn uniongyrchol i S3. Bydd hyn yn amrywio yn dibynnu ar eich stack datblygu. Yn ein enghraifft javascript rydym wedi defnyddio fetch ond gallwch ddefnyddio llyfrgelloedd eraill gan gynnwys aws-amplify.
Enghreifftiau Gwaith Cyflawn
- JavaScript
- Python
- C#
import fs from 'fs';
const AUTH_TOKEN = '<token-from-authentication-guide>';
const uploadPdfTemplate = async (groupId, title, pdfFilePath) => {
const graphqlEndpoint = 'https://graphql.uk.legalesign.com/graphql';
// Step 1: Create the template
console.log('Creating template...');
const createResponse = await fetch(graphqlEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${AUTH_TOKEN}`
},
body: JSON.stringify({
query: `
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
`,
variables: {
input: {
groupId: groupId,
title: title
}
}
})
});
const createResult = await createResponse.json();
const templateId = createResult.data.createTemplate.id;
const uploadUrl = createResult.data.createTemplate.uploadUrl;
console.log('Template created with ID:', templateId);
// Step 2: Upload the PDF
console.log('Uploading PDF...');
const fileData = fs.readFileSync(pdfFilePath);
const uploadResponse = await fetch(uploadUrl, {
method: 'PUT',
body: fileData,
headers: {
'Content-Type': 'application/pdf'
}
});
if (!uploadResponse.ok) {
throw new Error(`Upload failed: ${uploadResponse.statusText}`);
}
console.log('PDF uploaded successfully!');
return {
success: true,
templateId: templateId,
title: title
};
};
// Usage example
uploadPdfTemplate(
'grpYourGroupId',
'Employment Contract',
'./contract.pdf'
).then(result => {
console.log('Complete!', result);
}).catch(error => {
console.error('Error:', error);
});
Dim angen dibyniaethau ychwanegol — mae Node.js 18+ yn cynnwys fetch yn ddiofyn.
import requests
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport
def upload_pdf_template(graphql_endpoint, auth_token, group_id, title, pdf_file_path):
transport = RequestsHTTPTransport(
url=graphql_endpoint,
headers={'Authorization': auth_token}
)
client = Client(transport=transport, fetch_schema_from_transport=True)
# Step 1: Create the template
print('Creating template...')
create_mutation = gql('''
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
''')
create_result = client.execute(
create_mutation,
variable_values={
'input': {
'groupId': group_id,
'title': title
}
}
)
template_id = create_result['createTemplate']['id']
upload_url = create_result['createTemplate']['uploadUrl']
print(f'Template created with ID: {template_id}')
# Step 2: Upload the PDF
print('Uploading PDF...')
with open(pdf_file_path, 'rb') as f:
file_data = f.read()
response = requests.put(
upload_url,
data=file_data,
headers={'Content-Type': 'application/pdf'}
)
if response.status_code != 200:
raise Exception(f'Upload failed: {response.status_code}')
print('PDF uploaded successfully!')
return {
'success': True,
'templateId': template_id,
'title': title
}
if __name__ == '__main__':
result = upload_pdf_template(
'https://graphql.uk.legalesign.com/graphql',
'Bearer YOUR_TOKEN',
'grpYourGroupId',
'Employment Contract',
'./contract.pdf'
)
print('Complete!', result)
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using GraphQL;
using GraphQL.Client.Http;
using GraphQL.Client.Serializer.Newtonsoft;
using Newtonsoft.Json.Linq;
public class PdfTemplateUploader
{
private readonly GraphQLHttpClient graphQLClient;
public PdfTemplateUploader(string graphqlEndpoint, string authToken)
{
graphQLClient = new GraphQLHttpClient(graphqlEndpoint, new NewtonsoftJsonSerializer());
graphQLClient.HttpClient.DefaultRequestHeaders.Add("Authorization", authToken);
}
public async Task<UploadResult> UploadPdfTemplate(
string groupId,
string title,
string pdfFilePath)
{
// Step 1: Create the template
Console.WriteLine("Creating template...");
var createMutation = new GraphQLRequest
{
Query = @"
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
",
Variables = new
{
input = new
{
groupId = groupId,
title = title
}
}
};
var createResponse = await graphQLClient.SendMutationAsync<dynamic>(createMutation);
string templateId = createResponse.Data.createTemplate.id;
string uploadUrl = createResponse.Data.createTemplate.uploadUrl;
Console.WriteLine($"Template created with ID: {templateId}");
// Step 2: Upload the PDF
Console.WriteLine("Uploading PDF...");
using var httpClient = new HttpClient();
var fileBytes = await File.ReadAllBytesAsync(pdfFilePath);
var content = new ByteArrayContent(fileBytes);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
var putResponse = await httpClient.PutAsync(uploadUrl, content);
if (!putResponse.IsSuccessStatusCode)
{
throw new Exception($"Upload failed: {putResponse.StatusCode}");
}
Console.WriteLine("PDF uploaded successfully!");
return new UploadResult
{
Success = true,
TemplateId = templateId,
Title = title
};
}
}
public class UploadResult
{
public bool Success { get; set; }
public string TemplateId { get; set; }
public string Title { get; set; }
}
class Program
{
static async Task Main(string[] args)
{
var uploader = new PdfTemplateUploader(
"https://graphql.uk.legalesign.com/graphql",
"Bearer YOUR_TOKEN"
);
var result = await uploader.UploadPdfTemplate(
"grpYourGroupId",
"Employment Contract",
"./contract.pdf"
);
Console.WriteLine($"Complete! Template ID: {result.TemplateId}");
}
}
Beth Sy’n Digwydd Ar Ôl Uwchlwythiad?
Unwaith y bydd eich PDF wedi’i lwytho i fyny, mae Legalesign yn awtomatig:
- Sganiwch am firysau - Sicrhau bod y ffeil yn ddiogel
- Dilysu neu drosi’r ffeil - Gwirio bod PDFs yn ddilys, neu drosi ffeiliau a gefnogir megis dogfennau Word a delweddau i PDF
- Tynnu gwybodaeth tudalen - Cael cyfaint a dimensiynau tudalen
- Prosesu’r ffeil - Optimeiddio ar ei gyfer gwylio a llofnodi
- Storio’n ddiogel - Symud i storfa barhaol
Fel arfer, mae’r broses hon yn cymryd ychydig eiliadau. Unwaith wedi’i chwblhau, mae eich templed yn barod i’w ddefnyddio!
Olrhain Cynnydd Uwchlwytho
I gael adborth mewn amser real ar brosesu’r uwchlwythiad (sganio, dilysu, cwblhau), defnyddiwch danysgrifiaethau. Gweler Olrhain Cynnydd Uwchlwytho gyda Thanysgrifiadau.
Fel arall, cwisgwch faes fileUploaded y templed nes iddo ddychwelyd true:
query CheckUploadStatus($id: ID!) {
template(id: $id) {
id
fileUploaded
}
}
Ychwanegu Llofnodion a Meysydd
Os ydych chi eisiau awtomeiddio cyfranogwyr a lleoliad meysydd, gallwch baratoi’r ffeil ffynhonnell cyn ei huwchlwytho mewn rhai ffyrdd gwahanol:
- Tagiau testun — Ychwanegu tagiau testun Legalesign i’r ddogfen ffynhonnell fel bod cyfranogwyr, meysydd llofnodi, a meysydd ffurflen yn cael eu creu’n awtomatig yn ystod prosesu. Pasio
uploadOptions: { processTags: true }yn y mwtasiwncreateTemplatei alluogi hyn. Gweler yr esboniad API REST yn y canllaw cychwyn cyflym a’r cyfeiriad at y bwynt terfyn Trosi tagiau testun. - Meysydd PDF wedi’u mewnosod — Os yw’ch PDF eisoes yn cynnwys meysydd ffurflen wedi’u mewnosod, pasiwch
uploadOptions: { pdfFieldsImport: true }yn y mwtasiwncreateTemplatei’w mewnforio fel meysydd templed yn awtomatig.
Camau Nesaf
Nawr eich bod wedi cael templed gyda PDF, gallwch:
- Ychwanegu meysydd llofnodi - Defnyddio’r mwtasiwn
createTemplateElementi ychwanegu meysydd - Creu rolau - Diffinio pwy fydd yn llofnodi’r ddogfen
- Anfon ar gyfer llofnodi - Defnyddio’r mwtasiwn
sendi anfon at y derbynwyr
Materion Cyffredin a Sut i’w Datrys
Gwall "Dim caniatâd"
Cadarnhewch fod eich ID grŵp yn gywir ac rydych wedi dilysu gyda’r cyfrif cywir.
Gwall "Ffeil yn rhy fawr"
Cywasgwch eich PDF — y mwyafswm yw 50MB.
URL Uwchlwytho wedi dod i ben
Defnyddiwch y uploadUrl a ddychwelwyd gan createTemplate yn brydlon. Os bydd yn dod i ben cyn i chi lwytho i fyny, gofynnwch am URL newydd gyda’r ymholiad upload gan ddefnyddio’r ID templed a gadwyd.
Gwall "PDF annilys"
Agorwch y PDF mewn darllenydd PDF i gadarnhau ei fod yn ddilys, yna allforiwch neu gadwch eto.