أدوات لالتقاط وتحويل الويب

تحويل صفحات الويب و HTML إلى PDF

Node.js API

عند تحويل صفحات الويب و HTML إلى PDF GrabzIt's Node.js API يوفر الميزات التالية التي تساعد integrate GrabzIt intس النظام الخاص بك بسهولة قدر الإمكان. ولكن قبل أن تبدأ تذكر أنه بعد استدعاء 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 ، يمكنك طلب أن ترغب في تطبيق معين قالب إلى قوات الدفاع الشعبي ولدت. يجب أن يكون هذا القالب saveد مقدما وسيحدد محتويات رأس وتذييل جنبا إلى جنب مع أي متغيرات خاصة. في مثال التعليمة البرمجية أدناه ، يستخدم المستخدم قالبه المسمى "القالب".

إذا لم يكن هناك هامش كبير أو سفلي كبير بما يكفي للرأس أو التذييل على التوالي ، فلن يظهر في 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 مباشرة intيا وثيقة PDF يمكنك مع مكتبة GrabzIt's Node.js. يجب أن تمر محدد 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 تسيطر عليها باستخدام هذه التقنيات.