عند تحويل صفحات الويب أو قصاصات HTML مباشرة إلى PDF GrabzIt's Ruby API يوفر الميزات التالية التي تساعد integrate GrabzIt intس النظام الخاص بك بسهولة قدر الإمكان. ولكن قبل أن تبدأ تذكر أنه بعد استدعاء set_pdf_options طريقة save or save_to يجب استدعاء الطريقة لالتقاط لقطة شاشة PDF.
التقاط PDF يحول صفحة الويب بأكملها intيا قوات الدفاع الشعبي وثيقة من المحتمل أن العديد من الصفحات. مطلوب معلمة واحدة فقط من أجل تحويل صفحة ويب intيا وثيقة PDF أو ل تحويل HTML إلى PDF كما هو مبين في الأمثلة أدناه.
grabzItClient.url_to_pdf("https://www.tesla.com") # Then call the save or save_to method
grabzItClient.html_to_pdf("<html><body><h1>Hello World!</h1></body></html>") # Then call the save or save_to method
grabzItClient.file_to_pdf("example.html") # Then call the save or save_to method
يمكنك تمرير معرف مخصص إلى PDF الأساليب كما هو موضح أدناه ، ثم يتم إرجاع هذه القيمة إلى معالج GrabzIt Ruby الخاص بك. على سبيل المثال ، يمكن أن يكون هذا المعرّف المخصص معرف قاعدة بيانات ، مما يسمح بربط لقطة شاشة بسجل قاعدة بيانات معين.
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::PDFOptions.new() options.customId = "123456" grabzItClient.url_to_pdf("https://www.tesla.com", options) # Then call the save method grabzItClient.save("http://www.example.com/handler/index")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::PDFOptions.new() options.customId = "123456" grabzItClient.html_to_pdf("<html><body><h1>Hello World!</h1></body></html>", options) # Then call the save method grabzItClient.save("http://www.example.com/handler/index")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::PDFOptions.new() options.customId = "123456" grabzItClient.file_to_pdf("example.html", options) # Then call the save method grabzItClient.save("http://www.example.com/handler/index")
عند إنشاء لقطة شاشة PDF ، يمكنك طلب أن ترغب في تطبيق معين قالب إلى قوات الدفاع الشعبي ولدت. يجب أن يكون هذا القالب saveد مقدما وسيحدد محتويات رأس وتذييل جنبا إلى جنب مع أي متغيرات خاصة. في مثال التعليمة البرمجية أدناه ، يستخدم المستخدم قالبه المسمى "القالب".
إذا لم يكن هناك هامش كبير أو سفلي كبير بما يكفي للرأس أو التذييل على التوالي ، فلن يظهر في PDF. في المثال أدناه ، قمنا بتعيين الهوامش العلوية والسفلية على 20 لتوفير مساحة كبيرة.
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::PDFOptions.new() options.marginTop = 20 options.marginBottom = 20 options.templateId = "my template" grabzItClient.url_to_pdf("https://www.tesla.com", options) # Then call the save or save_to method grabzItClient.save_to("result.pdf")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::PDFOptions.new() options.marginTop = 20 options.marginBottom = 20 options.templateId = "my template" grabzItClient.html_to_pdf("<html><body><h1>Hello World!</h1></body></html>", options) # Then call the save or save_to method grabzItClient.save_to("result.pdf")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::PDFOptions.new() options.marginTop = 20 options.marginBottom = 20 options.templateId = "my template" grabzItClient.file_to_pdf("example.html", options) # Then call the save or save_to method grabzItClient.save_to("result.pdf")
إذا كنت تريد فقط تحويل عنصر HTML مثل div أو span مباشرة intيا وثيقة PDF يمكنك مع GrabzIt's Ruby Gem. يجب أن تمر محدد CSS عنصر HTML الذي ترغب في تحويله إلى targetElement
الأسلوب.
... <span id="Article"> <p>This is the content I am interested in.</p> <img src="myimage.jpg"> </span> ...
في هذا المثال ، نود أن نلتقط كل المحتوى الموجود في النطاق الذي يحمل معرف Article
، لذلك ننقل هذا إلى GrabzIt كما هو موضح أدناه.
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::PDFOptions.new() options.targetElement = "#Article" grabzItClient.url_to_pdf("http://www.bbc.co.uk/news", options) # Then call the save or save_to method grabzItClient.save_to("result.pdf")
كيف يمكن اقتصاص ملف PDF عند استهداف عنصر HTML تسيطر عليها باستخدام هذه التقنيات.