הוספת היכולת להמיר HTML או דפי אינטרנט into מסמכי Word לאפליקציה שלך מעולם לא היו קלים יותר ממשק ה- API של GrabzIt. עם זאת לפני שתתחיל לזכור את זה לאחר התקשרות אל URLToDOCX, HTMLToDOCX or FileToDOCX שיטות. ה Save or SaveTo יש לקרוא לשיטה ליצירת DOCX בפועל.
לכידת דפי אינטרנט כ- DOCX ממירה את כל דף האינטרנט intoa מסמך Word שיכול להכיל עמודים רבים. בדוגמאות להלן PHP ממיר HTML ל- DOCX ודף אינטרנט intoa מסמך Word, עם פרמטר אחד בלבד.
$grabzIt->URLToDOCX("https://www.tesla.com"); //Then call the Save or SaveTo method
$grabzIt->HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>"); //Then call the Save or SaveTo method
$grabzIt->FileToDOCX("example.html"); //Then call the Save or SaveTo method
אתה יכול להעביר מזהה מותאם אישית אל ה- DOCX שיטות כמוצג להלן, ערך זה יוחזר למטפל PHP שלך ב- GrabzIt. לדוגמה, מזהה מותאם אישית זה יכול להיות מזהה בסיס נתונים, המאפשר לשייך מסמך DOCX לרשומת מסד נתונים מסוימת.
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItDOCXOptions(); $options->setCustomId(123456); $grabzIt->URLToDOCX("https://www.tesla.com", $options); //Then call the Save method $grabzIt->Save("http://www.example.com/handler.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItDOCXOptions(); $options->setCustomId(123456); $grabzIt->HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>", $options); //Then call the Save method $grabzIt->Save("http://www.example.com/handler.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItDOCXOptions(); $options->setCustomId(123456); $grabzIt->FileToDOCX("example.html", $options); //Then call the Save method $grabzIt->Save("http://www.example.com/handler.php");
בעוד GrabzIt אינו תומך בתבנית Word המסורתית. כשאתה מוסיף כותרות עליונות עליונות ותחתונות למסמך Word אתה יכול לבקש שתרצה להחיל תבנית ל- DOCX שנוצר. תבנית זו חייבת להיות saved מראש ופרט את תוכן הכותרת העליונה התחתונה יחד עם כל משתנים מיוחדים. בקוד הדוגמה למטה המשתמש משתמש בתבנית שהם יצרו בשם "התבנית שלי".
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItDOCXOptions(); $options->setTemplateId("my template"); $grabzIt->URLToDOCX("https://www.tesla.com", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.docx");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItDOCXOptions(); $options->setTemplateId("my template"); $grabzIt->HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.docx");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItDOCXOptions(); $options->setTemplateId("my template"); $grabzIt->FileToDOCX("example.html", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.docx");
אם ברצונך להמיר רכיב HTML בלבד כגון div או span ישירות intoa מסמך Word שאתה יכול עם ספריית PHP של GrabzIt. עליך לעבור את בורר CSS של אלמנט ה- HTML שברצונך להמיר ל- setTargetElement
שיטת GrabzItDOCXOptions מעמד.
... <span id="Article"> <p>This is the content I am interested in.</p> <img src="myimage.jpg"> </span> ...
בדוגמה זו ברצוננו ללכוד את כל התוכן בטווח שיש לו מזהה Article
. על ידי העברת זה ל- GrabzIt as, מוצג להלן.
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItDOCXOptions(); $options->setTargetElement("#Article"); $grabzIt->URLToDOCX("http://www.bbc.co.uk/news", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.docx");
לא משנה אם אתה ממיר כתובת URL ל- Word כפי שמוצג בדוגמה או HTML ל- Word. שניהם ממקדים אלמנטים ב- HTML באותה צורה.