כלים ללכידה ולהמרה של האינטרנט

המרת דפי אינטרנט ו- HTML ל- PDF

ממשק ה- API של Node.js

בעת המרת דפי אינטרנט ו- 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 ל- PDF

אם ברצונך להמיר אלמנט 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 יכול להיות מבוקר באמצעות טכניקות אלה.