questpdf_example.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """
  2. Example usage of QuestPDF Python bindings
  3. This demonstrates how to use the auto-generated Python wrapper for QuestPDF.
  4. Make sure the QuestPDF native library is in the same directory or provide the path.
  5. """
  6. from questpdf import QuestPDFLibrary, Handle
  7. def create_simple_document():
  8. """Create a simple PDF document using QuestPDF"""
  9. # Initialize the library
  10. # You can pass a custom path: QuestPDFLibrary('path/to/QuestPDF.dll')
  11. pdf = QuestPDFLibrary()
  12. try:
  13. # Example: Create a container and apply styling
  14. # This is a conceptual example - actual method names will match your generated API
  15. # Create a document container
  16. container = pdf.some_container_method()
  17. # Apply alignment (example based on AlignRight method mentioned)
  18. with container as c:
  19. aligned = pdf.align_right(c)
  20. # Apply padding
  21. padded = pdf.padding(aligned, 10)
  22. # Add text or other content
  23. # result = pdf.text(padded, "Hello from Python!")
  24. print("Document created successfully!")
  25. except Exception as e:
  26. print(f"Error creating document: {e}")
  27. def main():
  28. """Main entry point"""
  29. print("QuestPDF Python Example")
  30. print("=" * 50)
  31. try:
  32. create_simple_document()
  33. except Exception as e:
  34. print(f"Fatal error: {e}")
  35. if __name__ == "__main__":
  36. main()