File size: 2,568 Bytes
c9be6fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6d6aa2
 
c9be6fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
const fs = require('fs');
const { docxPaths } = require('./constants');
const { v4: uuidv4 } = require('uuid');

// Function to extract relevant data from input
function GetData(data) {
  const {
    template_id,
    personal_information,
    job_title,
    career_objective,
    skills,
    education,
    experience,
    achievements
  } = data;

  const userData = {
    Name: personal_information.name,
    LastName: personal_information.last_name,
    EmailAddress: personal_information.email_address,
    PhoneNumber: personal_information.phone_number,
    LinkedIn: `<a href="${personal_information.linkedin_url}">LinkedIn</a>`,
    JobTitle: job_title,
    Summary: career_objective,
    Skills: skills,
    Education: education.map(edu => ({
      SchoolName: edu.school_name,
      Year: edu.passing_year,
      Description: edu.description
    })),
    Experience: experience.map(exp => ({
      CompanyName: exp.company_name,
      Year: exp.passing_year,
      Description: exp.responsibilities
    })),
    Achievements: achievements.map(ach => ({
      Type: ach.field,
      Description: ach.awards
    }))
  };
  const templateId=template_id;
  return { templateId, userData };
}

function GeneratePDF(data) {
  const { templateId, userData } = GetData(data);
  const inputFile = docxPaths[templateId];

  return new Promise((resolve, reject) => {
    const outputFileName = `resume_${uuidv4()}.pdf`; // Generate a unique file name using UUID
    const OUTPUT = `./temp/${outputFileName}`;
    const credentials = PDFServicesSdk.Credentials
      .servicePrincipalCredentialsBuilder()
      .withClientId("85c8c729f8a64332abd236589f997b2b")
      .withClientSecret("p8e-C4FxbvRivH-OIq2OLeBDLsCF96nVFHQq")
      .build();
    const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
    const documentMerge = PDFServicesSdk.DocumentMerge;
    const documentMergeOptions = documentMerge.options;

    const options = new documentMergeOptions.DocumentMergeOptions(
      userData,
      documentMergeOptions.OutputFormat.PDF
    );

    const documentMergeOperation = documentMerge.Operation.createNew(options);
    const input = PDFServicesSdk.FileRef.createFromLocalFile(inputFile);
    documentMergeOperation.setInput(input);
    documentMergeOperation
      .execute(executionContext)
      .then(result => result.saveAsFile(OUTPUT))
      .then(() => resolve(OUTPUT))
      .catch(err => {
        reject(err);
      });
  });
}

module.exports = {
  GeneratePDF
};