나는 나무를 통해 나무를 보지 못하는 지점까지 나를 이끌어내는 뭔가를 찾으려고 노력하고있다. 나는 JavaScript에 관해서는 멍청 하긴하지만, 보통 데이터베이스를 사용하여 이것을 분류하고 있지만 그 옵션은 없다. 실제로 일하고 있어요 무엇널 변수를 포함하지 않는 jsPDF를위한 빌딩 배열
은 다음과 같습니다
이것은 (descrete 응답/SCORM 준수) 질문, 다음 다른 (무료 텍스트/긴 텍스트) 질문에 응답하는 사용자를 묻는 퀴즈 응용 프로그램입니다. 이 코드의 특정 부분은 사용자 응답의 PDF 출력을 만드는 데 사용됩니다 (헤더 정보가 약간 포함됨).
나는 다른 곳에서 생성 한 변수 집합을 출력하는 pdf ("jsPDF - Parallax"사용)를 작성하기 위해 JavaScript를 사용해야합니다. 예 :
: 다음 설정에, 거기에 다른 내용이 유일한 페이지입니다 첫 페이지에 헤더 정보를 (나는이 같은 페이지를 구축하고 jsPDF를 사용하여//VARIABLES........................................................................
var NoofQuesAnswered = VarNoofQuesAnswered.getValue();
var User_Score = VarUser_Score.getValue();
var CorrectImagData = 'data:image/jpeg;base64,/9j/etc/etc'; //Omitted actual 64base text
var IncorrectImgData = 'data:image/jpeg;base64,/9j/etc/etc'; //Omitted actual 64base text
/* General Text Values */
var notAnswered = '~~~null~~~';
var questionExcludedTitle = 'Question Excluded';
var questionAnswerGivenTitle = 'Answer Given';
var openQuestionTitle = 'Open Question';
/* Question Title - Variables */
var questionTitle_1 = 'Question 1';
var questionTitle_2 = 'Question 2';
var questionTitle_3 = 'Question 3';
var questionTitle_4 = 'Question 4';
var questionTitle_5 = 'Question 5';
var questionTitle_N = 'Question N';
/* Question Response/Answer Given - Variables */
//These variables are determined elsewhere (XML/Javascript)
var UsersAnswer_Que1 = Var_UsersAnswer_Que1.getValue();
var UsersAnswer_Que2 = Var_UsersAnswer_Que2.getValue();
var UsersAnswer_Que3 = Var_UsersAnswer_Que3.getValue();
var UsersAnswer_Que4 = Var_UsersAnswer_Que4.getValue();
var UsersAnswer_Que5 = Var_UsersAnswer_Que5.getValue();
var UsersAnswer_QueN = Var_UsersAnswer_QueN.getValue();
/* Open Question - Variables */
var openQuestion_1 = 'Why are young people potentially at risk?';
var openQuestion_2 = 'Why are there champions for young people?';
var openQuestion_3 = 'How does social media impact on the lives of young people?';
var openQuestion_4 = 'What kinds of support are there for young people, in your area?';
var openQuestion_5 = 'What type of information are young people most likely to need in crisis?';
var openQuestion_N = 'Open question (n)';
/* Open Question - User Response/Answer Given Variables */
//These variables are determined elsewhere (XML/Javascript)
var UserResp_LongTextQue_1 = Var_UserResp_LongTextQue_1.getValue();
var UserResp_LongTextQue_2 = Var_UserResp_LongTextQue_2.getValue();
var UserResp_LongTextQue_3 = Var_UserResp_LongTextQue_3.getValue();
var UserResp_LongTextQue_4 = Var_UserResp_LongTextQue_4.getValue();
var UserResp_LongTextQue_5 = Var_UserResp_LongTextQue_5.getValue();
var UserResp_LongTextQue_N = Var_UserResp_LongTextQue_N.getValue();
function genPDF() { //Function to output the pdf using jsPDF
var doc = new jsPDF();
/* Begin Page Build */
// Page Header Space........................................................................
/* There are some other logos and other header bits here but I have ommitted them due to copyright */
doc.setFont('helvetica')
doc.setFontSize(30)
doc.text(50, 55, 'Results and Responses')
doc.setFontSize(14)
doc.text(45, 78, 'No. of Questions Answered -')
doc.text(113, 78, NoofQuesAnswered)
doc.text(125, 78, 'Final score -')
doc.text(158, 78, User_Score)
doc.line(20, 82, 195, 82)
// Questions with responses
/* This is the point at which i need to build the page dynamically becasue the stuff above is all static and everything below could be built dynically */
// \t Question_1
doc.line(20, 113, 195, 113)
if (Var_UsersAnswer_Que1.equals(notAnswered)) {
doc.setFontSize(25)
doc.text(65, 125, questionTitle_1)
doc.line(20, 130, 195, 130)
doc.setFontSize(30)
doc.text(58, 155, questionExcludedTitle)
} else {
doc.setFontSize(14)
doc.text(20, 120, questionAnswerGivenTitle)
doc.setFontSize(12)
var splitUsersAnswer_Que1 = doc.splitTextToSize(usersAnswer_Que1, 150);
doc.text(20, 127, splitUsersAnswer_Que1)
doc.line(20, 130, 195, 130)
doc.setFontSize(14)
doc.text(20, 137, openQuestionTitle)
doc.setFontSize(12)
var splitOpenQuestion_1 = doc.splitTextToSize(openQuestion_1, 180);
doc.text(20, 145, splitOpenQuestion_1)
if (Var_UsersAnswer_Que1.isCorr('\u0041\u006C\u006C\u0020\u0061\u0072\u0065')) {
doc.addImage(CorrectImagData, 'Correct Image', 185, 115, 10, 11)
} else {
doc.addImage(IncorrectImgData, 'Incorrect Image', 185, 115, 10, 11)
}
doc.setFontSize(12)
var splitUserResp_LongTextQue_1 = doc.splitTextToSize(userResp_LongTextQue_1, 170);
doc.text(20, 160, splitUserResp_LongTextQue_1)
doc.line(20, 153, 195, 153)
}
// \t Question_2
doc.line(20, 190, 195, 190)
if (Var_UsersAnswer_Que2.equals(notAnswered)) {
doc.setFontSize(25)
doc.text(65, 202, questionTitle_2)
doc.line(20, 207, 195, 207)
doc.setFontSize(30)
doc.text(58, 232, questionExcludedTitle)
} else {
doc.setFontSize(14)
doc.text(20, 197, questionAnswerGivenTitle)
doc.setFontSize(12)
var splitUsersAnswer_Que2 = doc.splitTextToSize(usersAnswer_Que2, 150);
doc.text(20, 204, splitUsersAnswer_Que2)
doc.line(20, 207, 195, 207)
doc.setFontSize(14)
doc.text(20, 214, openQuestionTitle)
doc.setFontSize(12)
var splitOpenQuestion_2 = doc.splitTextToSize(openQuestion_2, 180);
doc.text(20, 222, splitOpenQuestion_2)
if (Var_UsersAnswer_Que2.isCorr('\u0049\u006E\u0066\u006F\u0072\u006D\u0061\u0074\u0069\u006F\u006E')) {
doc.addImage(CorrectImagData, 'Correct Image', 185, 192, 10, 11)
} else {
doc.addImage(IncorrectImgData, 'Incorrect Image', 185, 192, 10, 11)
}
doc.setFontSize(12)
var splitUserResp_LongTextQue_2 = doc.splitTextToSize(userResp_LongTextQue_2, 170);
doc.text(20, 237, splitUserResp_LongTextQue_2)
doc.line(20, 230, 195, 230)
}
//New Page - From here down, the position of everything on the page will be the same
doc.addPage()
// \t Question_3
doc.line(20, 13, 195, 13)
if (Var_UsersAnswer_Que3.equals(notAnswered)) {
doc.setFontSize(25)
doc.text(65, 25, questionTitle_3)
doc.line(20, 30, 195, 30)
doc.setFontSize(30)
doc.text(58, 55, questionExcludedTitle)
} else {
doc.setFontSize(14)
doc.text(20, 20, questionAnswerGivenTitle)
doc.setFontSize(12)
var splitUsersAnswer_Que3 = doc.splitTextToSize(usersAnswer_Que3, 150);
doc.text(20, 27, splitUsersAnswer_Que3)
doc.line(20, 30, 195, 30)
doc.setFontSize(14)
doc.text(20, 37, openQuestionTitle)
doc.setFontSize(12)
var splitOpenQuestion_3 = doc.splitTextToSize(openQuestion_3, 180);
doc.text(20, 45, splitOpenQuestion_3)
if (Var_UsersAnswer_Que3.isCorr('\u0041\u006C\u006C\u0020')) {
doc.addImage(CorrectImagData, 'Correct Image', 185, 15, 10, 11)
} else {
doc.addImage(IncorrectImgData, 'Incorrect Image', 185, 15, 10, 11)
}
doc.setFontSize(12)
var splitUserResp_LongTextQue_3 = doc.splitTextToSize(userResp_LongTextQue_3, 170);
doc.text(20, 60, splitUserResp_LongTextQue_3)
doc.line(20, 53, 195, 53)
}
// \t Question_4
doc.line(20, 90, 195, 90)
if (Var_UsersAnswer_Que4.equals(notAnswered)) {
doc.setFontSize(25)
doc.text(65, 102, questionTitle_4)
doc.line(20, 107, 195, 107)
doc.setFontSize(30)
doc.text(58, 132, questionExcludedTitle)
} else {
doc.setFontSize(14)
doc.text(20, 97, questionAnswerGivenTitle)
doc.setFontSize(12)
var splitUsersAnswer_Que4 = doc.splitTextToSize(usersAnswer_Que4, 150);
doc.text(20, 104, splitUsersAnswer_Que4)
doc.line(20, 107, 195, 107)
doc.setFontSize(14)
doc.text(20, 114, openQuestionTitle)
doc.setFontSize(12)
var splitOpenQuestion_4 = doc.splitTextToSize(openQuestion_4, 180);
doc.text(20, 122, splitOpenQuestion_4)
if (Var_UsersAnswer_Que4.isCorr('\u0041\u006C\u006C\u0020\u0061\u0072\u0065\u0020')) {
doc.addImage(CorrectImagData, 'Correct Image', 185, 92, 10, 11)
} else {
doc.addImage(IncorrectImgData, 'Incorrect Image', 185, 92, 10, 11)
}
doc.setFontSize(12)
var splitUserResp_LongTextQue_4 = doc.splitTextToSize(UserResp_LongTextQue_4, 170);
doc.text(20, 137, splitUserResp_LongTextQue_4)
doc.line(20, 130, 195, 130)
}
// \t Question_5
doc.line(20, 167, 195, 167)
if (Var_UsersAnswer_Que5.equals(notAnswered)) {
doc.setFontSize(25)
doc.text(65, 179, questionTitle_5)
doc.line(20, 184, 195, 184)
doc.setFontSize(30)
doc.text(58, 209, questionExcludedTitle)
} else {
doc.setFontSize(14)
doc.text(20, 174, questionAnswerGivenTitle)
doc.setFontSize(12)
var splitUsersAnswer_Que5 = doc.splitTextToSize(usersAnswer_Que5, 150);
doc.text(20, 181, splitUsersAnswer_Que5)
doc.line(20, 184, 195, 184)
doc.setFontSize(14)
doc.text(20, 191, openQuestionTitle)
doc.setFontSize(12)
var splitOpenQuestion_5 = doc.splitTextToSize(openQuestion_5, 180);
doc.text(20, 199, splitOpenQuestion_5)
if (Var_UsersAnswer_Que5.isCorr('\u0048\u006F\u0077\u0020\u0074\u006F\u0020\u0067\u0065\u0074')) {
doc.addImage(CorrectImagData, 'Correct Image', 185, 169, 10, 11)
} else {
doc.addImage(IncorrectImgData, 'Incorrect Image', 185, 169, 10, 11)
}
doc.setFontSize(12)
var splitUserResp_LongTextQue_5 = doc.splitTextToSize(openQuestion_5, 170);
doc.text(20, 214, splitUserResp_LongTextQue_5)
doc.line(20, 207, 195, 207)
}
//New Page - There are another 55 questions
// doc.addPage()
/* \t Question_N
doc.line(20, 13, 195, 13)
if (Var_UsersAnswer_QueN.equals(notAnswered)) {
\t doc.setFontSize(25)
\t doc.text(65, 25, questionTitle_N)
\t doc.line(20, 30, 195, 30)
\t doc.setFontSize(30)
\t doc.text(58, 55, questionExcludedTitle)
} else {
\t doc.setFontSize(14)
\t doc.text(20, 20, questionAnswerGivenTitle)
\t doc.setFontSize(12)
\t var splitUsersAnswer_QueN = doc.splitTextToSize(usersAnswer_QueN, 150);
\t doc.text(20, 27, splitUsersAnswer_QueN)
\t doc.line(20, 30, 195, 30)
\t doc.setFontSize(14)
\t doc.text(20, 37, openQuestionTitle)
\t doc.setFontSize(12)
\t var splitOpenQuestion_N = doc.splitTextToSize(openQuestion_N, 180);
\t doc.text(20, 45, splitOpenQuestion_N)
\t if (Var_UsersAnswer_QueN.isCorr('\u0041\u006C\u006C\u0020')) {
\t \t doc.addImage(CorrectImagData, 'Correct Image', 185, 15, 10, 11)
\t } else {
\t \t doc.addImage(IncorrectImgData, 'Incorrect Image', 185, 15, 10, 11)
\t }
\t doc.setFontSize(12)
\t var splitUserResp_LongTextQue_N = doc.splitTextToSize(userResp_LongTextQue_N, 170);
\t doc.text(20, 60, splitUserResp_LongTextQue_N)
\t doc.line(20, 53, 195, 53)
}
\t
etc................................................
\t
*/
// Save document/Create PDF
doc.save('Test.pdf');
}
이 C의 결과 ode는 각 질문에 대한 사전 정의 된 페이지 위치와 해당 질문에 대한 각 요소가있는 각 질문 (1-60)이있는 pdf의 작성입니다. 그러나 응답이 주어진 지 확인하기 위해 (사용자는 60 가지 질문 모두에 대해 무작위로 결정된 30 가지 질문에만 답변해야 함) 해당 질문에 대한 응답이없는 경우 (응용 프로그램에서 질문은 사용자에게) "제외 된 질문"이라고 말하지만 페이지의 공간은 그대로 유지합니다.
결과적으로 40 개 이상의 페이지로 끝나고 답변이있는 질문 만 사용자 응답을 표시하며 제외 된 질문은 그대로 표시됩니다.
PDF를 작성하기 전에 대답하지 않은 질문을 설정 한 다음 변수를 채운 배열을 사용하여 페이지를 동적으로 작성할 수 있기를 바랍니다. 사용자가 응답 한 질문 만 표시됩니다.
내가 달성하고자하는 것은 사용자가 대답 한 질문 수 (1 또는 2 일 수 있지만 최대 30 일 수 있음)에 따라 페이지 수를 줄이는 것입니다. 내가 머리를 얻을 수 없다는 사실은 각 요소에 대한 페이지의 실제 위치를 명시해야하기 때문에 자동으로 스택을 가져올 수없고 Javascript를 사용해야하기 때문입니다. 응답을 쿼리 한 다음 즉시 페이지에 삽입하십시오.
도움을 주시면 감사하겠습니다.
나는 여기 잘못된 트랙을 완전히 무너 뜨릴 것이므로 더 나은 접근법을 듣고 기쁘게 생각합니다.
미리 감사드립니다.
const answers = [AnswerToQuestion1, AnswerToQuestion2, AnswerToQuestion3].filter(x => x);
필터 기능을 null 또는 정의되지 않습니다 모든 레코드를 제거 : 당신은 그냥 널 필터링 응답의 배열을 원하는처럼
변수를 사용하여 배열을 생성하는 부분에 대해 다음과 같이 할 수 있습니다. 당신은 코드 시도 (또는 그것에 가까운 무엇인가)를 게시합니까? – bitstrider
나는 내일 (모스크바 오후 7시 50 분) 내일을 위해 노력하고있는 것에 대한 몇 가지 예제 코드를 게시 할 것이므로 저녁에 남겨 두었으나 내일 오후에 다시 돌아올 것이다. 신속한 대응을 위해 건배. –
안녕하세요 @ 비트 스트라이더, 예제 코드를 포함하도록 게시물을 업데이트했습니다. 보고 싶은 것이 있다면 알려주세요. 내 응용 프로그램의 다른 곳에서 결정된 변수에 액세스 할 수 없으므로 코드가 실행되지 않으므로 필요에 따라 출력 예제를 첨부 할 수 있습니다. 감사! –