Llwytho Ffeil fel Templed
Mae’r canllaw hwn yn eich cerdded drwy’r broses gyflawn o greu templed a llwytho ffeil PDF, delwedd, neu Word i’w defnyddio fel eich templed dogfen yn Legalesign.
Oes angen adborth amser real ar brosesu’r llwytho i fyny? Gweler Olrhain Cynnydd Llwytho i Fyny gyda Subscribiadau.
Beth Fyddwch Chi'n Dysgu
Ar ddiwedd y canllaw hwn, byddwch yn gwybod sut i:
- Creu templed newydd yn eich grŵp Legalesign
- Cael yr ID templed a’r URL llwytho i fyny o ymateb y modd mudo
- Llwytho’ch ffeil ffynhonnell i’r templed
- Gwirio bod y llwytho i fyny wedi bod yn llwyddiannus
Rhagofynion
Cyn i chi ddechrau, sicrhewch fod gennych:
- Cyfrif Legalesign gyda mynediad API
- Eich manylion awdurdodiad (gweler ein canllaw awdurdodiad)
- Ffeil PDF, delwedd, 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 Gyflawn
Cam 1: Creu Templed
Yn gyntaf, creu templed gwag yn Legalesign. Mae hyn yn dychwelyd y ddau ID templed a URL llwytho i fyny wedi’i rido yn flaenorol ar gyfer y llwytho i fyny PDF. I wneud hyn bydd angen i chi redeg modd mudo GraphQL, os nad ydych wedi gwneud hyn o’r blaen gweler yr Cyflwyniad i GraphQL.
Beth yw Templed?
Mae templed yn strwythur dogfen adnewadwy yn Legalesign. Unwaith y byddwch yn llwytho PDF i templed, gallwch:
- Ychwanegu meysydd llofnodi a meysydd ffurflen
- Anfon ato i sawl derbynnydd
- Ail-ddefnyddio ar gyfer llofnodwyr gwahanol
Modd Mudo GraphQL
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
Amrywiolion Mewnbwn
{
"input": {
"groupId": "grpYourGroupAPIId",
"title": "Employment Contract Template"
}
}
Esboniad o Baramedrau
- groupId: Yr ID base 64 o’ch grŵp/gweithle (gallwch ei gael o’r URL yn Console https://console.legalesign.com/)
- title: Enw disgrifiadol ar gyfer eich templed (gallwch newid hyn yn ddiweddarach)
Cam 2: Tynnu’r ID Templed a’r URL Llwytho i Fyny
Mae’r modd mudo 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’r ID templed yn llinyn wedi’i godio Base64. Cadwch y ddau werth o’r ymateb. Mae’r uploadUrl yn rhannol fyw a dylid ei ddefnyddio’n brydlon.
Cam 3: Llwytho Eich PDF i Fyny
Defnyddiwch y uploadUrl dychwelyd 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 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 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 - Gwirio bod PDFs yn ddilys, neu drawsnewid ffeiliau cefnogedig fel dogfennau Word a delweddau i PDF
- Tynnu gwybodaeth tudalen - Cael cyfrif tudalennau a dimensiynau
- Prosesu’r ffeil - Optimeiddio ar gyfer gweld a llofnodi
- Storio’n ddiogel - Symud i storfa barhaol
Fel arfer mae’r broses hon yn cymryd ychydig eiliadau. Ar ôl ei chwblhau, mae’ch templed yn barod i’w ddefnyddio!
Ychwanegu Llofnodion a Meysydd
Os ydych am awtomeiddio cyfranogwyr a lleoliad y meysydd, gallwch baratoi’r ffeil ffynhonnell cyn ei llwytho i fyny mewn sawl ffordd wahanol:
- Tagiau testun - Ychwanegu tagiau testun Legalesign i’r ddogfen ffynhonnell fel y gellir creu cyfranogwyr, meysydd llofnod, a meysydd ffurflen yn awtomatig yn ystod prosesu. Gweler esboniad y REST API yn y gwers gyflym a chyfeiriad y pwynt terfyn Trosi tagiau testun.
- Meysydd PDF wedi’u hymgorffori - Os yw’ch PDF eisoes yn cynnwys meysydd ffurflen wedi’u hymgorffori, gall Legalesign eu defnyddio fel rhan o broses llwytho i fyny a pharatoi templed.
Camau Nesaf
Nawr bod gennych templed gyda PDF, gallwch:
- Ychwanegu meysydd llofnodi - Defnyddio’r modd mudo
createTemplateElementi ychwanegu meysydd - Creu rolau - Diffinio pwy fydd yn llofnodi’r ddogfen
- Anfon ar gyfer llofnodi - Defnyddio’r modd mudo
sendi anfon at y derbynwyr
Problemau Cyffredin a Datrysiadau
Gwall “Dim caniatâd”
Gwirio bod eich ID grŵp yn gywir ac eich bod wedi’ch awdurdodi gyda’r cyfrif cywir.
Gwall “Ffeil yn rhy fawr”
Cywasgwch eich PDF — mae’r uchafswm yn 50MB.
URL Llwytho i Fyny Wedi Dod i Ddiffyg
Defnyddiwch y uploadUrl a ddychwelwyd gan createTemplate yn brydlon. Os yw’n dod i ddiffyg cyn i chi lwytho i fyny, gofyn am URL newydd gyda’r ymholiad upload gan ddefnyddio’r ID templed a gadwyd.
Gwall “PDF Anhysbys”
Agorwch y PDF mewn darllenydd PDF i wirio ei fod yn ddilys, yna ailallforiwch neu ail arbedwch ef.
Olrhain Cynnydd Llwytho i Fyny
I gael adborth amser real ar brosesu’r llwytho i fyny (sganio, dilysiad, cwblhau), defnyddiwch subscribiadau. Gweler Olrhain Cynnydd Llwytho i Fyny gyda Subscribiadau.