docstron / laravel-sdk
Laravel SDK for Docstron API
Installs: 39
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/docstron/laravel-sdk
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.0|^11.0
This package is auto-updated.
Last update: 2026-01-02 16:16:16 UTC
README
Docstron Laravel SDK
A Laravel SDK for the Docstron API, allowing you to easily generate PDFs, manage templates, applications, documents, and track usage statistics.
Installation
You can install the package via composer:
composer require docstron/laravel-sdk
Configuration
Publish the configuration file:
php artisan vendor:publish --tag=docstron-config
Add your API key to your .env file:
DOCSTRON_API_KEY=your-api-key DOCSTRON_BASE_URL=https://api.docstron.com/v1
Usage
Applications
use Docstron\Laravel\Facades\Docstron; // Get all applications $apps = Docstron::getApplications(); // Get a specific application $app = Docstron::getApplication('app-7b4d78fb-820c-4ca9-84cc-46953f211234');
Usage Statistics
use Docstron\Laravel\Facades\Docstron; // Get usage statistics and limits $usage = Docstron::getUsage(); // Response includes: // - applications (total, limit, usage_percentage) // - templates (total, limit, usage_percentage) // - documents (total, monthly, usage, monthly_limit, usage_percentage) // - subscription (plan_name, api_rate_limit, processing_priority, support_level)
Templates
use Docstron\Laravel\Facades\Docstron; // Get all templates $templates = Docstron::getTemplates(); // Create a template $template = Docstron::createTemplate([ 'application_id' => 'app-7b4d78fb-820c-4ca9-84cc-46953f211234', 'name' => 'Invoice Template', 'content' => '<h1>Invoice for {{ customer_name }}</h1><p>Amount: {{ amount }}</p>', 'is_active' => true, 'extra_css' => '@page { margin: 3cm; }', // Optional ]); // Get a specific template $template = Docstron::getTemplate('template-c2465c0b-fc54-4672-b9ac-7446886cd6de'); // Update a template $template = Docstron::updateTemplate('template-c2465c0b-fc54-4672-b9ac-7446886cd6de', [ 'name' => 'Updated Invoice Template', 'is_active' => false, ]); // Delete a template Docstron::deleteTemplate('template-c2465c0b-fc54-4672-b9ac-7446886cd6de');
Documents
Generate Document
use Docstron\Laravel\Facades\Docstron; // Generate a document with direct PDF response $pdfContent = Docstron::generateDocument([ 'template_id' => 'template-c2465c0b-fc54-4672-b9ac-7446886cd6de', 'data' => [ 'customer_name' => 'John Doe', 'amount' => '$299.00', ], 'response_type' => 'pdf', // Default ]); // Save the PDF to file file_put_contents('invoice.pdf', $pdfContent); // Generate with Base64 response $response = Docstron::generateDocument([ 'template_id' => 'template-c2465c0b-fc54-4672-b9ac-7446886cd6de', 'data' => [ 'customer_name' => 'John Doe', 'amount' => '$299.00', ], 'response_type' => 'json_with_base64', ]); // Generate with Document ID response $response = Docstron::generateDocument([ 'template_id' => 'template-c2465c0b-fc54-4672-b9ac-7446886cd6de', 'data' => [ 'customer_name' => 'John Doe', 'amount' => '$299.00', ], 'response_type' => 'document_id', ]); // Generate password-protected PDF $pdfContent = Docstron::generateDocument([ 'template_id' => 'template-c2465c0b-fc54-4672-b9ac-7446886cd6de', 'data' => [ 'customer_name' => 'John Doe', 'amount' => '$299.00', ], 'response_type' => 'pdf', 'password' => 'SecureDoc2025!', ]);
Quick Generate Document
use Docstron\Laravel\Facades\Docstron; // Quick generate without pre-creating a template $pdfContent = Docstron::quickGenerateDocument([ 'html_content' => '<h1>Hello {{ name }}</h1><p>Welcome to Docstron!</p>', 'data' => [ 'name' => 'John Doe', ], 'response_type' => 'pdf', ]); // Quick generate with custom CSS $pdfContent = Docstron::quickGenerateDocument([ 'html_content' => '<h1>Invoice</h1>', 'extra_css' => '@page { margin: 2cm; }', 'response_type' => 'pdf', ]); // Quick generate and save as template $response = Docstron::quickGenerateDocument([ 'html_content' => '<h1>Receipt</h1>', 'save_as_template' => true, 'template_name' => 'Receipt Template', 'application_id' => 'app-7b4d78fb-820c-4ca9-84cc-46953f211234', 'response_type' => 'document_id', ]);
Manage Documents
use Docstron\Laravel\Facades\Docstron; // Get all documents $documents = Docstron::getDocuments(); // Get a specific document $document = Docstron::getDocument('document-489a79af-8680-4a08-a777-df52f26f296f'); // Download a document $pdfContent = Docstron::downloadDocument('document-489a79af-8680-4a08-a777-df52f26f296f'); file_put_contents('downloaded.pdf', $pdfContent); // Update a document $document = Docstron::updateDocument('document-489a79af-8680-4a08-a777-df52f26f296f', [ 'attributes' => [ 'customer_name' => 'Jane Doe', 'amount' => '$399.00', ], ]); // Delete a document Docstron::deleteDocument('document-489a79af-8680-4a08-a777-df52f26f296f');
Response Types
When generating documents, you can specify different response types:
pdf(default): Returns the PDF file content directly as binary datajson_with_base64: Returns JSON with the PDF encoded as base64document_id: Returns JSON with the document ID for later retrieval
Error Handling
The SDK throws GuzzleException for HTTP errors. You should wrap your calls in try-catch blocks:
use GuzzleHttp\Exception\GuzzleException; use Docstron\Laravel\Facades\Docstron; try { $pdf = Docstron::generateDocument([ 'template_id' => 'template-id', 'data' => ['name' => 'John'], ]); } catch (GuzzleException $e) { // Handle error logger()->error('Docstron API Error: ' . $e->getMessage()); }
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- 📚 Documentation
- 💬 Issues
- 📧 Email: support@docstron.com
Links
Made with ❤️ by Playiiit Company