Llwytho Ffeil fel Templed
Mae’r canllaw hwn yn eich tywys drwy’r broses gyflawn o greu templed a llwytho ffeil PDF, ddelwedd, neu Word i’w defnyddio fel eich templed dogfen yn Legalesign.
Beth Fyddwch Chi’n Dysgu
Erbyn diwedd y canllaw hwn, byddwch yn gwybod sut i:
- Greu templed newydd yn eich grŵp Legalesign
- Cael yr ID templed a’r URL llwytho i fyny o’r ymateb mutasiwn
- Llwytho’ch ffeil ffynhonnell i’r templed
- Dilysu bod y llwytho i fyny wedi bod yn llwyddiannus
Gwybodaeth Angenrheidiol
Cyn i chi ddechrau, sicrhewch fod gennych:
- Cyfrif Legalesign gyda mynediad API
- Eich manylion dilysu (gweler ein canllaw dilysu)
- Ffeil PDF, ddelwedd, neu Word yn barod i’w llwytho i fyny (uchafswm 50MB)
- Eich ID grŵp (y gweithle lle rydych am greu’r templed)
Y Broses Gynhwysfawr
Cam 1: Creu Templed
Yn gyntaf, creu templed gwag yn Legalesign. Mae hyn yn dychwelyd yr ID templed a URL ar gyfer llwytho i fyny wedi’i llofnodi ymlaen llaw ar gyfer y PDF. I wneud hyn bydd angen i chi redeg mutasiwn GraphQL, os nad ydych wedi gwneud hyn o’r blaen gweler yr Cyflwyniad i GraphQL.
Beth yw Templed?
Mae templed yn strwythur dogfen a all gael ei ailddefnyddio yn Legalesign. Ar ôl i chi lwytho PDF i mewn i templed, gallwch:
- Ychwanegu meysydd llofnod a meysydd ffurflen
- Ei anfon at sawl derbynnydd
- Ei ailddefnyddio ar gyfer llofnodwyr gwahanol
Mutasiwn GraphQL
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
Amrywiolion Mewnbwn
{
"input": {
"groupId": "grpYourGroupAPIId",
"title": "Employment Contract Template"
}
}
Esboniad y Paramedrau
- groupId: ID sylfaen 64 eich grŵp/gweithle (gellir cael hwn o’r URL yn y Console https://console.legalesign.com/)
- title: Enw disgrifiadol i’ch templed (gellir newid hyn yn nes ymlaen)
Cam 2: Tynnu ID Templed a URL Llwytho i Fyny
Mae’r mutasiwn yn dychwelyd gwrthrych templateCreateOutput. Cadw’r maes id a’r llinyn uploadUrl.
Enghraifft o ymateb:
{
"data": {
"createTemplate": {
"id": "dHBsYjQ5YTg5NWQtYWRhMy0xMWYwLWIxZGMtMDY5NzZlZmU0MzIx",
"uploadUrl": "https://s3.amazonaws.com/bucket/path?signature=..."
}
}
}
Mae’r ID templed yn llinyn wedi’i godio mewn Base64. Cadw’r ddau werth o’r ymateb. Mae’r uploadUrl yn para am gyfnod byr felly dylid ei ddefnyddio’n gyflym.
Cam 3: Llwytho Eich PDF
Defnyddiwch y uploadUrl a ddychwelwyd i lwytho’ch ffeil PDF yn uniongyrchol i S3. Bydd hyn yn wahanol yn dibynnu ar eich stac datblygu. Yn ein enghraifft javascript rydym wedi defnyddio fetch ond gallwch ddefnyddio llyfrgelloedd eraill gan gynnwys aws-amplify.
Enghreifftiau Gwaith Cynhwysfawr
- 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 dibyniaethau ychwanegol angen — mae Node.js 18+ yn cynnwys fetch yn frodorol.
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 Llwytho i Fyny?
Unwaith y bydd eich PDF wedi’i lwytho i fyny, mae Legalesign yn awtomatig:
- Sganio am firysau - Sicrhau bod y ffeil yn ddiogel
- Dilysu neu drosi’r ffeil - Gwiriwch fod PDFs yn ddilys, neu droswch ffeiliau a gefnogi megis dogfennau Word a delweddau yn PDF
- Tynnu gwybodaeth y dudalen - Cael cyfrif tudalennau a dimensiynau
- Prosesu’r ffeil - Gwella’r perfformiad ar gyfer gweld a llofnodi
- Storfa ddiogel - Symud i storfa barhaol
Fel arfer mae’r proses hon yn cymryd ychydig eiliadau. Unwaith wedi’i gwblhau, mae eich templed yn barod i’w ddefnyddio!
Olrhain Cynnydd Llwytho i Fyny
I gael adborth amser-real ar brosesu’r llwytho i fyny (sganio, dilysu, cwblhau), defnyddiwch danysgrifiadau. Gweler Olrhain Cynnydd Llwytho i Fyny gyda Thanysgrifiadau.
Fel arall, polliwch faes fileUploaded y templed nes iddo ddychwelyd true:
query CheckUploadStatus($id: ID!) {
template(id: $id) {
id
fileUploaded
}
}
Ychwanegu Llofnodion a Meysydd
Os hoffech chi awtomeiddio cyfranogwyr a lleoliad meysydd, gallwch baratoi’r ffeil ffynhonnell cyn ei llwytho i fyny mewn ychydig o wahanol ffyrdd:
- Tagiau testun - Ychwanegu tagiau testun Legalesign i mewn i’r ddogfen ffynhonnell er mwyn i gyfranogwyr, meysydd llofnodi a meysydd ffurflen gael eu creu’n awtomatig yn ystod y broses. Gweler y cyflwyniad API REST yn y tiwtorial cyflym a’r cyfeiriadur at bwynt terfyn Convert text tags.
- Meysydd PDF Cymysg - Os yw’ch PDF eisoes yn cynnwys meysydd ffurflen wedi’u mewnbwn, gall Legalesign eu defnyddio fel rhan o’r llif gwaith llwytho i fyny a pharatoi templed.
Camau Nesaf
Nawr bod gennych templed gyda PDF, gallwch:
- Ychwanegu meysydd llofnodi - Defnyddiwch y mutasiwn
createTemplateElementi ychwanegu meysydd - Creu rolau - Diffinio pwy fydd yn llofnodi’r ddogfen
- Anfon ar gyfer llofnodi - Defnyddiwch y mutasiwn
sendi anfon at y derbynwyr
Materion Cyffredin a Datrysiadau
Gwall "Dim caniatâd"
Gwiriwch fod eich ID grŵp yn gywir a’ch bod wedi dilysu gyda’r cyfrif cywir.
Gwall "Ffeil yn rhy fawr"
Cywasgwch eich PDF — y mwyafswm yw 50MB.
Mae URL Llwytho i Fyny wedi Dod i Ben
Defnyddiwch y uploadUrl a ddychwelwyd gan createTemplate yn syth. Os bydd yn dod i ben cyn i chi lwytho, 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 wirio ei fod yn ddilys, yna allforwch neu achub eto.