בעת המרת דפי אינטרנט ו- HTML ל- PDF ממשק ה- API של GrabzIt Node.js מספק את התכונות הבאות שעוזרות intאיחוד GrabzIt into המערכת שלך בקלות רבה ככל האפשר. עם זאת לפני שתתחיל לזכור את זה לאחר התקשר אל url_to_pdf, html_to_pdf or file_to_pdf שיטות save or save_to יש לקרוא לשיטה לצילום צילום המסך PDF או להמרת HTML היישר ל- PDF.
כדי להמיר דף אינטרנט נדרש פרמטר אחד בלבד intמסמך PDF או ל- המרת HTML ל- PDF כמוצג להלן.
client.url_to_pdf("https://www.tesla.com"); //Then call the save or save_to method
client.html_to_pdf("<html><body><h1>Hello World!</h1></body></html>"); //Then call the save or save_to method
client.file_to_pdf("example.html"); //Then call the save or save_to method
אתה יכול להעביר מזהה מותאם אישית אל ה- PDF שיטות כמוצג להלן, ערך זה יוחזר למטפל GrabzIt Node.js שלך. לדוגמה, מזהה מותאם אישית זה יכול להיות מזהה בסיס נתונים, המאפשר לשייך צילום מסך לרשומת מסד נתונים מסוימת.
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"customId":123456}; client.url_to_pdf("https://www.tesla.com", options); //Then call the save method client.save("http://www.example.com/handler", function (error, id){ if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"customId":123456}; client.html_to_pdf("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the save method client.save("http://www.example.com/handler", function (error, id){ if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"customId":123456}; client.file_to_pdf("example.html", options); //Then call the save method client.save("http://www.example.com/handler", function (error, id){ if (error != null){ throw error; } });
כשאתה יוצר צילום מסך PDF אתה יכול לבקש שתרצה להחיל מסוים תבנית ל- PDF שנוצר. תבנית זו חייבת להיות saved מראש ופרט את תוכן הכותרת העליונה התחתונה יחד עם כל משתנים מיוחדים. בקוד הדוגמה למטה המשתמש משתמש בתבנית שלו שנקראת "התבנית שלי".
אם אין שולי עליון או תחתון גדולים מספיק לכותרת העליונה או התחתונה בהתאמה, זה לא יופיע ב- PDF. בדוגמה להלן קבענו את השוליים העליונים והתחתונים ל- 20 כדי לספק מקום רב.
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"marginTop":20,"marginBottom":20,"templateId":"my template"}; client.url_to_pdf("https://www.tesla.com", options); //Then call the save or save_to method client.save_to("result.pdf", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"marginTop":20,"marginBottom":20,"templateId":"my template"}; client.html_to_pdf("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the save or save_to method client.save_to("result.pdf", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"marginTop":20,"marginBottom":20,"templateId":"my template"}; client.file_to_pdf("example.html", options); //Then call the save or save_to method client.save_to("result.pdf", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
אם ברצונך להמיר אלמנט HTML כגון div או span ישירות intoa מסמך PDF אתה יכול עם ספריית Node.js של GrabzIt. עליך לעבור את בורר CSS של אלמנט ה- HTML שברצונך להמיר ל- targetElement
פָּרָמֶטֶר.
... <span id="Article"> <p>This is the content I am interested in.</p> <img src="myimage.jpg"> </span> ...
בדוגמה זו ברצוננו ללכוד את כל התוכן בטווח שיש לו מזהה Article
לכן אנו מעבירים זאת ל- GrabzIt כמוצג להלן.
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); grabzIt.url_to_pdf("http://www.bbc.co.uk/news", {"targetElement":"#Article"}); //Then call the save or save_to method client.save_to("result.pdf", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
כיצד ניתן לקצץ PDF בעת מיקוד לאלמנט HTML יכול להיות מבוקר באמצעות טכניקות אלה.