Improve PDF processing with robust error handling

Enhanced PDF processing by adding error handling and optimizing server-side processing.